# ODE collision issues

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

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

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.surface.mode = dContactBounce;
contact.surface.bounce = 0.5f;
contact.surface.mu = 50.0; // was: dInfinity

dJointID c = dJointCreateContact(g_World,g_ContactGroup,&contact);
dJointAttach(c, dGeomGetBody(contact.geom.g1), dGeomGetBody(contact.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 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 on other sites
Quote:
 Original post by cossieI 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.