From 9f03e4f4fbc42394ba87ba11e8226f2515593abd Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Wed, 17 Nov 2021 10:19:25 +0000 Subject: [PATCH 1/2] LYN-6430 Add debug draw for heightfields. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- Gems/PhysX/Code/Editor/DebugDraw.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Gems/PhysX/Code/Editor/DebugDraw.cpp b/Gems/PhysX/Code/Editor/DebugDraw.cpp index 90a1eb6004..403fcd7ce6 100644 --- a/Gems/PhysX/Code/Editor/DebugDraw.cpp +++ b/Gems/PhysX/Code/Editor/DebugDraw.cpp @@ -687,6 +687,30 @@ namespace PhysX [[maybe_unused]] const AZ::Vector3& colliderScale, [[maybe_unused]] const bool forceUniformScaling) const { + const float minXBounds = -(heightfieldShapeConfig.GetNumColumns() * heightfieldShapeConfig.GetGridResolution().GetX()) / 2.0f; + const float minYBounds = -(heightfieldShapeConfig.GetNumRows() * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; + + for (int xIndex = 0; xIndex < heightfieldShapeConfig.GetNumColumns() - 1; xIndex++) + { + for (int yIndex = 0; yIndex < heightfieldShapeConfig.GetNumRows() - 1; yIndex++) + { + const int index0 = yIndex * heightfieldShapeConfig.GetNumColumns() + xIndex; + const int index1 = yIndex * heightfieldShapeConfig.GetNumColumns() + xIndex + 1; + const int index2 = (yIndex + 1) * heightfieldShapeConfig.GetNumColumns() + xIndex + 1; + const int index3 = (yIndex + 1) * heightfieldShapeConfig.GetNumColumns() + xIndex; + + const float x0 = minXBounds + heightfieldShapeConfig.GetGridResolution().GetX() * xIndex; + const float x1 = minXBounds + heightfieldShapeConfig.GetGridResolution().GetX() * (xIndex + 1); + const float y0 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * (yIndex + 1); + const float y1 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * yIndex; + + debugDisplay.DrawWireQuad( + AZ::Vector3(x0, y0, heightfieldShapeConfig.GetSamples()[index0].m_height), + AZ::Vector3(x1, y0, heightfieldShapeConfig.GetSamples()[index1].m_height), + AZ::Vector3(x1, y1, heightfieldShapeConfig.GetSamples()[index2].m_height), + AZ::Vector3(x0, y1, heightfieldShapeConfig.GetSamples()[index3].m_height)); + } + } } AZ::Transform Collider::GetColliderLocalTransform( From 9ebb7f5c224ab9aa3025fe8232c3bc48df854873 Mon Sep 17 00:00:00 2001 From: sphrose <82213493+sphrose@users.noreply.github.com> Date: Tue, 30 Nov 2021 11:54:21 +0000 Subject: [PATCH 2/2] review changes. Signed-off-by: sphrose <82213493+sphrose@users.noreply.github.com> --- Gems/PhysX/Code/Editor/DebugDraw.cpp | 55 ++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/Gems/PhysX/Code/Editor/DebugDraw.cpp b/Gems/PhysX/Code/Editor/DebugDraw.cpp index 403fcd7ce6..a54230ec38 100644 --- a/Gems/PhysX/Code/Editor/DebugDraw.cpp +++ b/Gems/PhysX/Code/Editor/DebugDraw.cpp @@ -687,28 +687,51 @@ namespace PhysX [[maybe_unused]] const AZ::Vector3& colliderScale, [[maybe_unused]] const bool forceUniformScaling) const { - const float minXBounds = -(heightfieldShapeConfig.GetNumColumns() * heightfieldShapeConfig.GetGridResolution().GetX()) / 2.0f; - const float minYBounds = -(heightfieldShapeConfig.GetNumRows() * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; + const int numColumns = heightfieldShapeConfig.GetNumColumns(); + const int numRows = heightfieldShapeConfig.GetNumRows(); - for (int xIndex = 0; xIndex < heightfieldShapeConfig.GetNumColumns() - 1; xIndex++) + const float minXBounds = -(numColumns * heightfieldShapeConfig.GetGridResolution().GetX()) / 2.0f; + const float minYBounds = -(numRows * heightfieldShapeConfig.GetGridResolution().GetY()) / 2.0f; + + auto heights = heightfieldShapeConfig.GetSamples(); + + for (int xIndex = 0; xIndex < numColumns - 1; xIndex++) { - for (int yIndex = 0; yIndex < heightfieldShapeConfig.GetNumRows() - 1; yIndex++) + for (int yIndex = 0; yIndex < numRows - 1; yIndex++) { - const int index0 = yIndex * heightfieldShapeConfig.GetNumColumns() + xIndex; - const int index1 = yIndex * heightfieldShapeConfig.GetNumColumns() + xIndex + 1; - const int index2 = (yIndex + 1) * heightfieldShapeConfig.GetNumColumns() + xIndex + 1; - const int index3 = (yIndex + 1) * heightfieldShapeConfig.GetNumColumns() + xIndex; + const int index0 = yIndex * numColumns + xIndex; + const int index1 = yIndex * numColumns + xIndex + 1; + const int index2 = (yIndex + 1) * numColumns + xIndex; + const int index3 = (yIndex + 1) * numColumns + xIndex + 1; const float x0 = minXBounds + heightfieldShapeConfig.GetGridResolution().GetX() * xIndex; const float x1 = minXBounds + heightfieldShapeConfig.GetGridResolution().GetX() * (xIndex + 1); - const float y0 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * (yIndex + 1); - const float y1 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * yIndex; - - debugDisplay.DrawWireQuad( - AZ::Vector3(x0, y0, heightfieldShapeConfig.GetSamples()[index0].m_height), - AZ::Vector3(x1, y0, heightfieldShapeConfig.GetSamples()[index1].m_height), - AZ::Vector3(x1, y1, heightfieldShapeConfig.GetSamples()[index2].m_height), - AZ::Vector3(x0, y1, heightfieldShapeConfig.GetSamples()[index3].m_height)); + const float y0 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * yIndex; + const float y1 = minYBounds + heightfieldShapeConfig.GetGridResolution().GetY() * (yIndex + 1); + + // Always draw top and left line of quad + debugDisplay.DrawLine( + AZ::Vector3(x0, y0, heights[index0].m_height), + AZ::Vector3(x1, y0, heights[index1].m_height)); + debugDisplay.DrawLine( + AZ::Vector3(x0, y0, heights[index0].m_height), + AZ::Vector3(x0, y1, heights[index2].m_height)); + + // Draw bottom line in last row + if (yIndex == numRows - 2) + { + debugDisplay.DrawLine( + AZ::Vector3(x1, y1, heights[index3].m_height), + AZ::Vector3(x0, y1, heights[index2].m_height)); + } + + // Draw right line in last column + if (xIndex == numColumns - 2) + { + debugDisplay.DrawLine( + AZ::Vector3(x1, y0, heights[index1].m_height), + AZ::Vector3(x1, y1, heights[index3].m_height)); + } } } }