Jump to content
  • Advertisement
Sign in to follow this  
deavik

ODE dSpaceCollide vs dCollide for 2 geom scene

This topic is 3496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there! I've spent the past few days messing around with ODE, getting a heightfield / capsule collision detection working. I have a simple scenario with just 2 geoms, the capsule and the heightfield. For some reason, if I call dCollide with the 2 geoms every physics step, I get a more or less stable simulation. However, if I use dSpaceCollide, leaving everything else the EXACT same, I get my character wildly bouncing around. I am using a fixed time step (atleast, I'm doing this:)
accumulatedTime += dt; // add the time the current frame took (t-t0)

	// do as many steps as required (maybe even 0)
	while (accumulatedTime > stepSize) {
		
		dSpaceCollide(space, NULL, &nearCallback);
		dWorldQuickStep(world, stepSize);
		dJointGroupEmpty(contactGroup);

		accumulatedTime -= stepSize;
	}

Does anyone know how to tackle such a problem? I'm thinking that dSpaceCollide is not calling dCollide on my object aptly enough, resulting in large penetration depths and equally large rebound forces. - How do you bound these rebound forces? - or ideally make it "move" the capsule to handle collisions, instead of using dynamics and forces. Here's my nearCallback (almost identical to the ODE manual):
void nearCallback(void* data, dGeomID o1, dGeomID o2) {
	if (dGeomIsSpace(o1) || dGeomIsSpace(o2)) { 

		// colliding a space with something :
		dSpaceCollide2(o1, o2, data, &nearCallback); 

		// collide all geoms internal to the space(s)
		if (dGeomIsSpace(o1))
				dSpaceCollide((dSpaceID) o1, data, &nearCallback);
		if (dGeomIsSpace(o2))
				dSpaceCollide((dSpaceID) o2, data, &nearCallback);
	} else {
		if (o1 == o2) return;

		dContact contacts[Physics::MAX_CONTACTS];

		for (int i=0; i<Physics::MAX_CONTACTS; ++i) {
			contacts.surface.mode = dContactBounce;
			contacts.surface.mu = 0;
			contacts.surface.bounce = 0;
		}

		int numContacts = dCollide(o1, o2, Physics::MAX_CONTACTS, &contacts[0].geom, sizeof(dContact));

		for (int i=0; i < numContacts; ++i) {
			dJointID c = dJointCreateContact(Physics::world, Physics::contactGroup, &contacts);
			dJointAttach(c, dGeomGetBody(o1), dGeomGetBody(o2));
		}
	}
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!