From e0fc4cd9850786e87cf6f4442854470ecbc2cfe3 Mon Sep 17 00:00:00 2001 From: greerdv Date: Tue, 25 May 2021 13:11:05 +0100 Subject: [PATCH] some tidying up --- .../AzCore/Math/TransformSerializer.cpp | 4 +++ .../Code/Source/Shape/PolygonPrismShape.cpp | 12 ++++++--- .../Code/Source/Shape/ShapeDisplay.h | 6 ++++- .../Code/Source/Shape/TubeShape.cpp | 25 +++++++++++++------ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Math/TransformSerializer.cpp b/Code/Framework/AzCore/AzCore/Math/TransformSerializer.cpp index 46440ac000..86bc1c36ea 100644 --- a/Code/Framework/AzCore/AzCore/Math/TransformSerializer.cpp +++ b/Code/Framework/AzCore/AzCore/Math/TransformSerializer.cpp @@ -58,6 +58,8 @@ namespace AZ } { + // Scale is transitioning to a single uniform scale value, but since it's still internally represented as a Vector3, + // we need to pick one number to use for load/store operations. float scale = transformInstance->GetUniformScale(); JSR::ResultCode loadResult = @@ -120,6 +122,8 @@ namespace AZ { AZ::ScopedContextPath subPathName(context, ScaleTag); + // Scale is transitioning to a single uniform scale value, but since it's still internally represented as a Vector3, + // we need to pick one number to use for load/store operations. float scale = transformInstance->GetUniformScale(); float defaultScale = defaultTransformInstance ? defaultTransformInstance->GetUniformScale() : 0.0f; diff --git a/Gems/LmbrCentral/Code/Source/Shape/PolygonPrismShape.cpp b/Gems/LmbrCentral/Code/Source/Shape/PolygonPrismShape.cpp index be910f7bfa..4244199b85 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/PolygonPrismShape.cpp +++ b/Gems/LmbrCentral/Code/Source/Shape/PolygonPrismShape.cpp @@ -433,18 +433,21 @@ namespace LmbrCentral const float height = polygonPrism.GetHeight(); const AZ::Vector3& nonUniformScale = polygonPrism.GetNonUniformScale(); + AZ::Transform worldFromLocalUniformScale = worldFromLocal; + worldFromLocalUniformScale.SetUniformScale(worldFromLocalUniformScale.GetUniformScale()); + AZ::Aabb aabb = AZ::Aabb::CreateNull(); // check base of prism for (const AZ::Vector2& vertex : vertexContainer.GetVertices()) { - aabb.AddPoint(worldFromLocal.TransformPoint(nonUniformScale * AZ::Vector3(vertex.GetX(), vertex.GetY(), 0.0f))); + aabb.AddPoint(worldFromLocalUniformScale.TransformPoint(nonUniformScale * AZ::Vector3(vertex.GetX(), vertex.GetY(), 0.0f))); } // check top of prism // set aabb to be height of prism - ensure entire polygon prism shape is enclosed in aabb for (const AZ::Vector2& vertex : vertexContainer.GetVertices()) { - aabb.AddPoint(worldFromLocal.TransformPoint(nonUniformScale * AZ::Vector3(vertex.GetX(), vertex.GetY(), height))); + aabb.AddPoint(worldFromLocalUniformScale.TransformPoint(nonUniformScale * AZ::Vector3(vertex.GetX(), vertex.GetY(), height))); } return aabb; @@ -460,10 +463,13 @@ namespace LmbrCentral const AZStd::vector& vertices = polygonPrism.m_vertexContainer.GetVertices(); const size_t vertexCount = vertices.size(); + AZ::Transform worldFromLocalWithUniformScale = worldFromLocal; + worldFromLocalWithUniformScale.SetUniformScale(worldFromLocalWithUniformScale.GetUniformScale()); + // transform point to local space // it's fine to invert the transform including scale here, because it won't affect whether the point is inside the prism const AZ::Vector3 localPoint = - worldFromLocal.GetInverse().TransformPoint(point) / polygonPrism.GetNonUniformScale(); + worldFromLocalWithUniformScale.GetInverse().TransformPoint(point) / polygonPrism.GetNonUniformScale(); // ensure the point is not above or below the prism (in its local space) if (localPoint.GetZ() < 0.0f || localPoint.GetZ() > polygonPrism.GetHeight()) diff --git a/Gems/LmbrCentral/Code/Source/Shape/ShapeDisplay.h b/Gems/LmbrCentral/Code/Source/Shape/ShapeDisplay.h index 3591ecde36..5b5cc5fb4d 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/ShapeDisplay.h +++ b/Gems/LmbrCentral/Code/Source/Shape/ShapeDisplay.h @@ -42,7 +42,11 @@ namespace LmbrCentral return; } - debugDisplay.PushMatrix(worldFromLocal); + // only uniform scale is supported in physics so the debug visuals reflect this fact + AZ::Transform worldFromLocalWithUniformScale = worldFromLocal; + worldFromLocalWithUniformScale.SetUniformScale(worldFromLocalWithUniformScale.GetUniformScale()); + + debugDisplay.PushMatrix(worldFromLocalWithUniformScale); drawShape(debugDisplay); diff --git a/Gems/LmbrCentral/Code/Source/Shape/TubeShape.cpp b/Gems/LmbrCentral/Code/Source/Shape/TubeShape.cpp index fde4290d6d..0db2660e01 100644 --- a/Gems/LmbrCentral/Code/Source/Shape/TubeShape.cpp +++ b/Gems/LmbrCentral/Code/Source/Shape/TubeShape.cpp @@ -216,7 +216,10 @@ namespace LmbrCentral return AZ::Aabb::CreateNull(); } - return CalculateTubeBounds(*this, m_currentTransform); + AZ::Transform worldFromLocalUniformScale = m_currentTransform; + worldFromLocalUniformScale.SetUniformScale(worldFromLocalUniformScale.GetUniformScale()); + + return CalculateTubeBounds(*this, worldFromLocalUniformScale); } void TubeShape::GetTransformAndLocalBounds(AZ::Transform& transform, AZ::Aabb& bounds) @@ -232,8 +235,10 @@ namespace LmbrCentral return false; } - const float scale = m_currentTransform.GetUniformScale(); - const AZ::Vector3 localPoint = m_currentTransform.GetInverse().TransformPoint(point); + AZ::Transform worldFromLocalNormalized = m_currentTransform; + const float scale = worldFromLocalNormalized.ExtractUniformScale(); + const AZ::Transform localFromWorldNormalized = worldFromLocalNormalized.GetInverse(); + const AZ::Vector3 localPoint = localFromWorldNormalized.TransformPoint(point) / scale; const auto address = m_spline->GetNearestAddressPosition(localPoint).m_splineAddress; const float radiusSq = powf(m_radius, 2.0f); @@ -245,20 +250,24 @@ namespace LmbrCentral float TubeShape::DistanceSquaredFromPoint(const AZ::Vector3& point) { - const float scale = m_currentTransform.GetUniformScale(); - const AZ::Transform localFromWorld = m_currentTransform.GetInverse(); - const AZ::Vector3 localPoint = localFromWorld.TransformPoint(point); + AZ::Transform worldFromLocalNormalized = m_currentTransform; + const float uniformScale = worldFromLocalNormalized.ExtractUniformScale(); + const AZ::Transform localFromWorldNormalized = worldFromLocalNormalized.GetInverse(); + const AZ::Vector3 localPoint = localFromWorldNormalized.TransformPoint(point) / uniformScale; const auto splineQueryResult = m_spline->GetNearestAddressPosition(localPoint); const float variableRadius = m_variableRadius.GetElementInterpolated(splineQueryResult.m_splineAddress, Lerpf); - return powf((sqrtf(splineQueryResult.m_distanceSq) - (m_radius + variableRadius)) * scale, 2.0f); + return powf((sqrtf(splineQueryResult.m_distanceSq) - (m_radius + variableRadius)) * uniformScale, 2.0f); } bool TubeShape::IntersectRay(const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) { - const auto splineQueryResult = IntersectSpline(m_currentTransform, src, dir, *m_spline); + AZ::Transform transformUniformScale = m_currentTransform; + transformUniformScale.SetUniformScale(transformUniformScale.GetUniformScale()); + + const auto splineQueryResult = IntersectSpline(transformUniformScale, src, dir, *m_spline); const float variableRadius = m_variableRadius.GetElementInterpolated( splineQueryResult.m_splineAddress, Lerpf);