diff --git a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp index 143fe59ca7..06443c0698 100644 --- a/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp +++ b/Code/Framework/AzCore/AzCore/Math/Quaternion.cpp @@ -348,13 +348,20 @@ namespace AZ return result.GetW() >= 0.0f ? result : -result; } - const Quaternion Quaternion::CreateFromEulerAnglesDegrees(Vector3& anglesInDegrees) + const Quaternion Quaternion::CreateFromEulerAnglesDegrees(const Vector3& anglesInDegrees) { Quaternion result; result.SetFromEulerDegrees(anglesInDegrees); return result; } + const Quaternion Quaternion::CreateFromEulerAnglesRadians(const Vector3& anglesInRadians) + { + Quaternion result; + result.SetFromEulerRadians(anglesInRadians); + return result; + } + Quaternion Quaternion::Slerp(const Quaternion& dest, float t) const { const float DestDot = Dot(dest); diff --git a/Code/Framework/AzCore/AzCore/Math/Quaternion.h b/Code/Framework/AzCore/AzCore/Math/Quaternion.h index c4502063de..be8ac3e841 100644 --- a/Code/Framework/AzCore/AzCore/Math/Quaternion.h +++ b/Code/Framework/AzCore/AzCore/Math/Quaternion.h @@ -84,7 +84,10 @@ namespace AZ static Quaternion CreateShortestArc(const Vector3& v1, const Vector3& v2); /// Creates a quaternion using rotation in degrees about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis. - static const Quaternion CreateFromEulerAnglesDegrees(Vector3& anglesInDegrees); + static const Quaternion CreateFromEulerAnglesDegrees(const Vector3& anglesInDegrees); + + /// Creates a quaternion using rotation in radians about the axes. First rotated about the X axis, followed by the Y axis, then the Z axis. + static const Quaternion CreateFromEulerAnglesRadians(const Vector3& anglesInRadians); //! Stores the vector to an array of 4 floats. The floats need only be 4 byte aligned, 16 byte alignment is not required. void StoreToFloat4(float* values) const; diff --git a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp index 8d5cbef030..3dafc7c717 100644 --- a/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp +++ b/Code/Framework/AzFramework/AzFramework/Components/TransformComponent.cpp @@ -432,17 +432,14 @@ namespace AzFramework void TransformComponent::SetLocalRotation(const AZ::Vector3& eulerRadianAngles) { - AZ::Transform newLocalTM = AZ::ConvertEulerRadiansToTransform(eulerRadianAngles); - newLocalTM.SetScale(m_localTM.GetScale()); - newLocalTM.SetTranslation(m_localTM.GetTranslation()); + AZ::Transform newLocalTM = m_localTM; + newLocalTM.SetRotation(AZ::Quaternion::CreateFromEulerAnglesRadians(eulerRadianAngles)); SetLocalTM(newLocalTM); } void TransformComponent::SetLocalRotationQuaternion(const AZ::Quaternion& quaternion) { - AZ::Transform newLocalTM; - newLocalTM.SetScale(m_localTM.GetScale()); - newLocalTM.SetTranslation(m_localTM.GetTranslation()); + AZ::Transform newLocalTM = m_localTM; newLocalTM.SetRotation(quaternion); SetLocalTM(newLocalTM); } diff --git a/Code/Framework/AzToolsFramework/Tests/Slice.cpp b/Code/Framework/AzToolsFramework/Tests/Slice.cpp index 33160b9c20..7b67481684 100644 --- a/Code/Framework/AzToolsFramework/Tests/Slice.cpp +++ b/Code/Framework/AzToolsFramework/Tests/Slice.cpp @@ -483,6 +483,9 @@ namespace UnitTest { AUTO_RESULT_IF_SETTING_TRUE(UnitTest::prefabSystemSetting, true) + // Swallow deprecation warnings from the Transform component as they are not relevant to this test + UnitTest::ErrorHandler errorHandler("GetScale is deprecated"); + // Create a parent entity with a transform component AZ::Entity* parentEntity = aznew AZ::Entity("TestParentEntity"); parentEntity->CreateComponent(); diff --git a/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorLayerComponentTests.cpp b/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorLayerComponentTests.cpp index 7b03b63dd0..2177b9e1b2 100644 --- a/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorLayerComponentTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorLayerComponentTests.cpp @@ -610,15 +610,15 @@ namespace AzToolsFramework m_layerEntity.m_layer->ClearUnsavedChanges(); // Change the scale of the child entity so it registers as an unsaved change on the layer. - AZ::Vector3 scale(-1.0f,0.0f,0.0f); + float scale = 0.0f; AZ::TransformBus::EventResult( scale, childEntity->GetId(), - &AZ::TransformBus::Events::GetLocalScale); - scale.SetX(scale.GetX() + 1.0f); + &AZ::TransformBus::Events::GetLocalUniformScale); + scale += 1.0f; AZ::TransformBus::Event( childEntity->GetId(), - &AZ::TransformBus::Events::SetLocalScale, + &AZ::TransformBus::Events::SetLocalUniformScale, scale); bool hasUnsavedChanges = false; diff --git a/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorTransformComponentTests.cpp b/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorTransformComponentTests.cpp index 62cf16f9a7..fcc4aa49e5 100644 --- a/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorTransformComponentTests.cpp +++ b/Code/Framework/AzToolsFramework/Tests/ToolsComponents/EditorTransformComponentTests.cpp @@ -52,19 +52,19 @@ namespace AzToolsFramework TransformTestEntityHierarchy hierarchy = BuildTestHierarchy(); // Set scale to parent entity - const AZ::Vector3 parentScale(2.0f, 1.0f, 3.0f); - AZ::TransformBus::Event(hierarchy.m_parentId, &AZ::TransformInterface::SetLocalScale, parentScale); + const float parentScale = 2.0f; + AZ::TransformBus::Event(hierarchy.m_parentId, &AZ::TransformInterface::SetLocalUniformScale, parentScale); // Set scale to child entity - const AZ::Vector3 childScale(5.0f, 6.0f, 10.0f); - AZ::TransformBus::Event(hierarchy.m_childId, &AZ::TransformInterface::SetLocalScale, childScale); + const float childScale = 5.0f; + AZ::TransformBus::Event(hierarchy.m_childId, &AZ::TransformInterface::SetLocalUniformScale, childScale); - const AZ::Vector3 expectedScale = childScale * parentScale; + const float expectedScale = childScale * parentScale; - AZ::Vector3 childWorldScale = AZ::Vector3::CreateOne(); - AZ::TransformBus::EventResult(childWorldScale, hierarchy.m_childId, &AZ::TransformBus::Events::GetWorldScale); + float childWorldScale = 1.0f; + AZ::TransformBus::EventResult(childWorldScale, hierarchy.m_childId, &AZ::TransformBus::Events::GetWorldUniformScale); - EXPECT_THAT(childWorldScale, UnitTest::IsClose(expectedScale)); + EXPECT_NEAR(childWorldScale, expectedScale, AZ::Constants::Tolerance); } TEST_F(EditorTransformComponentTest, TransformTests_GetChildren_DirectChildrenMatchHierarchy)