[ODE] Terrain + ODE ... again

Paul Cheyrou-Lagreze p.cheyroulagreze at free.fr
Tue May 11 14:58:08 MST 2004


> So, can someone who already have made it to explain a good way to have  
> terrain collision?

Because there is many ways to handle this, Benoit CHAPEROT implementation,  
transform terrain into a trimesh, Create a new Ode object as in slickworm  
http://slickworm.sourceforge.net/, etc.

> Heh... ODE is i nice stuff.. i don't understand why nobody write  
> something strong for this,... a

So here's another one, surely the easiest to test... (don't know if it's  
the best one...)

I use "Sliding Planes", that is ode plane appears under entities according  
to terrain normals at the entity position.

Here's one (in C++),
that just need a GetHeightAt function in you terrain algos :

/////code
const dReal *pos_bod = dBodyGetPosition (entity->getBody ());

float objheight = (float) pos_bod[1]; // pos_bod[1] is  entity y pos

Vector3 pos = Vector3 ((Real) pos_bod[0],
                        (Real) pos_bod[1],
                        (Real) pos_bod[2]);

getHeightAt (pos); // does modify pos.y according to terrain height at  
this position

// if test is true, then there is some collision
// therefore, we create a "sliding plane"
if  (pos.y > objheight)
{
   Vector3 vecz = pos;
   Vector3 vecx = pos;


  vecx.x = vecx.x + SHIFT_POS;
  activetempentity->getHeightAt (vecx);

  vecz.z = vecz.z + SHIFT_POS;
  activetempentity->getHeightAt (vecz);

  Vector3 kEdge1 = pos - vecx;
  Vector3 kEdge2 = vecz - vecx;
  Vector3 normal = kEdge1.crossProduct (kEdge2);

  normal.normalise();
  Real distance = normal.dotProduct (pos);

  dPlane temp  (space,
		   (dReal) normal.x, (dReal) normal.y, (dReal) normal.z,
		   (dReal) distance);

  dContact contact[NUM_CONTACTS];
  if (int numc = dCollide (entity->getGeom (),  temp.id (), NUM_CONTACTS,  
&contact[0].geom, sizeof(dContact)))
   {
      for (int i=0; i < numc; i++)
      {		
  	[...]// usual Ode contact stuff
      }	
   }
}
/////end of code

- SHIFT_POS must be equal to object width or height...
- Vector3, Vector3::normalise and Vector3::dotProduct comes from OGRE  
engine. but surely you have same objects or functions somewhere in your  
code. (perhaps there is some in Ode's?)

...


More information about the ODE mailing list