[ODE] Quake level collision

bob.efrei bob.efrei at ifrance.com
Mon Dec 29 22:49:24 MST 2003


I'm writing a little 3D demo, who will look like a quake level where player can visit.

I represent the player by a sphere and try to prevent him to go throught floor and walls (trimesh). I use the following code, which work but have little bugs because it seems that ODE never returns exactly the same depth:

int i,n;

  const int N = 10;
  dContact contact[N];
  n = dCollide(o1, player->geom,N,&contact[0].geom,sizeof(dContact));

	Vector pos(dBodyGetPosition(player->body));

	for (i=0; i<n; i++) 
		{
		Vector normal = contact[i].geom.normal;

		//La normale pointe vers l'objet contact[i].g1,
		//il faut donc l'inverser si le joueur est en g2.
		if( contact[i].geom.g2 == player->geom )
			normal = -normal;

		pos += -normal * contact[i].geom.depth;

		dBodySetPosition(player->body, pos.x, pos.y, pos.z);
    }


I also tryied to use contacts, but I've the same bugs on the floor and on the wall, it makes my sphere rolling:

		contact[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactApprox1;
      contact[i].surface.mu = dInfinity;
      contact[i].surface.slip1 = 0.1f;
      contact[i].surface.slip2 = 0.1f;
      contact[i].surface.soft_erp = 0.5f;
      contact[i].surface.soft_cfm = 0.3f;

      dJointID c = dJointCreateContact (world,contactgroup,&contact[i]);

      dJointAttach (c, player->body, 0);


So which is the best method and how to correct this imprecision?


_____________________________________________________________________
Envie de discuter en "live" avec vos amis ? Télécharger MSN Messenger
http://www.ifrance.com/_reloc/m la 1ère messagerie instantanée de France



More information about the ODE mailing list