I've been scratching my head at this for a while now, and Google hasn't been my friend for this particular issue. This is my first time using ODE after somebody recommended it to me, and it seems to be a fairly nice and straightforward library to use. However, I'm having some trouble with the use of TriMeshes. Since I want to have terrain collision detection, I decided to use ODE's built-in TriMesh to represent the terrain. Of course, I start off with a simple 2-triangle square representing my "Terrain". I do that with the following code:
void PhysicsManager::createTriMeshBB(Model* model)
{
const int vCount = 4;
float vertices[vCount * 3] = {
0,0,0,
20*30,0,0,
20*30,0,20*30,
0,0,20*30
};
dTriIndex indices[6] = {
0,1,2,
0,2,3
};
dTriMeshDataID dataID;
dGeomID geomID;
dataID = dGeomTriMeshDataCreate();
dGeomTriMeshDataBuildSingle(dataID, vertices, sizeof(float)*3, vCount, indices, 6, sizeof(dTriIndex)*3);
//dGeomTriMeshDataBuildSimple(dataID, vertices, 4, tmpCreateIndices(), 6);
geomID = dCreateTriMesh(mSpace, dataID, 0, 0, 0);
dGeomSetPosition(geomID,0,0,0);
dGeomSetBody(geomID, 0);
model->setGeometryID(geomID);
}
After having done this, I specify a callback function - say "tmpCallback" as below:
void PhysicsManager::tmpCallback(void * d, dGeomID id1, dGeomID id2)
{
int i;
// Get the dynamics bodies
dBodyID b1 = dGeomGetBody(id1);
dBodyID b2 = dGeomGetBody(id2);
std::cout << "Callback" << std::endl;
// Holds the contact joints - Need to read up on this
dContact contact[32];
dContactGeom ptr;
for (i = 0; i < 32; i++)
{
contact.surface.mode = dContactBounce;
contact.surface.mu = dInfinity;
contact.surface.mu2 = 0;
contact.surface.bounce = 0.01;
contact.surface.bounce_vel = 0.5;
contact.surface.soft_cfm = 0.01;
}
int numc = dCollide(id1, id2, 1, &contact[0].geom, sizeof(dContact));
if (numc > 0)
{
for (i = 0; i < numc; i++)
{
dJointID c = dJointCreateContact(PhysicsManager::get()->getWorld(), PhysicsManager::get()->getContactGroup(), contact + i);
dJointAttach(c, b1, b2);
}
}
}
This callback function works perfectly when doing plane to sphere collision detection. When the TriMesh is involved however, the program crashes at "dCollide(id1,id2, 1, &contact[0].geom, sizeof(dContact))", throwing an unhandled Access Violation from inside the standard libraries. I'm at a loss at what's causing the problem, and I've tried everything I could think of to solve it.
If you want to slap me in the face and tell me I shouldn't be using ODE, that's fine as well - please do give your own recommendations however
Thanks in advance