How to use bullets HeightfieldTerrainShape

222 views Asked by At

I'm struggling to find out how to use HeightfieldTerrainShape from JBullet physics library. As I can see, there are 2 constructors available:

public HeightfieldTerrainShape(int heightStickWidth, int heightStickLength, byte[] heightfieldData,
            float heightScale, float minHeight, float maxHeight, int upAxis, PHY_ScalarType heightDataType,
            boolean flipQuadEdges)

and

public HeightfieldTerrainShape(int heightStickWidth, int heightStickLength, byte[] heightfieldData,
        float maxHeight, int upAxis, boolean useFloatData, boolean flipQuadEdges)

heightScale, minHeight, maxHeight and upAxis are self explainatory. But what exactly is a "heightStick" ? And how do I determine it's width and length? What format is expected for heightfieldData? Im asuming this is just a byte buffer of floats?

1

There are 1 answers

4
Edward Aung On

The first function

public HeightfieldTerrainShape(int heightStickWidth, int heightStickLength, byte[] heightfieldData, float heightScale, float minHeight, float maxHeight, int upAxis, PHY_ScalarType heightDataType, boolean flipQuadEdges)

is the preferred on according to documentation https://pybullet.org/Bullet/BulletFull/classbtHeightfieldTerrainShape.html#a90d823ba5f44871a0bcfce0174177223.

Going through the documentation (and the cpp code), it seems like the rectangular size for atomic rectangular surfaces which represent the surface (terrain) you are defining.

For example, if your width and height are 1 and your terrain is 10 x 10 (x and y), there will be 10 x 10 = 100 such rectangles that is representing your terrain.