[ODE] slipping

Shamyl Zakariya shamyl at zakariya.net
Tue Mar 1 08:08:36 MST 2005


I calculate slippage to kick up dust clouds when my vehicle slides 
across terrain. It looks pretty nice, albeit not as nice as on the 
relatively new ATV racing game for PS2 :P

What I do is this: in my nearcallback, I detect if in the collision 
between geoms one is the "ground". If it is, have a callback on the 
stage to kick up dust if the relative speed of the contact point of the 
offending object passes a threshold. Note that "Collidable" is a base 
class for everything in my game which has a geom and (maybe) a body. 
Their bodies and geoms have their void * data set to point to their 
Collidable instance.


Here's a snippet from the near callback:

	if (int numc = dCollide( g1, g2, maxContacts, &contact[0].geom, 
sizeof(dContact)))
	{
		for (int i = 0; i < numc; i++)
		{
			dJointID c = dJointCreateContact( game->_world, game->_contactGroup, 
contact +i);
			dJointAttach( c, b1, b2 );
			
			dGeomID cg1 = contact[i].geom.g1;
			dGeomID cg2 = contact[i].geom.g2;
			
			//terrain can have more than one trimesh geom
			if ( terrain->isTerrainGeom(cg1) )
			{
				game->_stage->collision(
					Collidable::collidableForGeom( cg2 ),
					contact[i].geom.depth,
					contact[i].geom.pos,
					contact[i].geom.normal );
			}
			else if ( terrain->isTerrainGeom(cg2) )
			{
				game->_stage->collision(
					Collidable::collidableForGeom( cg1 ),
					contact[i].geom.depth,
					contact[i].geom.pos,
					contact[i].geom.normal );
			}			
		}
	}



And here's the callback on the "stage" object:

void Stage::collision( Collidable *c, float penetration, vec3 contact, 
vec3 normal )
{
	/*
		One over the minimum speed threshold, or 1/30 = 0.033f
		Remember that fp division is slow on PPC.
	*/
	float iMinSpeedThreshold = 0.033f;

	if ( c )
	{
		dBodyID body = c->body();
		if ( body )
		{
			vec3 lVel;
			dBodyGetPointVel( body, contact.x, contact.y, contact.z, lVel.v );		

			/*
				Now, we're emitting more dust based on how fast the relative
				velocity is. E.g, the faster the more dust. We'll do this by
				emitting a number of particles relative to the speed.		
			*/

			float relSpeed = __fres( __frsqrtes( lVel.length2() ) );
			float numParticles = __fres( __frsqrtes( relSpeed * 
iMinSpeedThreshold ));
			
			if ( numParticles > 10 ) numParticles = 10;
			
			if ( numParticles >= 1.0f )
			{
				_dust->emitSpherical( contact, (int)numParticles );
			}
		}
	}
}

Hope this helps.


Shamyl Zakariya
   "this is, after all, one of those movies where people spend a great
   deal of time looking at things and pointing."
	From a review of _Fantastic Voyage_

On Feb 28, 2005, at 4:52 PM, Marek Lapko wrote:

> i wonder how can i find out whether the body is slipping on surface
>
> thanks
> marek
>
>
>
> ____________________________________
> EPI.sk Zbierka zakonov a uplne znenia online.
> Zakony, vyhlasky, nariadenia, denna aktualizacia.
> Najdete na stranke http://www.epi.sk/zbierka.htm
>
>
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
>



More information about the ODE mailing list