Page 1 of 1

Man, I don't understand the btHeightfieldTerrainShape...

Posted: Tue Feb 23, 2016 4:33 am
by thegeneralsolution
I have been trying to understand how the btHeightfieldTerrainShape works. I think my main problem is I don't understand what coordinate space the various input and output elements are in.

I am using the following constructor:

Code: Select all

btHeightfieldTerrainShape::btHeightfieldTerrainShape	(	int 	heightStickWidth,
int 	heightStickLength,
const void * 	heightfieldData,
btScalar 	heightScale,
btScalar 	minHeight,
btScalar 	maxHeight,
int 	upAxis,
PHY_ScalarType 	heightDataType,
bool 	flipQuadEdges 
)	
I read the following note from: http://www.bulletphysics.com/Bullet/Bul ... Shape.html
NOTE: be careful with coordinates. If you have a heightfield with a local min height of -100m, and a max height of +500m, you may be tempted to place it at the origin (0,0) and expect the heights in world coordinates to be -100 to +500 meters. Actually, the heights will be -300 to +300m, because bullet will re-center the heightfield based on its AABB (which is determined by the min/max heights). So keep in mind that once you create a btHeightfieldTerrainShape object, the heights will be adjusted relative to the center of the AABB.
Really? Then how come when I pass larger or smaller values into the minHeight/maxHeight parameters of the constructor, it changes the bounding box but seems to have no effect on where the actual collision boundary is created? For example, I created a btHeightfieldTerrainShape, I used the float data type and passed in an array of floats all with value 0.7. I tried various min and max heights (-5 and 2), (0.6 and 0.8 ), even (0.4 to 0.6 which doesn't even contain 0.7) and the objects in my scene still collided at the exact same location (I had a graphical object drawn at 0.7 units above the ground to inspect).

So... what exactly is this 're-centering' doing? And for the 2d array of height values being passed in.. what space should they be in? So in the example described above (where it gets recentered from (-100,500) to (-300,300).. do I pass in height values within the (-100,500) range or within the (-300,300) range?

Any help in understanding this would be much appreciated.

Re: Man, I don't understand the btHeightfieldTerrainShape...

Posted: Fri Feb 26, 2016 9:24 pm
by thegeneralsolution
Is there any more information I could give that would allow someone to better answer my question?

Re: Man, I don't understand the btHeightfieldTerrainShape...

Posted: Sat Feb 27, 2016 12:18 pm
by Xammond
I'm not sure what you would like to do differently?

We find the min and max heights, then position the shape at the center location between the two extremes.
Just offset your heightfield data to start with (when generating or importing) if you want everything non-zero origin.