Sign in to follow this  
a quack

ODE collision issues

Recommended Posts

I am having some big problems using ODE. I have a very simple test case set up, here are the ODE relevant portions. First I initialize ODE like so:
const float WORLD_SIZE = 5.0;

dInitODE();
g_World = dWorldCreate();
g_Space = dHashSpaceCreate(0);
g_ContactGroup = dJointGroupCreate(0);
dWorldSetGravity (g_World, 0, -9.8, 0);
	
g_Boundary[0] = dCreatePlane(g_Space, -1.0,  0.0,  0.0, -WORLD_SIZE / 2.0);
g_Boundary[1] = dCreatePlane(g_Space,  1.0,  0.0,  0.0, -WORLD_SIZE / 2.0);
g_Boundary[2] = dCreatePlane(g_Space,  0.0, -1.0,  0.0, -WORLD_SIZE / 2.0);
g_Boundary[3] = dCreatePlane(g_Space,  0.0,  1.0,  0.0, -WORLD_SIZE / 2.0);
g_Boundary[4] = dCreatePlane(g_Space,  0.0,  0.0, -1.0, -WORLD_SIZE / 2.0);
g_Boundary[5] = dCreatePlane(g_Space,  0.0,  0.0,  1.0, -WORLD_SIZE / 2.0);
Then, I create 3 bodies, and 3 geoms, each one like this:
Body = dBodyCreate(g_World);

dMassSetSphereTotal(&Mass, 1.0, 1.0);
dBodySetMass(Body, &Mass);

Geom = dCreateBox(g_Space, CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
// --OR--
Geom = dCreateSphere(g_Space, SPHERE_RADIUS);

dGeomSetBody(Geom, Body);
They are initialized to be not colliding inside the box. My NearCallback:
void NearCallback(void *data, dGeomID g1, dGeomID g2)
{
	MyObject * o1 = (MyObject *)dGeomGetData(g1);
	MyObject * o2 = (MyObject *)dGeomGetData(g2);
	if (dGeomIsSpace(g1) || dGeomIsSpace(g2))
	{
		dSpaceCollide2(g1,g2,data,&NearCallback);
		return;
	}
	const int N = 32;
	dContact contact[N];
	int n = dCollide (g1,g2,N,&(contact[0].geom),sizeof(dContact));
	for (int i=0; i<n; i++) 
	{
		contact[i].surface.mode = dContactBounce;
		contact[i].surface.bounce = 0.5f;
		contact[i].surface.mu = 50.0; // was: dInfinity

		dJointID c = dJointCreateContact(g_World,g_ContactGroup,&contact[i]);
		dJointAttach(c, dGeomGetBody(contact[i].geom.g1), dGeomGetBody(contact[i].geom.g2));
	}

}
}
And my world timestep code:
const float TIMESTEP = 0.01;

dSpaceCollide(g_Space, NULL, NearCallback);
dWorldQuickStep(g_World, TIMESTEP);
dJointGroupEmpty(g_ContactGroup);
This seems to me to be a very, very simple test case yet the objects penetrate each other very easily, and often come to rest penetrating. The world is 5x5x5, the bodies are 2 units per edge/diameter. I'm not talking about small penetrations either, the corners of the cubes often will come to rest nearly half way through the spheres. I've tried many different settings for ERP, CFM, etc. and tried a few different contact surface modes, including 0. This is ODE 0.8. What am I doing wrong?

Share this post


Link to post
Share on other sites
Hi a quack,

I was having a similar problem this morning, a sphere was "disappearing" into a cylinder and only causing a collision about half way inside the cylinder not on the outside.

I changed the radius of the sphere to 1.0 (from 0.2) and that fixed things. I see though that your radius is 1.0 (in your dMassSetSphereTotal() ) but it might be worth trying different sizes.

And I see you are using QuickStep, have you tried just using WorldStep? It might be slower but it may be more accurate and if your cube and sphere are so small the level of inaccuracy may be magnified with QuickStep.

Sorry if this is all old news to you!

Share this post


Link to post
Share on other sites
Quote:
Original post by cossie
I changed the radius of the sphere to 1.0 (from 0.2) and that fixed things. I see though that your radius is 1.0 (in your dMassSetSphereTotal() ) but it might be worth trying different sizes.
I've tried many, many different shapes and sizes over the past few days, all of them have issues like this.
Quote:
And I see you are using QuickStep, have you tried just using WorldStep? It might be slower but it may be more accurate and if your cube and sphere are so small the level of inaccuracy may be magnified with QuickStep.
I've tried all the world steppers available, and many different parameters for the number of iterations on QuickStep.

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