update to latest Bullet 2.x sources. prepare to make near sensors much faster
authorErwin Coumans <blender@erwincoumans.com>
Mon, 4 Dec 2006 15:48:32 +0000 (15:48 +0000)
committerErwin Coumans <blender@erwincoumans.com>
Mon, 4 Dec 2006 15:48:32 +0000 (15:48 +0000)
extern/bullet2/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btDispatcher.h
extern/bullet2/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
extern/bullet2/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
extern/bullet2/src/BulletDynamics/Dynamics/btRigidBody.h

index 3ad2467886b28f5085b9fdee23f3ce793c2f64d4..b279022c802aa4a96664d9848d7e2d5d6accd56c 100644 (file)
@@ -70,7 +70,8 @@ struct btBroadphaseProxy
                StaticFilter = 2,
                KinematicFilter = 4,
                DebrisFilter = 8,
-               AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
+                       SensorTrigger = 16,
+               AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger,
        };
 
        //Usually the client btCollisionObject or Rigidbody class
@@ -118,8 +119,7 @@ class btCollisionAlgorithm;
 
 struct btBroadphaseProxy;
 
-//Increase SIMPLE_MAX_ALGORITHMS to allow multiple btDispatchers caching their own algorithms
-#define SIMPLE_MAX_ALGORITHMS 1
+
 
 /// contains a pair of aabb-overlapping objects
 struct btBroadphasePair
@@ -127,22 +127,16 @@ struct btBroadphasePair
        btBroadphasePair ()
                :
        m_pProxy0(0),
-               m_pProxy1(0)
+               m_pProxy1(0),
+               m_algorithm(0)
        {
-               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
-               {
-                       m_algorithms[i] = 0;
-               }
        }
 
        btBroadphasePair(const btBroadphasePair& other)
                :               m_pProxy0(other.m_pProxy0),
-                               m_pProxy1(other.m_pProxy1)
+                               m_pProxy1(other.m_pProxy1),
+                               m_algorithm(other.m_algorithm)
        {
-               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
-               {
-                       m_algorithms[i] = other.m_algorithms[i];
-               }
        }
        btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
        {
@@ -159,17 +153,14 @@ struct btBroadphasePair
             m_pProxy1 = &proxy0; 
         }
 
-               for (int i=0;i<SIMPLE_MAX_ALGORITHMS;i++)
-               {
-                       m_algorithms[i] = 0;
-               }
+               m_algorithm = 0;
 
        }
        
        btBroadphaseProxy* m_pProxy0;
        btBroadphaseProxy* m_pProxy1;
        
-       mutable btCollisionAlgorithm* m_algorithms[SIMPLE_MAX_ALGORITHMS];
+       mutable btCollisionAlgorithm* m_algorithm;
 };
 
 
index 1a4713986380026ca250ce991737794f148be819..c7714f592c40ef6939f7cbc63eec4b710e273f8b 100644 (file)
@@ -22,11 +22,6 @@ class btRigidBody;
 class  btCollisionObject;
 class btOverlappingPairCache;
 
-enum btCollisionDispatcherId
-{
-       RIGIDBODY_DISPATCHER = 0,
-       USERCALLBACK_DISPATCHER
-};
 
 class btPersistentManifold;
 class btStackAlloc;
@@ -74,11 +69,6 @@ public:
 
        virtual btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold=0) = 0;
 
-       //
-       // asume dispatchers to have unique id's in the range [0..max dispacher]
-       //
-       virtual int getUniqueId() = 0;
-
        virtual btPersistentManifold*   getNewManifold(void* body0,void* body1)=0;
 
        virtual void releaseManifold(btPersistentManifold* manifold)=0;
index 8950d20f22e73cf3fd14a6f53d3abea84f658908..5e3fa63358912989411ef7b986390580c28c4b36 100644 (file)
@@ -54,14 +54,11 @@ void        btOverlappingPairCache::removeOverlappingPair(btBroadphasePair& findPair)
 
 void   btOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair)
 {
-       for (int dispatcherId=0;dispatcherId<SIMPLE_MAX_ALGORITHMS;dispatcherId++)
+       if (pair.m_algorithm)
        {
-               if (pair.m_algorithms[dispatcherId])
                {
-                       {
-                               delete pair.m_algorithms[dispatcherId];
-                               pair.m_algorithms[dispatcherId]=0;
-                       }
+                       delete pair.m_algorithm;;
+                       pair.m_algorithm=0;
                }
        }
 }
index e8865a2c45a51b4a3b7c37776d0afc3c0c232399..d4c9e1476b1e1ade44a4f22fea835a4d74bdf652 100644 (file)
@@ -45,6 +45,8 @@ m_emptyCreateFunc(0)
 {
        int i;
 
+       setNearCallback(defaultNearCallback);
+
        m_emptyCreateFunc = new btEmptyAlgorithm::CreateFunc;
        for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
        {
@@ -61,6 +63,8 @@ btCollisionDispatcher::btCollisionDispatcher ():
                m_count(0)
 {
        int i;
+
+       setNearCallback(defaultNearCallback);
        
        //default CreationFunctions, filling the m_doubleDispatch table
        m_convexConvexCreateFunc = new btConvexConvexAlgorithm::CreateFunc;
@@ -275,50 +279,20 @@ class btCollisionPairCallback : public btOverlapCallback
 {
        btDispatcherInfo& m_dispatchInfo;
        btCollisionDispatcher*  m_dispatcher;
-       int             m_dispatcherId;
+
 public:
 
-       btCollisionPairCallback(btDispatcherInfo& dispatchInfo,btCollisionDispatcher*   dispatcher,int          dispatcherId)
+       btCollisionPairCallback(btDispatcherInfo& dispatchInfo,btCollisionDispatcher*   dispatcher)
        :m_dispatchInfo(dispatchInfo),
-       m_dispatcher(dispatcher),
-       m_dispatcherId(dispatcherId)
+       m_dispatcher(dispatcher)
        {
        }
 
        virtual bool    processOverlap(btBroadphasePair& pair)
        {
-               btCollisionObject* body0 = (btCollisionObject*)pair.m_pProxy0->m_clientObject;
-               btCollisionObject* body1 = (btCollisionObject*)pair.m_pProxy1->m_clientObject;
-
-               if (!m_dispatcher->needsCollision(body0,body1))
-                       return false;
+               (*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
 
-               //dispatcher will keep algorithms persistent in the collision pair
-               if (!pair.m_algorithms[m_dispatcherId])
-               {
-                       pair.m_algorithms[m_dispatcherId] = m_dispatcher->findAlgorithm(
-                               body0,
-                               body1);
-               }
-
-               if (pair.m_algorithms[m_dispatcherId])
-               {
-                       btManifoldResult* resultOut = m_dispatcher->internalGetNewManifoldResult(body0,body1);
-                       if (m_dispatchInfo.m_dispatchFunc ==            btDispatcherInfo::DISPATCH_DISCRETE)
-                       {
-                               
-                               pair.m_algorithms[m_dispatcherId]->processCollision(body0,body1,m_dispatchInfo,resultOut);
-                       } else
-                       {
-                               float toi = pair.m_algorithms[m_dispatcherId]->calculateTimeOfImpact(body0,body1,m_dispatchInfo,resultOut);
-                               if (m_dispatchInfo.m_timeOfImpact > toi)
-                                       m_dispatchInfo.m_timeOfImpact = toi;
-
-                       }
-                       m_dispatcher->internalReleaseManifoldResult(resultOut);
-               }
                return false;
-
        }
 };
 
@@ -327,9 +301,7 @@ void        btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
 {
        //m_blockedForChanges = true;
 
-       int dispatcherId = getUniqueId();
-
-       btCollisionPairCallback collisionCallback(dispatchInfo,this,dispatcherId);
+       btCollisionPairCallback collisionCallback(dispatchInfo,this);
 
        pairCache->processAllOverlappingPairs(&collisionCallback);
 
@@ -338,3 +310,39 @@ void       btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
 }
 
 
+
+
+//by default, Bullet will use this near callback
+void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo)
+{
+               btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
+               btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
+
+               if (dispatcher.needsCollision(colObj0,colObj1))
+               {
+                       //dispatcher will keep algorithms persistent in the collision pair
+                       if (!collisionPair.m_algorithm)
+                       {
+                               collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
+                       }
+
+                       if (collisionPair.m_algorithm)
+                       {
+                               btManifoldResult contactPointResult(colObj0,colObj1);
+                               
+                               if (dispatchInfo.m_dispatchFunc ==              btDispatcherInfo::DISPATCH_DISCRETE)
+                               {
+                                       //discrete collision detection query
+                                       collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
+                               } else
+                               {
+                                       //continuous collision detection query, time of impact (toi)
+                                       float toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
+                                       if (dispatchInfo.m_timeOfImpact > toi)
+                                               dispatchInfo.m_timeOfImpact = toi;
+
+                               }
+                       }
+               }
+
+}
\ No newline at end of file
index 41bc98e1dca8cb3f81865a1f7cebace23c8c7cfc..77c09b618ec25f5fbd602daf8984d4d2fb941cb7 100644 (file)
@@ -32,6 +32,10 @@ class btOverlappingPairCache;
 
 #define USE_DISPATCH_REGISTRY_ARRAY 1
 
+class btCollisionDispatcher;
+///user can override this nearcallback for collision filtering and more finegrained control over collision detection
+typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo);
+
 
 ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
 ///Time of Impact, Closest Points and Penetration Depth.
@@ -43,6 +47,8 @@ class btCollisionDispatcher : public btDispatcher
        bool m_useIslands;
        
        btManifoldResult        m_defaultManifoldResult;
+
+       btNearCallback          m_nearCallback;
        
        btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
        
@@ -62,19 +68,7 @@ class btCollisionDispatcher : public btDispatcher
 
 public:
 
-       ///allows the user to get contact point callbacks 
-       inline btManifoldResult*        internalGetNewManifoldResult(btCollisionObject* obj0,btCollisionObject* obj1)
-       {
-               //in-place, this prevents parallel dispatching, but just adding a list would fix that.
-               btManifoldResult* manifoldResult = new (&m_defaultManifoldResult)       btManifoldResult(obj0,obj1);
-               return manifoldResult;
-       }
-               
-       ///allows the user to get contact point callbacks 
-       inline void     internalReleaseManifoldResult(btManifoldResult*)
-       {
-       }
-
+       
        ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
        void    registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
 
@@ -121,12 +115,21 @@ public:
        virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1);
        
        virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1);
-
-       virtual int getUniqueId() { return RIGIDBODY_DISPATCHER;}
        
        virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,btDispatcherInfo& dispatchInfo);
 
-       
+       void    setNearCallback(btNearCallback  nearCallback)
+       {
+               m_nearCallback = nearCallback; 
+       }
+
+       btNearCallback  getNearCallback() const
+       {
+               return m_nearCallback;
+       }
+
+       //by default, Bullet will use this near callback
+       static void  defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, btDispatcherInfo& dispatchInfo);
 
 };
 
index 49b8525149d8f4e1e5b85cbf6d6c54e1581e32d3..43869363cdf5e98f00c639b4357506ecbeb3eeda 100644 (file)
@@ -336,7 +336,12 @@ public:
        {
                return m_angularFactor;
        }
-       
+
+       //is this rigidbody added to a btCollisionWorld/btDynamicsWorld/btBroadphase?
+       bool    isInWorld() const
+       {
+               return (getBroadphaseProxy() != 0);
+       }
 
        int     m_debugBodyId;
 };