[ODE] Bounce and trimesh
Tim Rightnour
root at garbled.net
Sun Dec 5 08:58:29 MST 2004
On 05-Dec-2004 Eike Decker wrote:
> * Use dTerrain objects instead of trimeshs (wish I knew how to use them)
It's not as hard as it seems..
This is basically how I load my map:
maph->mapspace = dHashSpaceCreate(maph->mapg->space);
map->terrh = safer_malloc(sizeof(dReal) * square(maph->width));
for (i=0, k=0; i<maph->width; i++) {
for (j=0; j<maph->width; j++) {
map->terrh[k] =
groundheight_at_xz(map->elevation,
(float)j*SCALE_XZ, (float)i*SCALE_XZ,
maph->width, maph->width);
k++;
}
}
map->terrgeom = dCreateTerrainY(maph->mapspace, map->terrh,
maph->width*SCALE_XZ, maph->width,
1, 1);
dGeomSetPosition(map->terrgeom, maph->x, maph->y, maph->z);
My map is stored internally as an (int8_t **) for historical purposes. The
groundheight_at_xz just gives the height value at a specific x,z coordinate.
That is stored in a big array of dReals (map->terrh) and passed as an argument
to dCreateTerrainY(). The maph->width*SCALE_XZ argument sets the size of my map
to 2560.0 x 2560.0. Then I use dGeomSetPosition() to move it to the
appropriate spot.
Some hints when using dTerrain:
1) Don't attach the terrain to a body, lots of annoying things happen, like
your terrain being affected by gravity.
2) You will probably have to do a few checks in your collide callback for the
ground, to react differently to it. In my case, I'm using multiple terrain
geoms to make a full world. So I make the collision callback ignore
terrain/terrain hits.
---
Tim Rightnour <root at garbled.net>
NetBSD: Free multi-architecture OS http://www.netbsd.org/
Genecys: Open Source 3D MMORPG: http://www.genecys.org/
More information about the ODE
mailing list