mirat
Posts: 16 Joined: Thu May 29, 2008 10:47 am
Post
by mirat » Wed Dec 17, 2008 6:08 am
I want only to know if two btCollisionObjects are in collision, no information about contact points is needed. I check if broadphase pair exists for given objects, and then get number of manifolds. Does existing of one or more manifolds means colliding of two objects? Can manifold exist when it doesn't contain any contact points (I mean if checking of manifolds count is not enought)?
Code: Select all
bool check_collision (const btCollisionObject * body0, const btCollisionObject * body1) const
{
btCollisionWorld * world = get_bt_world(); // my function returning active btCollisionWorld
const btBroadphaseProxy * prox0 = body0->getBroadphaseHandle();
const btBroadphaseProxy * prox1 = body1->getBroadphaseHandle();
btBroadphasePair * pair = world->getBroadphase()->getOverlappingPairCache()->findPair(prox0, prox1);
if (pair)
{
btManifoldArray manifoldArray;
if (pair->m_algorithm) pair->m_algorithm->getAllContactManifolds(manifoldArray);
if (manifoldArray.size() > 0)
{
return true;
}
}
return false;
}
mirat
Posts: 16 Joined: Thu May 29, 2008 10:47 am
Post
by mirat » Mon Dec 22, 2008 1:13 pm
Answering myself: no, not enough. Final code below, I hope it will be useful to somebody
Code: Select all
bool check_collision (const btCollisionObject * body0, const btCollisionObject * body1) const
{
btCollisionWorld * world = get_bt_world(); // my function returning active btCollisionWorld
const btBroadphaseProxy * prox0 = body0->getBroadphaseHandle();
const btBroadphaseProxy * prox1 = body1->getBroadphaseHandle();
btBroadphasePair * pair = world->getBroadphase()->getOverlappingPairCache()->findPair(prox0, prox1);
if (pair)
{
btManifoldArray manifoldArray;
if (pair->m_algorithm) pair->m_algorithm->getAllContactManifolds(manifoldArray);
for (unsigned int i = 0, s = manifoldArray.size(); i < s; ++i )
{
if ( manifoldArray[i]->getNumContacts() > 0 ) return true;
}
}
return false;
}