Class HeightFieldShape

All Implemented Interfaces:
ConstJoltPhysicsObject, ConstShape, RefTarget, AutoCloseable, Comparable<JoltPhysicsObject>

public class HeightFieldShape extends Shape
A Shape to represent a surface defined by a matrix of heights.
  • Method Details

    • getBlockSize

      public int getBlockSize()
      Return the block size. The shape is unaffected.
      Returns:
      the number of height values in a block
    • getPosition

      public Vec3 getPosition(int x, int y)
      Copy the location of specified sample. The shape is unaffected.
      Parameters:
      x - the X coordinate of the sample (≥0, <sampleCount)
      y - the Y coordinate of the sample (≥0, <sampleCount)
      Returns:
      a new location vector
    • getSurfaceNormal

      public Vec3 getSurfaceNormal(int subShapeId, Vec3Arg localLocation)
      Calculate the normal to the surface at the specified surface location.
      Parameters:
      subShapeId - which sub-shape to use
      localLocation - the location relative to the shape's center of mass (not null, unaffected)
      Returns:
      a new direction vector
    • isNoCollision

      public boolean isNoCollision(int x, int y)
      Test whether the shape has a hole at the specified sample. The shape is unaffected.
      Parameters:
      x - the X coordinate of the sample (≥0, <sampleCount)
      y - the Y coordinate of the sample (≥0, <sampleCount)
      Returns:
      true if there's a hole, otherwise false
    • projectOntoSurface

      public boolean projectOntoSurface(Vec3Arg localLocation, Vec3 storeSurfaceLocation, int[] storeSubShapeId)
      Project the specified location along the Y axis to find a location on the surface.
      Parameters:
      localLocation - the location relative to the shape's center of mass (not null, unaffected)
      storeSurfaceLocation - storage for the surface location (not null, modified)
      storeSubShapeId - storage for the sub-shape ID (not null, modified)
      Returns:
      true if a valid surface location was found, otherwise false
    • setHeights

      public void setHeights(int startX, int startY, int sizeX, int sizeY, FloatBuffer heights, int stride, TempAllocator allocator)
      Alter the heights for a rectangular sub-matrix.
      Parameters:
      startX - the index of the start row (multiple of the block size, ≥0, <sampleCount)
      startY - the index of the start column (multiple of the block size, ≥0, <sampleCount)
      sizeX - the number of affected rows (multiple of the block size, ≥0, ≤sampleCount-startX)
      sizeY - the number of affected columns (multiple of the block size, ≥0, ≤sampleCount-startY)
      heights - the height values to set
      stride - stride between consecutive rows in heights (in floats)
      allocator - for temporary allocations (not null)
    • setHeights

      public void setHeights(int startX, int startY, int sizeX, int sizeY, FloatBuffer heights, int stride, TempAllocator allocator, float cosThresholdAngle)
      Alter the heights for a rectangular sub-matrix.
      Parameters:
      startX - the index of the start row (multiple of the block size, ≥0, <sampleCount)
      startY - the index of the start column (multiple of the block size, ≥0, <sampleCount)
      sizeX - the number of affected rows (multiple of the block size, ≥0, ≤sampleCount-startX)
      sizeY - the number of affected columns (multiple of the block size, ≥0, ≤sampleCount-startY)
      heights - the height values to set
      stride - stride between consecutive rows in heights (in floats)
      allocator - for temporary allocations (not null)
      cosThresholdAngle - cosine of the threshold angle (default=0.996195)