ソースを参照

Merge pull request #5695 from aws-lumberyard-dev/terrain/sphrose/heightfield_debugdraw

LYN-6430 Add debug draw for heightfields.
sphrose 3 年 前
コミット
e64df3c141
1 ファイル変更47 行追加0 行削除
  1. 47 0
      Gems/PhysX/Code/Editor/DebugDraw.cpp

+ 47 - 0
Gems/PhysX/Code/Editor/DebugDraw.cpp

@@ -687,6 +687,53 @@ namespace PhysX
             [[maybe_unused]] const AZ::Vector3& colliderScale,
             [[maybe_unused]] const bool forceUniformScaling) const
         {
+            const int numColumns = heightfieldShapeConfig.GetNumColumns();
+            const int numRows = heightfieldShapeConfig.GetNumRows();
+
+            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 < numRows - 1; yIndex++)
+                {
+                    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;
+                    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));
+                    }
+                }
+            }
         }
 
         AZ::Transform Collider::GetColliderLocalTransform(