Shark_Bladder
Shark_Bladder

Reputation: 67

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?

Upvotes: 2

Views: 495

Answers (1)

mrvux
mrvux

Reputation: 8953

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

It can be

  • unsigned char (value * heightScale)
  • short (value * heightScale)
  • float (heightScale is ignored)

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.

Upvotes: 1

Related Questions