Merge pull request #5863 from aws-lumberyard-dev/asset-collider-manip-direction

fix direction of manipulator scaling for asset collider when axes are…
This commit is contained in:
greerdv
2021-11-24 12:44:01 +00:00
committed by GitHub
4 changed files with 61 additions and 9 deletions
+1
View File
@@ -216,6 +216,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
@@ -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(
@@ -8,10 +8,13 @@
#include "TestColliderComponent.h"
#include <AzManipulatorTestFramework/IndirectManipulatorViewportInteraction.h>
#include <AzManipulatorTestFramework/AzManipulatorTestFrameworkTestHelpers.h>
#include <AZTestShared/Math/MathTestHelpers.h>
#include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
#include <AzToolsFramework/ViewportSelection/EditorInteractionSystemViewportSelectionRequestBus.h>
#include <AzToolsFramework/ViewportSelection/EditorDefaultSelection.h>
#include <AzToolsFramework/ViewportSelection/EditorSelectionUtil.h>
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
#include <AzToolsFramework/ViewportUi/ViewportUiManager.h>
#include <Tests/Viewport/ViewportUiManagerTests.cpp>
@@ -386,4 +389,52 @@ namespace UnitTest
PhysX::ColliderComponentModeRequestBus::BroadcastResult(subMode, &PhysX::ColliderComponentModeRequests::GetCurrentMode);
EXPECT_EQ(PhysX::ColliderComponentModeRequests::SubMode::Dimensions, subMode);
}
using PhysXColliderComponentModeManipulatorTest =
UnitTest::IndirectCallManipulatorViewportInteractionFixtureMixin<PhysXColliderComponentModeTest>;
TEST_F(PhysXColliderComponentModeManipulatorTest, AssetScaleManipulatorsScaleInCorrectDirection)
{
auto colliderEntity = CreateColliderComponent();
colliderEntity->FindComponent<TestColliderComponentMode>()->SetShapeType(Physics::ShapeType::PhysicsAsset);
colliderEntity->FindComponent<TestColliderComponentMode>()->SetAssetScale(AZ::Vector3::CreateOne());
EnterComponentMode<TestColliderComponentMode>();
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<TestColliderComponentMode>()->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
@@ -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