[ODE] Box falling through plane and dropping for ever

Metrix metrixsoftware at hotmail.com
Mon Jan 3 01:47:18 MST 2005


Hi All

I am new to ODE so be gentle ;)

The problem I am having is that the box I created is falling through the 
plane I created. I have a break point on the collide code and know I am 
getting the collision correctly. I cut and pasted most of the code (read as 
all ;) ) from the box stack demo so I have no idea whats wrong.

Any help would be appreciated, here are the details:

The world is created like so:

{
    // create world
    world = dWorldCreate();
    space = dHashSpaceCreate (0);
    contactgroup = dJointGroupCreate (0);

    dWorldSetGravity (world, 0, 0, -0.5);
    dWorldSetCFM (world, 1e-5);
    dWorldSetAutoDisableFlag (world, 1);
    dWorldSetContactMaxCorrectingVel (world, 0.1);
    dWorldSetContactSurfaceLayer (world, 0.001);

    //create some spaces for boxes and stuff
    bodies = new dBodyID[10];
    boxes = new dGeomID[10];

    dCreatePlane(space,0,0,1,0);

    fRenderBoxCount = -1;
}


A body at position (0,0,100) with a width, height ,depth of (50, 10, 50) is 
attached to a box Geom like so:

int TPhysics::AddBox(const float TopLeftFront[3], const float 
BottomRightBack[3], bool isDynamic)
{
    fRenderBoxCount++;

    double mid[3];
    mid[0] = TopLeftFront[0] + (BottomRightBack[0] - TopLeftFront[0]) / 2;
    mid[1] = TopLeftFront[1] + (BottomRightBack[1] - TopLeftFront[1]) / 2;
    mid[2] = TopLeftFront[2] + (BottomRightBack[2] - TopLeftFront[2]) / 2;

    double width = (BottomRightBack[0] - TopLeftFront[0]);
    double height = (BottomRightBack[1] - TopLeftFront[1]);
    double depth = (BottomRightBack[2] - TopLeftFront[2]);

    //Step 1
    //create physics object
    bodies[fRenderBoxCount] = dBodyCreate (world);

    //Step 2
    dBodySetPosition (bodies[fRenderBoxCount], mid[0], mid[1], mid[2]);

    //Step 3 Skip

    //Step 4
    dBodySetData (bodies[fRenderBoxCount], (void*) fRenderBoxCount);

    //Step 5
    //Set mass
    dMass m;
    dMassSetBox ( &m,
            DENSITY,
            width,
            height,
            depth
            );

    //Step 6
    //Create geom box
    boxes[fRenderBoxCount] = dCreateBox ( space,
            width,
            height,
            depth
            );

    //Step 7
    dGeomSetBody (boxes[fRenderBoxCount], bodies[fRenderBoxCount]);

    //Step 8
    //dMassAdjust (&m,1);
    dBodySetMass (bodies[fRenderBoxCount],&m);
}

Then the call back function looks like this

static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
    int i;

    dBodyID b1 = dGeomGetBody(o1);
    dBodyID b2 = dGeomGetBody(o2);
    if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact))
        return;

    dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per 
box-box
    if (int numc = dCollide (o1, o2, MAX_CONTACTS, &contact[0].geom, 
sizeof(dContact)))
    {
        for (i = 0; i < numc; i++)
        {
            contact[i].surface.mode = dContactBounce | dContactSoftCFM;
            contact[i].surface.mu = dInfinity;
            contact[i].surface.mu2 = 0;
            contact[i].surface.bounce = 0.1;
            contact[i].surface.bounce_vel = 0.1;
            contact[i].surface.soft_cfm = 0.01;
            dJointID j = dJointCreateContact (world, contactgroup, 
&contact[i]);
            dJointAttach (j, b1, b2);
        }
    }
} 


More information about the ODE mailing list