[ODE] Just need a piece of code

Shaul Kedem shaul_kedem at yahoo.com
Sun Jun 1 11:06:02 2003


Ok...
 Here is a *very* basic code which use ODE and the
colission code without any graphics.

#include "ode/ode.h"

dWorldID	aWorld ;
dBodyID		aBody;
dSpaceID	aSpace;
dGeomID		aSphere;
dGeomID		aGround;
dJointGroupID grpContacts;

static void nearCallback (void *data, dGeomID o1,
dGeomID o2)
{
  int i;

  dBodyID b1 = dGeomGetBody(o1);
  dBodyID b2 = dGeomGetBody(o2);
  if (b1 && b2 && dAreConnectedExcluding
(b1,b2,dJointTypeContact)) 
  {
	  return;
  }

  dContact contact[4];			// up to 4 contacts per
box-box
  for (i=0; i<4; i++) {
    contact[i].surface.mode = dContactBounce |
dContactSoftCFM |dContactSoftERP;
    contact[i].surface.mu = dInfinity;
    contact[i].surface.mu2 = 0;
    contact[i].surface.bounce = 0.1;
    contact[i].surface.bounce_vel = 0.1;
    contact[i].surface.soft_cfm = 0.001;
	contact[i].surface.soft_erp = 1.0;
  }
  int numc = dCollide
(o1,o2,4,&contact[0].geom,sizeof(dContact));
  if (numc) {

	dMatrix3 RI;
    dRSetIdentity (RI);
    const dReal ss[3] = {1.0,1.0,1.0};
    for (i=0; i<numc; i++) {
		dJointID c = dJointCreateContact
(aWorld,grpContacts,&contact[i]);
      dJointAttach (c,b1,b2);

    }
  }
}


void main ( void )
{
	int count = 0;

	aWorld = dWorldCreate();

	dWorldSetGravity (aWorld,0,0,-0.5);

    dWorldSetCFM (aWorld,1e-5);

	aSpace = dHashSpaceCreate (0);

	dMass m;

	aBody = dBodyCreate (aWorld);

	dBodySetPosition ( aBody,0,0,10 );

	dMassSetSphere  (&m,0.2,1.0f );

	aSphere = dCreateSphere ( aSpace, 1.0f );

	dBodySetMass ( aBody,&m );

	dGeomSetBody ( aSphere,aBody );

	aGround = dCreatePlane ( aSpace,0,0,1,0 );

	grpContacts = dJointGroupCreate (0);

	dReal *pos;

	do
	{
		dJointGroupEmpty (grpContacts);

		dSpaceCollide (aSpace,0,&nearCallback);
	
		dWorldStep (aWorld, 0.1);

		pos = (dReal *)dGeomGetPosition(aSphere);

		printf ( "%f,%f,%f\n",pos[0],pos[1],pos[2] );

		// use this sleep to see what happens, you can
safely remove it
		_sleep(10);

		if ( pos[2] < 1.0 )
			count ++;
			
			// to get the rotation use
dGeomGetRotation(aSphere);
	} while ( count < 20 ) ;

	dJointGroupDestroy (grpContacts);

	dSpaceDestroy(aSpace);

	dWorldDestroy (aWorld);

	dCloseODE();
}

The printout is X,Y,Z.

hope this helps.

Best,
Shaul Kedem.

--- Emeric Rollo <erollo@wanadoo.fr> wrote:
> 
> 
> Shaul a écrit:
> 
> >Emeric,
> > Do you need something which is pure ODE, or squeak
> >oriented? 
> >
> Actually I would like to have pure ODE written in
> C... but I don't 
> understand well what you mean by squeak oriented.
> How can you get 
> something which is squeak oriented with ODE ?
> 
> >Do you simulate (call worldstep) on your own
> >or need an example including the simulation and
> >colission steps ?
> >  
> >
> I'd prefer an example including simulation and
> collision steps even if 
> it's not necessary. (I don't have yet understood how
> the "nearCallback " 
> function exactly works)
> 
> Thanks Shaul!
> Emeric
> 
> 
> _______________________________________________
> ODE mailing list
> ODE@q12.org
> http://q12.org/mailman/listinfo/ode


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com