Class HeightfieldCollisionShape

All Implemented Interfaces:
Comparable<NativePhysicsObject>

public class HeightfieldCollisionShape extends CollisionShape
A collision shape for terrain defined by a matrix of height values, based on Bullet's btHeightfieldTerrainShape. Should be more efficient than an equivalent MeshCollisionShape. Not for use in dynamic bodies. Collisions between HeightfieldCollisionShape, MeshCollisionShape, and PlaneCollisionShape objects are never detected.
  • Field Details

    • logger2

      public static final Logger logger2
      message logger for this class
  • Constructor Details

    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(float[] heightArray)
      Instantiate a square shape for the specified array of heights.
      Parameters:
      heightArray - (not null, length≥4, length a perfect square, unaffected)
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(float[] heightArray, Vector3f scale)
      Instantiate a square shape for the specified height array and scale vector.
      Parameters:
      heightArray - (not null, length≥4, length a perfect square, unaffected)
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
    • HeightfieldCollisionShape

      public HeightfieldCollisionShape(int stickLength, int stickWidth, float[] heightmap, Vector3f scale, int upAxis, boolean flipQuadEdges, boolean flipTriangleWinding, boolean useDiamond, boolean useZigzag)
      Instantiate a rectangular shape for the specified parameters.
      Parameters:
      stickLength - the number of rows in the heightfield (>1)
      stickWidth - number of columns in the heightfield (>1)
      heightmap - (not null, length≥stickLength*stickWidth, unaffected)
      scale - the desired scale factor for each local axis (not null, no negative component, unaffected, default=(1,1,1))
      upAxis - the height-axis index (0→X, 1→Y, 2→Z, default=1)
      flipQuadEdges - true→reverse the direction of the first diagonal (default=true)
      flipTriangleWinding - true→left-hand winding of triangles (default=false)
      useDiamond - true→diagonals alternate on both horizontal axes (default=false)
      useZigzag - true→diagonals alternate on one horizontal axis (default=false)
  • Method Details

    • countColumns

      public int countColumns()
      Count how many columns are in the heightfield.
      Returns:
      the count (≥2)
    • countMeshVertices

      public int countMeshVertices()
      Count how many heights are in the heightfield.
      Returns:
      the count (≥4)
    • countRows

      public int countRows()
      Count how many rows are in the heightfield.
      Returns:
      the count (≥2)
    • upAxis

      public int upAxis()
      Return the index of the height axis.
      Returns:
      the axis index: 0→X, 1→Y, 2→Z
    • toSplittableShape

      public CollisionShape toSplittableShape()
      Approximate this shape with a splittable shape.
      Overrides:
      toSplittableShape in class CollisionShape
      Returns:
      a new splittable shape