Skip to content

Commit

Permalink
Add support for moving the pivot during the transformation.
Browse files Browse the repository at this point in the history
Was broken in the last few revisions.
  • Loading branch information
codereader committed Dec 19, 2016
1 parent a4a654b commit 8ec724f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 13 deletions.
29 changes: 28 additions & 1 deletion radiant/selection/ManipulationPivot.h
Expand Up @@ -15,6 +15,12 @@ class ManipulationPivot
private:
Matrix4 _pivot2World;

// The untransformed pivot2world matrix
// When an operation starts, the current state is saved here.
// Since translations are relative to the starting point of the
// operation, they are applied on top of the pivot2WorldStart.
Matrix4 _pivot2WorldStart;

public:
const Matrix4& getMatrix4() const
{
Expand All @@ -26,8 +32,29 @@ class ManipulationPivot
_pivot2World = newPivot2World;
}

void translate(const Vector3& translation)
// Call this before an operation is started, such that later
// transformations can be applied on top of the correct starting point
void beginOperation()
{
_pivot2WorldStart = _pivot2World;
}

// Reverts the matrix to the state it had at the beginning of the operation
void revertToStart()
{
_pivot2World = _pivot2WorldStart;
}

void endOperation()
{
_pivot2WorldStart = _pivot2World;
}

void applyTranslation(const Vector3& translation)
{
// We apply translations on top of the starting point
revertToStart();

_pivot2World.translateBy(translation);
}
};
Expand Down
6 changes: 5 additions & 1 deletion radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -814,6 +814,9 @@ void RadiantSelectionSystem::onManipulationStart()
{
_pivotMoving = true;
_pivot2worldStart = getPivot2World();

// Save the pivot state now that the transformation is starting
_pivot.beginOperation();
}

void RadiantSelectionSystem::onManipulationChanged()
Expand All @@ -829,6 +832,7 @@ void RadiantSelectionSystem::onManipulationChanged()
void RadiantSelectionSystem::onManipulationEnd()
{
_pivotMoving = false;
_pivot.endOperation();

// The selection bounds have possibly changed, request an idle callback
_requestWorkZoneRecalculation = true;
Expand Down Expand Up @@ -1036,7 +1040,7 @@ void RadiantSelectionSystem::initialiseModule(const ApplicationContext& ctx)
constructStatic();

// Add manipulators
registerManipulator(std::make_shared<DragManipulator>());
registerManipulator(std::make_shared<DragManipulator>(_pivot));
registerManipulator(std::make_shared<ClipManipulator>());
registerManipulator(std::make_shared<TranslateManipulator>(_pivot, 2, 64));
registerManipulator(std::make_shared<ScaleManipulator>(*this, 0, 64));
Expand Down
6 changes: 4 additions & 2 deletions radiant/selection/manipulators/DragManipulator.cpp
Expand Up @@ -13,10 +13,12 @@ namespace selection

const std::string RKEY_TRANSIENT_COMPONENT_SELECTION = "user/ui/transientComponentSelection";

DragManipulator::DragManipulator() :
DragManipulator::DragManipulator(ManipulationPivot& pivot) :
_pivot(pivot),
_freeResizeComponent(_resizeTranslatable),
_resizeModeActive(false),
_freeDragComponent(_dragTranslatable)
_freeDragComponent(_dragTranslatable),
_dragTranslatable(SelectionTranslator::TranslationCallback())
{}

DragManipulator::Type DragManipulator::getType() const
Expand Down
5 changes: 4 additions & 1 deletion radiant/selection/manipulators/DragManipulator.h
Expand Up @@ -6,6 +6,7 @@
#include "selection/SelectionTest.h"
#include "selection/SelectionPool.h"
#include "selection/BasicSelectable.h"
#include "selection/ManipulationPivot.h"

namespace selection
{
Expand Down Expand Up @@ -33,6 +34,8 @@ class DragManipulator :
public ManipulatorBase
{
private:
ManipulationPivot& _pivot;

// Resize component
TranslateFree _freeResizeComponent;
ResizeTranslatable _resizeTranslatable;
Expand All @@ -46,7 +49,7 @@ class DragManipulator :
BasicSelectable _dragSelectable;

public:
DragManipulator();
DragManipulator(ManipulationPivot& pivot);

Type getType() const override;
Component* getActiveComponent() override;
Expand Down
19 changes: 19 additions & 0 deletions radiant/selection/manipulators/ManipulatorComponents.h
Expand Up @@ -11,6 +11,7 @@
#include "Translatable.h"
#include "Rotatable.h"
#include "Scalable.h"
#include <functional>

namespace selection
{
Expand Down Expand Up @@ -143,6 +144,18 @@ class ResizeTranslatable :
class SelectionTranslator :
public Translatable
{
public:
typedef std::function<void(const Vector3&)> TranslationCallback;

private:
TranslationCallback _onTranslation;

public:

SelectionTranslator(const TranslationCallback& onTranslation) :
_onTranslation(onTranslation)
{}

void translate(const Vector3& translation) override
{
if (GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
Expand All @@ -153,6 +166,12 @@ class SelectionTranslator :
{
Scene_Translate_Selected(GlobalSceneGraph(), translation);
}

// Invoke the feedback function
if (_onTranslation)
{
_onTranslation(translation);
}
}
};

Expand Down
5 changes: 3 additions & 2 deletions radiant/selection/manipulators/TranslateManipulator.cpp
Expand Up @@ -14,12 +14,13 @@ const std::string RKEY_TRANSLATE_CONSTRAINED = "user/ui/xyview/translateConstrai

// Constructor
TranslateManipulator::TranslateManipulator(ManipulationPivot& pivot, std::size_t segments, float length) :
_pivot(pivot),
_translator(std::bind(&ManipulationPivot::applyTranslation, &_pivot, std::placeholders::_1)),
_translateFree(_translator),
_translateAxis(_translator),
_arrowHeadX(3 * 2 * (segments << 3)),
_arrowHeadY(3 * 2 * (segments << 3)),
_arrowHeadZ(3 * 2 * (segments << 3)),
_pivot(pivot)
_arrowHeadZ(3 * 2 * (segments << 3))
{
draw_arrowline(length, &_arrowX.front(), 0);
draw_arrowhead(segments, length, &_arrowHeadX._vertices.front(), TripleRemapXYZ<Vertex3f>(), TripleRemapXYZ<Normal3f>());
Expand Down
12 changes: 6 additions & 6 deletions radiant/selection/manipulators/TranslateManipulator.h
@@ -1,11 +1,11 @@
#pragma once

#include "ManipulatorBase.h"
#include "../Renderables.h"
#include "../Pivot2World.h"
#include "selection/Renderables.h"
#include "selection/Pivot2World.h"
#include "ManipulatorComponents.h"
#include "../BasicSelectable.h"
#include "../ManipulationPivot.h"
#include "selection/BasicSelectable.h"
#include "selection/ManipulationPivot.h"

namespace selection
{
Expand All @@ -17,6 +17,8 @@ class TranslateManipulator :
public ManipulatorBase
{
private:
ManipulationPivot& _pivot;

SelectionTranslator _translator;
TranslateFree _translateFree;
TranslateAxis _translateAxis;
Expand All @@ -32,8 +34,6 @@ class TranslateManipulator :
selection::BasicSelectable _selectableZ;
selection::BasicSelectable _selectableScreen;
Pivot2World _pivot2World;

ManipulationPivot& _pivot;
public:
static ShaderPtr _stateWire;
static ShaderPtr _stateFill;
Expand Down

0 comments on commit 8ec724f

Please sign in to comment.