3

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?

theCNG27
  • 405
  • 8
  • 27

1 Answers1

3

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.

Edward Aung
  • 3,014
  • 1
  • 12
  • 15
  • 1
    Okay, so what you mean is that "heightStickWidth" and "heightStickLength" is supposed to be the size of the atomic rectangles in x and z axis (asuming y is up). Correct? And what data format is heightfieldData supposed to be? I tried different ways to store the values in a byte buffer but none seemed to work. (Nothing caused other rigid bodies to collide with the shape whatsoever) – theCNG27 May 24 '19 at 22:05
  • Yes, that is my theory (which I formed from reading code and documents). – Edward Aung May 25 '19 at 05:48
  • 1
    Sorry, but that cannot be true. Inside the HeightfieldTerrainShape implementation there is an assert statement: assert heightStickWidth > 1 : "bad width";. Also a variable m_width is initialized by (heightStickWidth - 1). So it cannot be the size of a single quad of the terrain. Any other thoughts? – theCNG27 May 28 '19 at 22:16
  • Just a wild guess, but perhaps "stick" in this case means "post" - like fenceposts in a fence, the number of posts is equal to the length + 1? – Talin Apr 20 '21 at 03:16