contactPairTest problem with object inside another object

Post Reply
Enrico Cappelletto
Posts: 2
Joined: Mon Mar 11, 2019 3:20 pm

contactPairTest problem with object inside another object

Post by Enrico Cappelletto » Tue Mar 12, 2019 3:10 pm

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;
}

User avatar
drleviathan
Posts: 550
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: contactPairTest problem with object inside another object

Post by drleviathan » Tue Mar 19, 2019 4:14 pm

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.

Enrico Cappelletto
Posts: 2
Joined: Mon Mar 11, 2019 3:20 pm

Re: contactPairTest problem with object inside another object

Post by Enrico Cappelletto » Tue Apr 09, 2019 7:15 am

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.

Enrico

Post Reply