Page 1 of 1

contactPairTest problem with object inside another object

Posted: Tue Mar 12, 2019 3:10 pm
by Enrico Cappelletto
Hey guys!
I am quite new to the Bullet library and I have a problem trying detect if an object in inside another one!

If two solids are partially overlapped the method finds correctly the collision, whereas if one of them is completely inside the other one the callback addSingleResult is never called.

What am I missing??
Any help would be appreciated.

Enrico

...
BulletContactResultCallback resultCallback;
m_pCollisionWorld->contactPairTest(pSolidA->m_pBulletObject, pSolidB->m_pBulletObject, resultCallback);
..
struct BulletContactResultCallback : public btCollisionWorld::ContactResultCallback
{
bool bCollisionFound;
double aBBox[6];

BulletContactResultCallback()
{
bCollisionFound = false;
aBBox[0] = aBBox[1] = aBBox[2] = DBL_MAX;
aBBox[3] = aBBox[4] = aBBox[5] = -DBL_MAX;
}

virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper * colObj1Wrap, int partId1, int index1)
{
aBBox[0] = min(cp.getPositionWorldOnA().x(), aBBox[0]);
aBBox[1] = min(cp.getPositionWorldOnA().y(), aBBox[1]);
aBBox[2] = min(cp.getPositionWorldOnA().z(), aBBox[2]);
aBBox[3] = max(cp.getPositionWorldOnA().x(), aBBox[3]);
aBBox[4] = max(cp.getPositionWorldOnA().y(), aBBox[4]);
aBBox[5] = max(cp.getPositionWorldOnA().z(), aBBox[5]);

aBBox[0] = min(cp.getPositionWorldOnB().x(), aBBox[0]);
aBBox[1] = min(cp.getPositionWorldOnB().y(), aBBox[1]);
aBBox[2] = min(cp.getPositionWorldOnB().z(), aBBox[2]);
aBBox[3] = max(cp.getPositionWorldOnB().x(), aBBox[3]);
aBBox[4] = max(cp.getPositionWorldOnB().y(), aBBox[4]);
aBBox[5] = max(cp.getPositionWorldOnB().z(), aBBox[5]);

bCollisionFound = true;
return 1;
}

Re: contactPairTest problem with object inside another object

Posted: Tue Mar 19, 2019 4:14 pm
by drleviathan
The ContactResultCallback::addSingleResult() is only called when an actual ManifoldContactPoint is added to the ContactManifold. Therefore it must be the case that no points are being added when one object is completely inside the other.

What btCollisionShape are you using for the outer btCollisionObject? If it is one of the btConcaveShapes then I wouldn't be surprised that no points are being added, however if it were a btConvexShape I would expect to get some points in the manifold.