make relative contact breaking threshold optional (use dispatcher->setDispatcherFlags(0) to turn off feature)

This commit is contained in:
erwin.coumans
2009-12-13 20:22:21 +00:00
parent 8444d0e5c4
commit 0a6f7b271d
4 changed files with 29 additions and 20 deletions

View File

@@ -34,9 +34,7 @@ int gNumManifold = 0;
btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration):
m_count(0), m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD),
m_useIslands(true),
m_staticWarningReported(false),
m_collisionConfiguration(collisionConfiguration) m_collisionConfiguration(collisionConfiguration)
{ {
int i; int i;
@@ -79,9 +77,11 @@ btPersistentManifold* btCollisionDispatcher::getNewManifold(void* b0,void* b1)
btCollisionObject* body0 = (btCollisionObject*)b0; btCollisionObject* body0 = (btCollisionObject*)b0;
btCollisionObject* body1 = (btCollisionObject*)b1; btCollisionObject* body1 = (btCollisionObject*)b1;
//test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold' //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
//btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()));
btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()); btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ?
btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold))
: gContactBreakingThreshold ;
btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold()); btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
@@ -169,13 +169,13 @@ bool btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO
bool needsCollision = true; bool needsCollision = true;
#ifdef BT_DEBUG #ifdef BT_DEBUG
if (!m_staticWarningReported) if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED))
{ {
//broadphase filtering already deals with this //broadphase filtering already deals with this
if ((body0->isStaticObject() || body0->isKinematicObject()) && if ((body0->isStaticObject() || body0->isKinematicObject()) &&
(body1->isStaticObject() || body1->isKinematicObject())) (body1->isStaticObject() || body1->isKinematicObject()))
{ {
m_staticWarningReported = true; m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED;
printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
} }
} }

View File

@@ -42,14 +42,10 @@ typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispa
///Time of Impact, Closest Points and Penetration Depth. ///Time of Impact, Closest Points and Penetration Depth.
class btCollisionDispatcher : public btDispatcher class btCollisionDispatcher : public btDispatcher
{ {
int m_count; int m_dispatcherFlags;
btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr; btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;
bool m_useIslands;
bool m_staticWarningReported;
btManifoldResult m_defaultManifoldResult; btManifoldResult m_defaultManifoldResult;
btNearCallback m_nearCallback; btNearCallback m_nearCallback;
@@ -59,13 +55,28 @@ class btCollisionDispatcher : public btDispatcher
btPoolAllocator* m_persistentManifoldPoolAllocator; btPoolAllocator* m_persistentManifoldPoolAllocator;
btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]; btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
btCollisionConfiguration* m_collisionConfiguration; btCollisionConfiguration* m_collisionConfiguration;
public: public:
enum DispatcherFlags
{
CD_STATIC_STATIC_REPORTED = 1,
CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2
};
int getDispatherFlags() const
{
return m_dispatcherFlags;
}
void setDispatcherFlags(int flags)
{
m_dispatcherFlags = 0;
}
///registerCollisionCreateFunc allows registration of custom/alternative collision create functions ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
void registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc); void registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);

View File

@@ -15,9 +15,6 @@ subject to the following restrictions:
#include "BulletCollision/CollisionShapes/btCollisionShape.h" #include "BulletCollision/CollisionShapes/btCollisionShape.h"
btScalar gContactThresholdFactor=btScalar(0.02);
/* /*
Make sure this dummy function never changes so that it Make sure this dummy function never changes so that it
can be used by probes that are checking whether the can be used by probes that are checking whether the
@@ -45,10 +42,11 @@ void btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) con
} }
btScalar btCollisionShape::getContactBreakingThreshold() const btScalar btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
{ {
return getAngularMotionDisc() * gContactThresholdFactor; return getAngularMotionDisc() * defaultContactThreshold;
} }
btScalar btCollisionShape::getAngularMotionDisc() const btScalar btCollisionShape::getAngularMotionDisc() const
{ {
///@todo cache this value, to improve performance ///@todo cache this value, to improve performance

View File

@@ -48,7 +48,7 @@ public:
///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations. ///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
virtual btScalar getAngularMotionDisc() const; virtual btScalar getAngularMotionDisc() const;
virtual btScalar getContactBreakingThreshold() const; virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep) ///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)