Sign in to follow this  
chillypacman

Bounces up forever

Recommended Posts

chillypacman    100
After a geom bounces off a static surface in ode it keeps going up and up none-stop despite there still being gravity. Heres the call back (if it will help):
void hit(void *data, dGeomID o1, dGeomID o2)
{
	dBodyID body1 = dGeomGetBody(o1);
	dBodyID body2 = dGeomGetBody(o2);
	body2 = 0;

	dJointGroupID contactGroup;
	dJointCreateBall(world, contactGroup);

	dContact contact[50];

	dJointGroupCreate(0);

	for (int i = 0; i < 50; i++) {
		contact[i].surface.mode = dContactBounce; // Bouncy surface
		contact[i].surface.bounce = 0.5;
		contact[i].surface.mu = 100.0; // Friction
	}

	int collisions = dCollide(o1, o2, 50, &contact[0].geom, sizeof(dContact));

	if (collisions)
	{
		for (int i = 0; i < collisions; ++i)
		{
			dJointID c = dJointCreateContact(world, contactGroup, &contact[i]);
			dJointAttach(c, body1, body2);
		}
	}
}



It bounces back up irrespective of whether or not I have contact[i].surface.mode = dContactBounce Edit: The collision is between two spheres, one right on top of the other. I moved the falling object a few notches to the side so it would bounce off at an angle so it would bounce off at an angle, it did and started falling into the abyss. I moved it forward very slightly so it would bounce at an angle off of the static sphere and bounce again and I got the following error: "Unhandled exception at 0x10058ac7 (ode.dll) in shapes2.exe: 0xC0000005: Access violation reading location 0x840f0004." Pointing to this line: if ((last->used + num_bytes) > dOBSTACK_ARENA_SIZE) { in odestack.cpp. Also when it is bouncing up and up if I move it a few notches forward via the following line of code:
if( ::GetAsyncKeyState('L') & 0x8000f )
		{
			xa = *(dBodyGetPosition(object1->bodyID));
			ya = (*(dBodyGetPosition (object1->bodyID) + 1));
			za = *(dBodyGetPosition (object1->bodyID) + 2) + 0.001;
			dGeomSetPosition (geomID1, xa, ya, za);
		}
it starts falling properly, again if it only moves forward a small bit so it can bounce on the same static sphere again I get that error above. [Edited by - chillypacman on May 5, 2007 7:52:49 AM]

Share this post


Link to post
Share on other sites
chillypacman    100
remove what now?

how do I remove the contact joints?

I did try adding this: dJointGroupEmpty(contactGroup); to the callback function but it started giving me bad arguments error in ode.cpp when it cllided..

[Edited by - chillypacman on May 5, 2007 8:42:36 PM]

Share this post


Link to post
Share on other sites
BradDaBug    913
Old contact joints (which should only have a lifespan of 1 step) are never being removed, so ODE is trying to resolve old collisions. The easiest way to remove old contact joints is to keep all contact joints in a single joint group, and then clear the joint group after each physics step. So first you need a contact group that you'll put all contact joints into. Once you've got that, just keep doing this:
  1. Do collision detection stuff, adding each contact joint to the joint group
  2. Take a step
  3. Clear the joint group
  4. Go to #1


In other words, don't create and clear the joint group in the callback. Do it higher up. Something like this:
// make sure that myJointGroup was created with dJointGroupCreate()
// before calling this
void DoPhysics()
{
// test for collisions
dSpaceCollide(...);

// now the bodies should have all the contact joints setup
// so take a step
dWorldStep();

// clear the old contact joints
dJointGroupEmpty(myJointGroup);
}
Hope that helps.

Share this post


Link to post
Share on other sites
chillypacman    100
Yup, works great, thanks.

Except one thing,

for (int i = 0; i < 50; i++) {
contact[i].surface.mode = dContactBounce; // Bouncy surface
contact[i].surface.bounce = 1.0;
contact[i].surface.mu = 300.0; // Friction
}






Is not actually having an effect, they are colliding but there is no bouncing.

edit: ok, so changing the dContactID contact[50] to dContactID contact[30] and it worked a bit better, the smaller the dContactID array is the more bounces I'm getting.

So yeah, I think I fixed it then.

Thanks for the help, much appreciated :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this