extract reused manipulator scaling logic
Signed-off-by: greerdv <greerdv@amazon.com>
This commit is contained in:
+13
-14
@@ -93,29 +93,20 @@ namespace AzToolsFramework
|
||||
linearManipulator->SetViews(AZStd::move(views));
|
||||
|
||||
linearManipulator->InstallMouseMoveCallback(
|
||||
[this, entityComponentIdPair](
|
||||
const LinearManipulator::Action& action)
|
||||
[this, entityComponentIdPair,
|
||||
transformScale{ linearManipulator->GetSpace().GetUniformScale() }](const LinearManipulator::Action& action)
|
||||
{
|
||||
AZ::Transform boxLocalTransform = AZ::Transform::CreateIdentity();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
boxLocalTransform, entityComponentIdPair, &BoxManipulatorRequests::GetCurrentLocalTransform);
|
||||
|
||||
AZ::Transform boxWorldTransform = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(
|
||||
boxWorldTransform, m_entityComponentIdPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
float boxScale = AZ::GetMax(AZ::MinTransformScale, boxWorldTransform.GetUniformScale());
|
||||
|
||||
// calculate the position of the manipulator in the reference frame of the box
|
||||
// the local position offset of the manipulator does not take the transform scale into account
|
||||
// so need to apply it here
|
||||
const AZ::Vector3 localPosition = boxLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition + action.m_current.m_localPositionOffset / boxScale);
|
||||
const AZ::Vector3 manipulatorPosition = GetPositionInManipulatorFrame(transformScale, boxLocalTransform, action);
|
||||
|
||||
// calculate the amount of displacement along an axis this manipulator has moved
|
||||
// clamp movement so it cannot go negative based on axis direction
|
||||
const AZ::Vector3 axisDisplacement =
|
||||
localPosition.GetAbs() * 2.0f
|
||||
* AZ::GetMax(0.0f, localPosition.GetNormalized().Dot(action.m_fixed.m_axis));
|
||||
manipulatorPosition.GetAbs() * 2.0f
|
||||
* AZ::GetMax(0.0f, manipulatorPosition.GetNormalized().Dot(action.m_fixed.m_axis));
|
||||
|
||||
AZ::Vector3 boxDimensions = AZ::Vector3::CreateZero();
|
||||
BoxManipulatorRequestBus::EventResult(
|
||||
@@ -148,4 +139,12 @@ namespace AzToolsFramework
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AZ::Vector3 GetPositionInManipulatorFrame(float worldUniformScale, const AZ::Transform& manipulatorLocalTransform,
|
||||
const LinearManipulator::Action& action)
|
||||
{
|
||||
return manipulatorLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition +
|
||||
action.m_current.m_localPositionOffset / AZ::GetClamp(worldUniformScale, AZ::MinTransformScale, AZ::MaxTransformScale));
|
||||
}
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
@@ -31,4 +31,10 @@ namespace AzToolsFramework
|
||||
using BoxManipulators = AZStd::array<AZStd::shared_ptr<LinearManipulator>, 6>;
|
||||
BoxManipulators m_linearManipulators; ///< Manipulators for editing box size.
|
||||
};
|
||||
|
||||
/// Calculates the position of the manipulator in its own reference frame.
|
||||
/// Removes the effects of the manipulator local transform, and accounts for world transform scale in
|
||||
/// the action local offset.
|
||||
AZ::Vector3 GetPositionInManipulatorFrame(float worldUniformScale, const AZ::Transform& manipulatorLocalTransform,
|
||||
const LinearManipulator::Action& action);
|
||||
} // namespace AzToolsFramework
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <AzToolsFramework/Manipulators/LinearManipulator.h>
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
#include <AzToolsFramework/ComponentModes/BoxViewportEdit.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AzFramework/Viewport/ViewportColors.h>
|
||||
@@ -175,15 +176,12 @@ namespace PhysX
|
||||
void ColliderCapsuleMode::OnRadiusManipulatorMoved(const AzToolsFramework::LinearManipulator::Action& action, const AZ::EntityComponentIdPair& idPair)
|
||||
{
|
||||
// manipulator action offsets do not take entity transform scale into account, so need to apply it here
|
||||
float transformScale = 1.0f;
|
||||
const AZ::Transform colliderLocalTransform = Utils::GetColliderLocalTransform(idPair);
|
||||
AZ::TransformBus::EventResult(transformScale, idPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldUniformScale);
|
||||
transformScale = AZ::GetMax(AZ::MinTransformScale, transformScale);
|
||||
const AZ::Vector3 localPosition = colliderLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition + action.m_current.m_localPositionOffset / transformScale);
|
||||
const AZ::Vector3 manipulatorPosition = AzToolsFramework::GetPositionInManipulatorFrame(
|
||||
m_radiusManipulator->GetSpace().GetUniformScale(), colliderLocalTransform, action);
|
||||
|
||||
// Get the distance the manipulator has moved along the axis.
|
||||
float extent = localPosition.Dot(action.m_fixed.m_axis);
|
||||
float extent = manipulatorPosition.Dot(action.m_fixed.m_axis);
|
||||
|
||||
// Clamp radius to a small value.
|
||||
extent = AZ::GetMax(extent, MinCapsuleRadius);
|
||||
@@ -201,15 +199,12 @@ namespace PhysX
|
||||
void ColliderCapsuleMode::OnHeightManipulatorMoved(const AzToolsFramework::LinearManipulator::Action& action, const AZ::EntityComponentIdPair& idPair)
|
||||
{
|
||||
// manipulator action offsets do not take entity transform scale into account, so need to apply it here
|
||||
float transformScale = 1.0f;
|
||||
const AZ::Transform colliderLocalTransform = Utils::GetColliderLocalTransform(idPair);
|
||||
AZ::TransformBus::EventResult(transformScale, idPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldUniformScale);
|
||||
transformScale = AZ::GetMax(AZ::MinTransformScale, transformScale);
|
||||
const AZ::Vector3 localPosition = colliderLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition + action.m_current.m_localPositionOffset / transformScale);
|
||||
const AZ::Vector3 manipulatorPosition = AzToolsFramework::GetPositionInManipulatorFrame(
|
||||
m_heightManipulator->GetSpace().GetUniformScale(), colliderLocalTransform, action);
|
||||
|
||||
// Get the distance the manipulator has moved along the axis.
|
||||
float extent = localPosition.Dot(action.m_fixed.m_axis);
|
||||
float extent = manipulatorPosition.Dot(action.m_fixed.m_axis);
|
||||
|
||||
// Ensure capsule's half height is always greater than the radius.
|
||||
extent = AZ::GetMax(extent, MinCapsuleHeight);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <AzToolsFramework/Manipulators/LinearManipulator.h>
|
||||
#include <AzToolsFramework/Manipulators/ManipulatorManager.h>
|
||||
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
|
||||
#include <AzToolsFramework/ComponentModes/BoxViewportEdit.h>
|
||||
#include <AzCore/Component/TransformBus.h>
|
||||
#include <AzCore/Component/NonUniformScaleBus.h>
|
||||
#include <AzCore/Math/ToString.h>
|
||||
@@ -110,15 +111,12 @@ namespace PhysX
|
||||
void ColliderSphereMode::OnManipulatorMoved(const AzToolsFramework::LinearManipulator::Action& action, const AZ::EntityComponentIdPair& idPair)
|
||||
{
|
||||
// manipulator offsets do not take transform scale into account, need to handle it here
|
||||
AZ::Transform colliderWorldTransform = AZ::Transform::CreateIdentity();
|
||||
AZ::TransformBus::EventResult(colliderWorldTransform, idPair.GetEntityId(), &AZ::TransformBus::Events::GetWorldTM);
|
||||
const AZ::Transform colliderLocalTransform = Utils::GetColliderLocalTransform(idPair);
|
||||
const float transformScale = AZ::GetMax(AZ::MinTransformScale, colliderWorldTransform.GetUniformScale());
|
||||
const AZ::Vector3 localPosition = colliderLocalTransform.GetInverse().TransformPoint(
|
||||
action.m_start.m_localPosition + action.m_current.m_localPositionOffset / transformScale);
|
||||
const AZ::Vector3 manipulatorPosition = AzToolsFramework::GetPositionInManipulatorFrame(
|
||||
m_radiusManipulator->GetSpace().GetUniformScale(), colliderLocalTransform, action);
|
||||
|
||||
// Get the distance the manipulator has moved along the axis.
|
||||
float extent = localPosition.Dot(action.m_fixed.m_axis);
|
||||
float extent = manipulatorPosition.Dot(action.m_fixed.m_axis);
|
||||
|
||||
// Clamp the distance to a small value to prevent it going negative.
|
||||
extent = AZ::GetMax(extent, MinSphereRadius);
|
||||
|
||||
Reference in New Issue
Block a user