colision detection with Triangular meshes

amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

colision detection with Triangular meshes

Post by amrishkum »

hi

I am trying to detect collision between two triangular surface meshes. I could use static triangular meshes as collision shapes and then tried to detect collision between them . Is this the correct way to do ?

Is there any problem in the code below?

The code what I am using for detecting collision between triangular mesh is
//Adding triangular meshes to the collision shapes
trimeshShape = new btBvhTriangleMeshShape(m_indexVertexArrays,useQuantizedAabbCompression);

m_collisionShapes.push_back(trimeshShape);

btCollisionWorld* collisionWorld = 0;
if (m_collisionShapes.size() >1)
{
for (int index =1; index < m_collisionShapes.size(); index++)
{

m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
btVector3 worldMin(-1000,-1000,-1000);
btVector3 worldMax(1000,1000,1000);
m_broadphase = new btAxisSweep3(worldMin,worldMax);
collisionWorld = new btCollisionWorld(m_dispatcher,m_broadphase,m_collisionConfiguration);

btCollisionAlgorithm* algo = collisionWorld->getDispatcher()->findAlgorithm(&objects[0],&objects[index]);
btManifoldResult contactPointResult(&objects[0],&objects[index]);
algo->processCollision(&objects[0],&objects[index],collisionWorld->getDispatchInfo(),&contactPointResult);

btManifoldArray manifoldArray;
algo->getAllContactManifolds(manifoldArray);

int numManifolds = manifoldArray.size();
int numContacts =0;
bool bCheckCollision = false;
for (int i=0;i<numManifolds;i++)
{
btPersistentManifold* contactManifold = manifoldArray;
numContacts = contactManifold->getNumContacts();
if (numContacts >0)
{
bCheckCollision = true;
break;
}

}

if (bCheckCollision == true)
{
return 1;
}
}

}


Thanks
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: colision detection with Triangular meshes

Post by amrishkum »

Hi

I have two stationary triangular meshes and I am trying to detect collision between them. When I used above method, the method fails and it doesn't get results. I tried to even use btGImpactMeshShape and also used m_dynamicsWorld. But I am not getting correct results.

The meshes are stationary. When they meshes intersect, I need to know whether they collided or not.

I am also uploading the code file.

Please let me know if somebody has some suggestions.
You do not have the required permissions to view the files attached to this post.
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: colision detection with Triangular meshes

Post by amrishkum »

I did write a simple code to detect collision between two triangles and this doesn't work too. Does any one has suggestion what is wrong in code as two triangles two intersect.

The number of contacts is zero which should not be the case. Can someone tell what I doing wrong? Please help............
btTriangleMesh* trimesh = new btTriangleMesh(true,false);

trimesh->addTriangle(btVector3(0,0,0), btVector3(100,0,0), btVector3(0,0,100));


btCollisionShape * trimeshShape = new btBvhTriangleMeshShape(trimesh,true,true);


objects[0].setCollisionShape(trimeshShape);

btTriangleMesh *trimesh1 = new btTriangleMesh(true,false);

trimesh1->addTriangle(btVector3(0,100,0), btVector3(100,-50,50), btVector3(0,0,0));


btCollisionShape * trimeshShape1 = new btBvhTriangleMeshShape(trimesh1,true,true);

objects[1].setCollisionShape(trimeshShape1);

m_collisionConfiguration = new btDefaultCollisionConfiguration();

m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);

btVector3 worldMin(-1000,-1000,-1000);
btVector3 worldMax(1000,1000,1000);
m_broadphase = new btAxisSweep3(worldMin,worldMax);

collisionWorld = new btCollisionWorld(m_dispatcher,m_broadphase,m_collisionConfiguration);

collisionWorld->addCollisionObject(&objects[0]);
collisionWorld->addCollisionObject(&objects[1]);
collisionWorld->performDiscreteCollisionDetection();
int num_manifolds = collisionWorld->getDispatcher()->getNumManifolds();
for (int i=0;i<num_manifolds;i++)
{
btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
int numContacts = contactManifold->getNumContacts();
}
amrishkum
Posts: 17
Joined: Wed May 23, 2012 7:08 pm

Re: colision detection with Triangular meshes

Post by amrishkum »

Can anyone help me? Please help...I need it urgently. I am also attaching the image of colliding triangles..
tritricol.jpg
You do not have the required permissions to view the files attached to this post.