Blender  V2.59
btCollisionDispatcher.h
Go to the documentation of this file.
00001 /*
00002 Bullet Continuous Collision Detection and Physics Library
00003 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 */
00015 
00016 #ifndef COLLISION__DISPATCHER_H
00017 #define COLLISION__DISPATCHER_H
00018 
00019 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
00020 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
00021 
00022 #include "BulletCollision/CollisionDispatch/btManifoldResult.h"
00023 
00024 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
00025 #include "LinearMath/btAlignedObjectArray.h"
00026 
00027 class btIDebugDraw;
00028 class btOverlappingPairCache;
00029 class btPoolAllocator;
00030 class btCollisionConfiguration;
00031 
00032 #include "btCollisionCreateFunc.h"
00033 
00034 #define USE_DISPATCH_REGISTRY_ARRAY 1
00035 
00036 class btCollisionDispatcher;
00038 typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
00039 
00040 
00043 class btCollisionDispatcher : public btDispatcher
00044 {
00045 
00046 protected:
00047 
00048         int             m_dispatcherFlags;
00049 
00050         btAlignedObjectArray<btPersistentManifold*>     m_manifoldsPtr;
00051 
00052         btManifoldResult        m_defaultManifoldResult;
00053 
00054         btNearCallback          m_nearCallback;
00055         
00056         btPoolAllocator*        m_collisionAlgorithmPoolAllocator;
00057 
00058         btPoolAllocator*        m_persistentManifoldPoolAllocator;
00059 
00060         btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
00061 
00062         btCollisionConfiguration*       m_collisionConfiguration;
00063 
00064 
00065 public:
00066 
00067         enum DispatcherFlags
00068         {
00069                 CD_STATIC_STATIC_REPORTED = 1,
00070                 CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2
00071         };
00072 
00073         int     getDispatcherFlags() const
00074         {
00075                 return m_dispatcherFlags;
00076         }
00077 
00078         void    setDispatcherFlags(int flags)
00079         {
00080                 m_dispatcherFlags = flags;
00081         }
00082 
00084         void    registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
00085 
00086         int     getNumManifolds() const
00087         { 
00088                 return int( m_manifoldsPtr.size());
00089         }
00090 
00091         btPersistentManifold**  getInternalManifoldPointer()
00092         {
00093                 return &m_manifoldsPtr[0];
00094         }
00095 
00096          btPersistentManifold* getManifoldByIndexInternal(int index)
00097         {
00098                 return m_manifoldsPtr[index];
00099         }
00100 
00101          const btPersistentManifold* getManifoldByIndexInternal(int index) const
00102         {
00103                 return m_manifoldsPtr[index];
00104         }
00105 
00106         btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration);
00107 
00108         virtual ~btCollisionDispatcher();
00109 
00110         virtual btPersistentManifold*   getNewManifold(void* b0,void* b1);
00111         
00112         virtual void releaseManifold(btPersistentManifold* manifold);
00113 
00114 
00115         virtual void clearManifold(btPersistentManifold* manifold);
00116 
00117                         
00118         btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
00119                 
00120         virtual bool    needsCollision(btCollisionObject* body0,btCollisionObject* body1);
00121         
00122         virtual bool    needsResponse(btCollisionObject* body0,btCollisionObject* body1);
00123         
00124         virtual void    dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
00125 
00126         void    setNearCallback(btNearCallback  nearCallback)
00127         {
00128                 m_nearCallback = nearCallback; 
00129         }
00130 
00131         btNearCallback  getNearCallback() const
00132         {
00133                 return m_nearCallback;
00134         }
00135 
00136         //by default, Bullet will use this near callback
00137         static void  defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
00138 
00139         virtual void* allocateCollisionAlgorithm(int size);
00140 
00141         virtual void freeCollisionAlgorithm(void* ptr);
00142 
00143         btCollisionConfiguration*       getCollisionConfiguration()
00144         {
00145                 return m_collisionConfiguration;
00146         }
00147 
00148         const btCollisionConfiguration* getCollisionConfiguration() const
00149         {
00150                 return m_collisionConfiguration;
00151         }
00152 
00153         void    setCollisionConfiguration(btCollisionConfiguration* config)
00154         {
00155                 m_collisionConfiguration = config;
00156         }
00157 
00158 };
00159 
00160 #endif //COLLISION__DISPATCHER_H
00161