DHeightfield
From ODE Wiki
dHeightfield is a regular grid heightfield collider. It can be used for heightmap terrains, but also for deformable animated water surfaces.
Contents |
Heightfield Data
The dHeightfieldData is a storage class, similar to the dTrimeshData class, that holds all geom properties and optionally height sample data.
dHeightfieldDataID dGeomHeightfieldDataCreate (); void dGeomHeightfieldDataDestroy (dHeightfieldDataID d)
Allocate and destroy dHeightfieldDataID objects. You must call dGeomHeightfieldDataDestroy to destroy it after the geom has been removed. The dHeightfieldDataID value is used when specifying a data format type.
Building from existing data
There are four functions to easily build a heightfield from an array of height values of different data types. They all have the same parameters, except the data type of the pHeightData pointer is different:
void dGeomHeightfieldDataBuildByte (dHeightfieldDataID d, const unsigned char *pHeightData, int bCopyHeightData, dReal width, dReal depth, int widthSamples, int depthSamples, dReal scale, dReal offset, dReal thickness, int bWrap); void dGeomHeightfieldDataBuildShort (dHeightfieldDataID d, const short *pHeightData, int bCopyHeightData, dReal width, dReal depth, int widthSamples, int depthSamples, dReal scale, dReal offset, dReal thickness, int bWrap); void dGeomHeightfieldDataBuildSingle (dHeightfieldDataID d, const float *pHeightData, int bCopyHeightData, dReal width, dReal depth, int widthSamples, int depthSamples, dReal scale, dReal offset, dReal thickness, int bWrap); void dGeomHeightfieldDataBuildDouble (dHeightfieldDataID d, const double *pHeightData, int bCopyHeightData, dReal width, dReal depth, int widthSamples, int depthSamples, dReal scale, dReal offset, dReal thickness, int bWrap);
Loads heightfield sample data into the HeightfieldData structure. Before a dHeightfieldDataID can be used by a geom it must be configured to specify the format of the height data. These calls all take the same parameters as listed below; the only difference is the data type pointed to by pHeightData.
-
pHeightDatais a pointer to the height data; -
bCopyHeightDataspecifies whether the height data should be copied to a local store. If zero, the data is accessed by reference and so must persist throughout the lifetime of the heightfield; -
width,heightare the world space heightfield dimensions on the geom's local X and Z axes; -
widthSamples,depthSamplesspecifies the number of vertices to sample along the width and depth of the heightfield. Naturally this value must be at least two or more; -
scaleis the vertical sample height multiplier, a uniform scale applied to all raw height data; -
offsetis the vertical sample offset, added to the scaled height data; -
thicknessis the thickness of AABB which is added below the lowest point, to prevent objects from falling through very thin heightfields; -
bWrapis 0 if the heightfield should be finite, 1 if should tile infinitely.
Retrieving data from a callback
typedef dReal (*dHeightfieldGetHeight) (void *userdata, int x, int z); void dGeomHeightfieldDataBuildCallback (dHeightfieldDataID d, void *pUserData, dHeightfieldGetHeight *pCallback, dReal width, dReal depth, int widthSamples, int depthSamples, dReal scale, dReal offset, dReal thickness, int bWrap);
This call specifies that the heightfield data is computed by the user and it should use the given callback when determining the height of a given element of its shape. The callback function is called while the simulation runs, and returns the value of the heightmap ("y" value) at a given (x,z) position.
-
pUserDatais a pointer for arbitrary user-defined data to pass to the callback -
pCallbackis a pointer to the callback function - The other arguments are the same as the other dGeomHeightfieldDataBuild* functions.
Setting terrain bounds
void dGeomHeightfieldDataSetBounds (dHeightfieldDataID d, dReal min_height, dReal max_height)
Sets the minimum and maximum height sample bounds in sample space. ODE does not automatically detect the sample data minimum and maximum height bounds, this must be done manually (for added flexibility and allows the user to control the process).
The default vertical sample bounds are infinite, so when the sample bounds are known, call this function for improved performance. Also, if the geom (built from this data) is rotated, its AABB will end up with NaNs, and break the collision detection; so always set the heightfield data's bounds to finite values if you are going to rotate the geom.
Heightfield Geom
dGeomID dCreateHeightfield(dSpaceID space, dHeightfieldDataID data, int bPlaceable);
Uses the information in the given dHeightfieldDataID to construct a geom representing a heightfield in a collision space.
-
dHeightfieldDataIDis the heightfield data object -
bPlaceabledefines whether this geom can be transformed in the world using the usual functions such as dGeomSetPosition and dGeomSetRotation. If the geom is not set as placeable, then it uses a fixed orientation where the global Y axis represents the 'height' of the heightfield.
void dGeomHeightfieldSetHeightfieldData(dGeomID g, dHeightfieldDataID Data); dHeightfieldDataID dGeomHeightfieldGetHeightfieldData(dGeomID g);
Set and retrieve the heightfield data object of this geom.

