Skip to content

Commit

Permalink
Add on-demand recalculation option to ManipulationPivot
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 19, 2016
1 parent 999560d commit 7cdf4c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
27 changes: 24 additions & 3 deletions radiant/selection/ManipulationPivot.cpp
Expand Up @@ -12,7 +12,9 @@ namespace
}

ManipulationPivot::ManipulationPivot() :
_entityPivotIsOrigin(false)
_entityPivotIsOrigin(false),
_needsRecalculation(true),
_operationActive(false)
{}

void ManipulationPivot::initialise()
Expand All @@ -25,14 +27,24 @@ void ManipulationPivot::initialise()
}

// Returns the pivot-to-world transform
const Matrix4& ManipulationPivot::getMatrix4() const
const Matrix4& ManipulationPivot::getMatrix4()
{
if (_needsRecalculation && !_operationActive)
{
updateFromSelection();
}

return _pivot2World;
}

// Returns the position of the pivot point relative to origin
const Vector3& ManipulationPivot::getVector3() const
const Vector3& ManipulationPivot::getVector3()
{
if (_needsRecalculation && !_operationActive)
{
updateFromSelection();
}

return _pivot2World.t().getVector3();
}

Expand All @@ -41,11 +53,17 @@ void ManipulationPivot::setFromMatrix(const Matrix4& newPivot2World)
_pivot2World = newPivot2World;
}

void ManipulationPivot::setNeedsRecalculation(bool needsRecalculation)
{
_needsRecalculation = needsRecalculation;
}

// Call this before an operation is started, such that later
// transformations can be applied on top of the correct starting point
void ManipulationPivot::beginOperation()
{
_pivot2WorldStart = _pivot2World;
_operationActive = true;
}

// Reverts the matrix to the state it had at the beginning of the operation
Expand All @@ -57,6 +75,7 @@ void ManipulationPivot::revertToStart()
void ManipulationPivot::endOperation()
{
_pivot2WorldStart = _pivot2World;
_operationActive = false;
}

void ManipulationPivot::applyTranslation(const Vector3& translation)
Expand All @@ -69,6 +88,8 @@ void ManipulationPivot::applyTranslation(const Vector3& translation)

void ManipulationPivot::updateFromSelection()
{
_needsRecalculation = false;

Vector3 objectPivot;

const SelectionInfo& info = GlobalSelectionSystem().getSelectionInfo();
Expand Down
14 changes: 12 additions & 2 deletions radiant/selection/ManipulationPivot.h
Expand Up @@ -27,19 +27,29 @@ class ManipulationPivot
// Use a single Entity's "origin" keyvalue as pivot
bool _entityPivotIsOrigin;

// "dirty" flag
bool _needsRecalculation;

// During operations, we want to block pivot recalculations
bool _operationActive;

public:
ManipulationPivot();

void initialise();

// Returns the pivot-to-world transform
const Matrix4& getMatrix4() const;
const Matrix4& getMatrix4();

// Returns the position of the pivot point relative to origin
const Vector3& getVector3() const;
const Vector3& getVector3();

void setFromMatrix(const Matrix4& newPivot2World);

// Set the dirty flag of the matrix, this will trigger
// an updateFromSelection() next time getMatrix4() is called
void setNeedsRecalculation(bool needsRecalculation);

// Call this before an operation is started, such that later
// transformations can be applied on top of the correct starting point
void beginOperation();
Expand Down
3 changes: 2 additions & 1 deletion radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -188,6 +188,7 @@ bool RadiantSelectionSystem::nothingSelected() const
void RadiantSelectionSystem::pivotChanged() const
{
_pivotChanged = true;
const_cast<RadiantSelectionSystem&>(*this)._pivot.setNeedsRecalculation(true);
SceneChangeNotify();
}

Expand Down Expand Up @@ -831,7 +832,7 @@ const Matrix4& RadiantSelectionSystem::getPivot2World() const
// Questionable const design - almost everything needs to be declared const here...
const_cast<RadiantSelectionSystem*>(this)->recalculatePivot2World();

return _pivot.getMatrix4();
return const_cast<RadiantSelectionSystem*>(this)->_pivot.getMatrix4();
}

void RadiantSelectionSystem::constructStatic()
Expand Down

0 comments on commit 7cdf4c6

Please sign in to comment.