From 23750b8c813b80738196126750883626128cf817 Mon Sep 17 00:00:00 2001 From: greerdv Date: Tue, 23 Nov 2021 11:34:31 +0000 Subject: [PATCH 1/3] fix direction of manipulator scaling for asset collider when axes are flipped Signed-off-by: greerdv --- Gems/PhysX/Code/CMakeLists.txt | 1 + .../Code/Editor/ColliderAssetScaleMode.cpp | 2 +- .../Tests/PhysXColliderComponentModeTests.cpp | 51 +++++++++++++++++++ Gems/PhysX/Code/Tests/TestColliderComponent.h | 16 +++--- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Gems/PhysX/Code/CMakeLists.txt b/Gems/PhysX/Code/CMakeLists.txt index bb3d7c08a2..164ce7c79c 100644 --- a/Gems/PhysX/Code/CMakeLists.txt +++ b/Gems/PhysX/Code/CMakeLists.txt @@ -224,6 +224,7 @@ if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) AZ::AzTestShared AZ::AzTest AZ::AzToolsFrameworkTestCommon + AZ::AzManipulatorTestFramework.Static Gem::PhysX.Static Gem::PhysX.Mocks Gem::PhysX.Editor.Static diff --git a/Gems/PhysX/Code/Editor/ColliderAssetScaleMode.cpp b/Gems/PhysX/Code/Editor/ColliderAssetScaleMode.cpp index ea08bb8160..67917bc49a 100644 --- a/Gems/PhysX/Code/Editor/ColliderAssetScaleMode.cpp +++ b/Gems/PhysX/Code/Editor/ColliderAssetScaleMode.cpp @@ -59,7 +59,7 @@ namespace PhysX m_dimensionsManipulators.InstallAxisMouseMoveCallback( [this, idPair] (const AzToolsFramework::LinearManipulator::Action& action) { - OnManipulatorMoved(action.LocalScaleOffset() + m_initialScale, idPair); + OnManipulatorMoved(action.m_start.m_sign * action.LocalScaleOffset() + m_initialScale, idPair); }); m_dimensionsManipulators.InstallUniformLeftMouseDownCallback( diff --git a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp index 1f393386f8..85168d17d0 100644 --- a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp +++ b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp @@ -8,10 +8,13 @@ #include "TestColliderComponent.h" +#include +#include #include #include #include #include +#include #include #include #include @@ -386,4 +389,52 @@ namespace UnitTest PhysX::ColliderComponentModeRequestBus::BroadcastResult(subMode, &PhysX::ColliderComponentModeRequests::GetCurrentMode); EXPECT_EQ(PhysX::ColliderComponentModeRequests::SubMode::Dimensions, subMode); } + + using PhysXColliderComponentModeManipulatorTest = + UnitTest::IndirectCallManipulatorViewportInteractionFixtureMixin; + + TEST_F(PhysXColliderComponentModeManipulatorTest, AssetScaleManipulatorsScaleInCorrectDirection) + { + auto colliderEntity = CreateColliderComponent(); + colliderEntity->FindComponent()->SetShapeType(Physics::ShapeType::PhysicsAsset); + colliderEntity->FindComponent()->SetAssetScale(AZ::Vector3::CreateOne()); + EnterComponentMode(); + PhysX::ColliderComponentModeRequestBus::Broadcast(&PhysX::ColliderComponentModeRequests::SetCurrentMode, + PhysX::ColliderComponentModeRequests::SubMode::Dimensions); + + // position the camera so the X axis manipulator will be flipped + AzFramework::SetCameraTransform( + m_cameraState, + AZ::Transform::CreateFromQuaternionAndTranslation( + AZ::Quaternion::CreateRotationZ(-AZ::Constants::QuarterPi), AZ::Vector3(-5.0f, -5.0f, 0.0f))); + + // select a point in world space slightly displaced from the position of the entity in the negative x direction + // in order to grab the X manipulator + const float x = 0.1f; + const float xDelta = 0.1f; + const AZ::Vector3 worldStart(-x, 0.0f, 0.0f); + + // position in world space to drag to + const AZ::Vector3 worldEnd(-(x + xDelta), 0.0f, 0.0f); + + const auto screenStart = AzFramework::WorldToScreen(worldStart, m_cameraState); + const auto screenEnd = AzFramework::WorldToScreen(worldEnd, m_cameraState); + + m_actionDispatcher + ->CameraState(m_cameraState) + // move the mouse to interact with the x scale manipulator + ->MousePosition(screenStart) + // drag to move the manipulator + ->MouseLButtonDown() + ->MousePosition(screenEnd) + ->MouseLButtonUp(); + + const auto WorldToScreenMultiplier = 1.0f / AzToolsFramework::CalculateScreenToWorldMultiplier(worldStart, m_cameraState); + const auto assetScale = colliderEntity->FindComponent()->GetAssetScale(); + // need quite a large tolerance because using screen co-ordinates limits precision + const float tolerance = 0.01f; + EXPECT_NEAR(assetScale.GetX(), 1.0f + xDelta * WorldToScreenMultiplier, tolerance); + EXPECT_NEAR(assetScale.GetY(), 1.0f, tolerance); + EXPECT_NEAR(assetScale.GetZ(), 1.0f, tolerance); + } } // namespace UnitTest diff --git a/Gems/PhysX/Code/Tests/TestColliderComponent.h b/Gems/PhysX/Code/Tests/TestColliderComponent.h index 91d3f16122..52b208ea80 100644 --- a/Gems/PhysX/Code/Tests/TestColliderComponent.h +++ b/Gems/PhysX/Code/Tests/TestColliderComponent.h @@ -67,13 +67,13 @@ namespace UnitTest private: AzToolsFramework::ComponentModeFramework::ComponentModeDelegate m_componentModeDelegate; - AZ::Vector3 m_offset; - AZ::Quaternion m_rotation; - AZ::Transform m_transform; - Physics::ShapeType m_shapeType; - float m_sphereRadius; - float m_capsuleHeight; - float m_capsuleRadius; - AZ::Vector3 m_assetScale; + AZ::Vector3 m_offset = AZ::Vector3::CreateZero(); + AZ::Quaternion m_rotation = AZ::Quaternion::CreateIdentity(); + AZ::Transform m_transform = AZ::Transform::CreateIdentity(); + Physics::ShapeType m_shapeType = Physics::ShapeType::PhysicsAsset; + float m_sphereRadius = 0.5f; + float m_capsuleHeight = 1.0f; + float m_capsuleRadius = 0.25f; + AZ::Vector3 m_assetScale = AZ::Vector3::CreateOne(); }; } // namespace UnitTest From 75d7c61ba1070cc167ef9fe01bf73eadcbf3a20f Mon Sep 17 00:00:00 2001 From: greerdv Date: Tue, 23 Nov 2021 21:25:50 +0000 Subject: [PATCH 2/3] fix variable capitalization Signed-off-by: greerdv --- Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp index 85168d17d0..c3966daea7 100644 --- a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp +++ b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp @@ -429,11 +429,11 @@ namespace UnitTest ->MousePosition(screenEnd) ->MouseLButtonUp(); - const auto WorldToScreenMultiplier = 1.0f / AzToolsFramework::CalculateScreenToWorldMultiplier(worldStart, m_cameraState); + const auto worldToScreenMultiplier = 1.0f / AzToolsFramework::CalculateScreenToWorldMultiplier(worldStart, m_cameraState); const auto assetScale = colliderEntity->FindComponent()->GetAssetScale(); // need quite a large tolerance because using screen co-ordinates limits precision const float tolerance = 0.01f; - EXPECT_NEAR(assetScale.GetX(), 1.0f + xDelta * WorldToScreenMultiplier, tolerance); + EXPECT_NEAR(assetScale.GetX(), 1.0f + xDelta * worldToScreenMultiplier, tolerance); EXPECT_NEAR(assetScale.GetY(), 1.0f, tolerance); EXPECT_NEAR(assetScale.GetZ(), 1.0f, tolerance); } From f32bf3db8af728a5d3561a891d1d2f514a7b287a Mon Sep 17 00:00:00 2001 From: greerdv Date: Wed, 24 Nov 2021 09:39:50 +0000 Subject: [PATCH 3/3] fix typo in include Signed-off-by: greerdv --- Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp index 76c7f54266..5722d1a397 100644 --- a/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp +++ b/Gems/PhysX/Code/Tests/PhysXColliderComponentModeTests.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include