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.


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

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.

Re: contactPairTest problem with object inside another object

Posted: Tue Apr 09, 2019 7:15 am
by Enrico Cappelletto
Thank you for you answer and for the explanation.

We are using a collection of btGImpactMeshShape that store concave triangle mesh, therefore, as you said I can't find any points when one object is completely inside another.

We are used to loading the triangle meshes from files so the entry point in the Bullet library are exactly btTriangleMesh for each shape. So how could I workaround the problem?? Is there a function similar as contactPairTest that check also "an object is completely inside another" even for concave shapes?? Or you would suggest me to looking for a way to convert the btTriangleMesh in a convenient and fast for collision check ConvexShape?

Thank you in advance.