[ODE] at least i managed to send a mail the right way... after 4 tries :/

Shaul Kedem shaul_kedem at yahoo.com
Tue Jun 17 10:47:01 2003


r0dy,
 There are couple of things you can do, one is check
out the tests, test_boxstack and test_buggy are two
good examples.

 Also, there are a couple of open source projects
which use ODE you can check.

 Check out the archives of the list, it might help
you.

 You can also check out the following simple example
of a sphere colliding with a plane:

#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);

  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();
}


Good luck,
Shaul


--- r0dy@r0dy.net wrote:
> Hello all
>  
> i'm new to physics engines, collisions and such, and
> even if ODE's doc
> is clear and complete, i'd like to see an example
> code to get started
> (just initializations and such)
> so if anyone has something to suggest, you're
> welcome
>  
> thanks
>  
> r0dy
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com