Skip to content

Commit

Permalink
When user is placing the pivot, don't recalculate it automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 19, 2016
1 parent ec9201e commit 38faf6a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
13 changes: 10 additions & 3 deletions radiant/selection/ManipulationPivot.cpp
Expand Up @@ -14,7 +14,8 @@ namespace
ManipulationPivot::ManipulationPivot() :
_entityPivotIsOrigin(false),
_needsRecalculation(true),
_operationActive(false)
_operationActive(false),
_userLocked(false)
{}

void ManipulationPivot::initialise()
Expand All @@ -29,7 +30,7 @@ void ManipulationPivot::initialise()
// Returns the pivot-to-world transform
const Matrix4& ManipulationPivot::getMatrix4()
{
if (_needsRecalculation && !_operationActive)
if (_needsRecalculation && !_operationActive && !_userLocked)
{
updateFromSelection();
}
Expand All @@ -40,7 +41,7 @@ const Matrix4& ManipulationPivot::getMatrix4()
// Returns the position of the pivot point relative to origin
const Vector3& ManipulationPivot::getVector3()
{
if (_needsRecalculation && !_operationActive)
if (_needsRecalculation && !_operationActive && !_userLocked)
{
updateFromSelection();
}
Expand All @@ -58,6 +59,11 @@ void ManipulationPivot::setNeedsRecalculation(bool needsRecalculation)
_needsRecalculation = needsRecalculation;
}

void ManipulationPivot::setUserLocked(bool locked)
{
_userLocked = locked;
}

// Call this before an operation is started, such that later
// transformations can be applied on top of the correct starting point
void ManipulationPivot::beginOperation()
Expand Down Expand Up @@ -89,6 +95,7 @@ void ManipulationPivot::applyTranslation(const Vector3& translation)
void ManipulationPivot::updateFromSelection()
{
_needsRecalculation = false;
_userLocked = false;

Vector3 objectPivot;

Expand Down
7 changes: 7 additions & 0 deletions radiant/selection/ManipulationPivot.h
Expand Up @@ -33,6 +33,9 @@ class ManipulationPivot
// During operations, we want to block pivot recalculations
bool _operationActive;

// "User has modified pivot"-flag, used to block pivot recalculations
bool _userLocked;

public:
ManipulationPivot();

Expand All @@ -50,6 +53,10 @@ class ManipulationPivot
// an updateFromSelection() next time getMatrix4() is called
void setNeedsRecalculation(bool needsRecalculation);

// If the user has placed the pivot manually, we want to refrain
// from recalculating it automatically.
void setUserLocked(bool locked);

// 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
20 changes: 19 additions & 1 deletion radiant/selection/RadiantSelectionSystem.cpp
Expand Up @@ -278,6 +278,9 @@ void RadiantSelectionSystem::setActiveManipulator(std::size_t manipulatorId)

_activeManipulator = found->second;

// Release the user lock when switching manipulators
_pivot.setUserLocked(false);

pivotChanged();
}

Expand All @@ -288,6 +291,10 @@ void RadiantSelectionSystem::setActiveManipulator(Manipulator::Type manipulatorT
if (pair.second->getType() == manipulatorType)
{
_activeManipulator = pair.second;

// Release the user lock when switching manipulators
_pivot.setUserLocked(false);

pivotChanged();
return;
}
Expand Down Expand Up @@ -349,6 +356,12 @@ void RadiantSelectionSystem::onSelectedChanged(const scene::INodePtr& node, cons

_requestWorkZoneRecalculation = true;
_requestSceneGraphChange = true;

// When everything is deselected, release the pivot user lock
if (_selection.empty())
{
_pivot.setUserLocked(false);
}
}

// greebo: This should be called "onComponentSelectionChanged", as it is a similar function of the above one
Expand Down Expand Up @@ -382,6 +395,11 @@ void RadiantSelectionSystem::onComponentSelection(const scene::INodePtr& node, c

_requestWorkZoneRecalculation = true;
_requestSceneGraphChange = true;

if (_componentSelection.empty())
{
_pivot.setUserLocked(false);
}
}

// Returns the last instance in the list (if the list is not empty)
Expand Down Expand Up @@ -830,7 +848,7 @@ void RadiantSelectionSystem::renderWireframe(RenderableCollector& collector, con
const Matrix4& RadiantSelectionSystem::getPivot2World() const
{
// Questionable const design - almost everything needs to be declared const here...
const_cast<RadiantSelectionSystem*>(this)->recalculatePivot2World();
//const_cast<RadiantSelectionSystem*>(this)->recalculatePivot2World();

return const_cast<RadiantSelectionSystem*>(this)->_pivot.getMatrix4();
}
Expand Down
3 changes: 3 additions & 0 deletions radiant/selection/manipulators/ManipulatorComponents.h
Expand Up @@ -190,6 +190,9 @@ class TranslatablePivot :
void translate(const Vector3& translation) override
{
_pivot.applyTranslation(translation);

// User is placing the pivot manually, so let's keep it that way
_pivot.setUserLocked(true);
}
};

Expand Down

0 comments on commit 38faf6a

Please sign in to comment.