### contactPairTest problem with object inside another object

Posted:

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

}

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;

}