[ODE] Trimesh Collision Problems

Alexandre Ribeiro de Sá alex_r at vortexentertainment.com
Wed Jan 19 15:25:32 MST 2005


AHOY!

I have some problem with trimesh collision, I made a function to create 
trimesh collision for world and object, here is the code:

    float mass = 1.0f, density = 1.0f, lx = 0.5f, ly = 0.5f, lz = 0.5f;

    bool usePhysic = true;
    m_usePhysic = usePhysic;

    // 50.0f  -  World Size
    // 0.5f  -  Body Size
    Size[0] = 0.5f;
    Size[1] = 0.5f;
    Size[2] = 0.5f;
 
    Vertices[0][0] = -Size[0];
    Vertices[0][1] = -Size[1];
    Vertices[0][2] = Size[2];
 
    Vertices[1][0] = Size[0];
    Vertices[1][1] = -Size[1];
    Vertices[1][2] = Size[2];
 
    Vertices[2][0] = Size[0];
    Vertices[2][1] = Size[1];
    Vertices[2][2] = Size[2];
 
    Vertices[3][0] = -Size[0];
    Vertices[3][1] = Size[1];
    Vertices[3][2] = Size[2];
 
    Vertices[4][0] = 0;
    Vertices[4][1] = 0;
    Vertices[4][2] = 0;
 
    Indices[0] = 0;
    Indices[1] = 1;
    Indices[2] = 4;
 
    Indices[3] = 1;
    Indices[4] = 2;
    Indices[5] = 4;
 
    Indices[6] = 2;
    Indices[7] = 3;
    Indices[8] = 4;
 
    Indices[9] = 3;
    Indices[10] = 0;
    Indices[11] = 4;

    dTriMeshDataID Data = dGeomTriMeshDataCreate();
    dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, 
Indices, IndexCount);

    if( usePhysic == true )        // Body
    {
        prt_ODE_Body = dBodyCreate(w);
        prt_ODE_BodyGeom = dCreateTriMesh(s, Data, 0, 0, 0);
        dGeomSetBody(prt_ODE_BodyGeom, prt_ODE_Body);
    }
    else                        // World
    {
        prt_ODE_BodyGeom = dCreateTriMesh(s, Data, 0, 0, 0);
    }

Now the problem is, when I create the world the collision works, but 
very slow and break, when I create a bode the collision don't work and 
break...

This is my nearCollisionCallback function:

    dContact contacts[10];

    dBodyID b1 = dGeomGetBody(o1);
    dBodyID b2 = dGeomGetBody(o2);

    if( ( b1 != 0 ) && ( b2 != 0 ) && dAreConnectedExcluding( b1, b2, 
dJointTypeContact ) )
    {
        return;
    }

    int i = 0;

    for( i=0; i < 10; i++ )
    {
        contacts[i].surface.mode = dContactBounce | dContactSoftCFM;
        contacts[i].surface.mu = dInfinity;
        contacts[i].surface.mu2 = 0;
        contacts[i].surface.bounce = 0.1;
        contacts[i].surface.bounce_vel = 0.1;
        contacts[i].surface.soft_cfm = 0.01;
    }

    int numc = dCollide( o1, o2, 10, &contacts[0].geom, sizeof( dContact 
) );

    if(numc > 0 )
    {
        VPhysicBody *body1 = ( VPhysicBody * ) dGeomGetData( o1 );
        assert( body1 );
        VPhysicBody *body2 = ( VPhysicBody * ) dGeomGetData( o2 );
        assert( body2 );

        for( i = 0; i < numc; ++i )
        {              
            dJointID c = dJointCreateContact( objWorld->vWorld, 
objWorld->vContactGroup, &contacts[i] );
            dJointAttach( c, b1, b2 );
        }
    }


Thanks
Alexandre Ribeiro de Sá
alex_r at vortexentertainment.com
http://www.vortexentertainment.com


More information about the ODE mailing list