With discrete collision detection, it was found that a btCompoundShape was determining that it was in collision with an object at a larger threshold than an individual primitive btCollisionShape like a capsule. The capsule was able to get much closer to the target object.
From some digging around the code, I found that the btPersistentManifold defaults to using a relative threshold. This threshold appears to be relative to the size of the bounding sphere of an entire shape (or compound) - the larger it is, the larger the threshold. That is why the compound shape has a larger threshold than the individual shape.
Code: Select all
btPersistenManifold* btCollisionDispatcher::getNewManifold(...)
{
(...)
//optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ?
btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold)) :
gContactBreakingThreshold ;
(...)
Code: Select all
void btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const
{
btTransform tr;
tr.setIdentity();
btVector3 aabbMin,aabbMax;
getAabb(tr,aabbMin,aabbMax);
radius = (aabbMax-aabbMin).length()*btScalar(0.5);
center = (aabbMin+aabbMax)*btScalar(0.5);
}
btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
{
return getAngularMotionDisc() * defaultContactThreshold;
}
btScalar btCollisionShape::getAngularMotionDisc() constbtScalar btCollisionShape::getAngularMotionDisc() const
{
///@todo cache this value, to improve performance
btVector3 center;
btScalar disc;
getBoundingSphere(center,disc);
disc += (center).length();
return disc;
}
My questions are:
- Does anyone know if this is change would affect something else that I am not aware of?
- Are there other solutions to this relative contact threshold?