[ODE] Looking for some collision advice

Hill Thompson hillthompson at hotmail.com
Mon Sep 29 16:58:17 MST 2003


Could someone please help me figure out what I'm missing.  I've gone back 
and forth through this but I can't seem to make these two boxes interact 
with each other.  I know that they are colliding, but they don't respond.  
Mostly, I'm having a hard time understanding ODE handles these collision 
events and generates interactions.  Here's my code:

#include<ode/ode.h>
#include<drawstuff/drawstuff.h>

static dWorldID world1;
static dBodyID body[2];
static dSpaceID space1;
static dGeomID gbody[2];
static dJointGroupID contactgroup;

static void start(){
                static float xyz[3] = {0,3.0f,3.0f};
	static float hpr[3] = {-90.0f,-30.0f,0.0000f};
	dsSetViewpoint (xyz,hpr);
}

static void nearCallback (void *data, dGeomID o1, dGeomID o2){
	dBodyID b1 = dGeomGetBody(o1);
	dBodyID b2 = dGeomGetBody(o2);
	const int N = 10;
	dContact contact[N];
	for (int i=0; i<N; i++) {
		contact[i].surface.mode = dContactBounce ;
		contact[i].surface.bounce = 1;
		contact[i].surface.bounce_vel = 0.1;
	}
	if (int numc = dCollide (o1,o2,0,&contact[0].geom,sizeof(dContact))) {
	 	for (int i=0; i<numc; i++) {
	    	dJointID c = dJointCreateContact (world1,contactgroup,&contact[i]);
	    	dJointAttach (c,b1,b2);
	  	}
	}
}

static void simLoop(int pauseS){
	dSpaceCollide (space1,0,&nearCallback);
	dReal sides1[3] = {1,1,1};
	dsSetTexture (DS_WOOD);
	dsSetColor (1,1,0);
    dsDrawBoxD (dBodyGetPosition(body[0]),dBodyGetRotation(body[0]),sides1);
    dBodyAddForce(body[0], 0.1,0,0);
    dsDrawBoxD (dBodyGetPosition(body[1]),dBodyGetRotation(body[1]),sides1);
    dWorldStep (world1,0.05);
    dJointGroupEmpty (contactgroup);
}

int main(void){
	dsFunctions fn;
	fn.version = DS_VERSION;
	fn.start = &start;
	fn.step = &simLoop;
  	fn.stop = 0;
  	fn.path_to_textures = "../../drawstuff/textures";

	world1 = dWorldCreate();
	space1 = dHashSpaceCreate(0);
	contactgroup = dJointGroupCreate (0);

	dMass m;
	dMassAdjust (&m,1);

	body[0] = dBodyCreate(world1);
	dBodySetMass (body[0],&m);
	dBodySetPosition (body[0],-1,-0.5,1);
	gbody[0] = dCreateBox (space1,1,1,1);
	dGeomSetBody (gbody[0],body[0]);

	body[1] = dBodyCreate(world1);
	dBodySetMass (body[1],&m);
	dBodySetPosition (body[1],1,-0.5,1);
	gbody[1] = dCreateBox (space1,1,1,1);
	dGeomSetBody (gbody[1],body[1]);

	dsSimulationLoop (0,0,352,288,&fn);
	dSpaceDestroy (space1);
	dJointGroupDestroy (contactgroup);
	dWorldDestroy(world1);
	return 0;
}

_________________________________________________________________
Frustrated with dial-up? Get high-speed for as low as $29.95/month 
(depending on the local service providers in your area).  
https://broadband.msn.com



More information about the ODE mailing list