game-physicsphysics-enginebulletphysics

Bullet Physics - Two Question about btHeightfieldTerrainShape


first, I've searched about btHeightfieldTerrainShape, and then i realized that constructor doesn't need any normal data. is it compute normal itself by terrain height - index data?

second, is there any kind of form about parameter void* heightfieldData? I know that must be heightDataType - array, but there must be x - z coordinates or something, but only it gets are just array. is there any formula for this?


Solution

  • Array format depends on the PHY_ScalarType parameter, and it will be intepreted as such.

    It can be

    Array is a simple "2d image" where each value represents the elevation of that point, some form of virtual grid/2d map.

    The resolution is set with

    int heightStickWidth, 
    int heightStickLength,
    

    in the constructor.

    So your array must be of the size heightStickWidth*heightStickLength elements

    In case of a 4x4 grid this would visually look like:

    [0.0,-1.0,2.0,3.0,
     0.0,2.0,-1.0,-2.0
     5.0,10.0,-10.0,-2.0
    5.0,10.0,-10.0,-2.0]
    

    The axis of elevation depends on the upAxis parameter in the constructor (0=X, 1=Y,2=Z iirc)

    Also don't forget that bullet for that type of shape, does not make a copy of your array, so you need to make sure not to delete it while your shape is still active.