Bullet Collision Detection & Physics Library: btCollisionDispatcher.h Source File

Bullet Collision Detection & Physics Library

btCollisionDispatcher.h
Go to the documentation of this file.
1 /*
2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 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.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14 */
15
16 #ifndef BT_COLLISION__DISPATCHER_H
17 #define BT_COLLISION__DISPATCHER_H
18
19 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
20 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
21
22 #include "BulletCollision/CollisionDispatch/btManifoldResult.h"
23
24 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
25 #include "LinearMath/btAlignedObjectArray.h"
26
27 class btIDebugDraw;
28 class btOverlappingPairCache;
29 class btPoolAllocator;
30 class btCollisionConfiguration;
31
32 #include "btCollisionCreateFunc.h"
33
34 #define USE_DISPATCH_REGISTRY_ARRAY 1
35
36 class btCollisionDispatcher;
38 typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
39
42 class btCollisionDispatcher : public btDispatcher
43 {
44 protected:
45 int m_dispatcherFlags;
46
47 btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;
48
49 btManifoldResult m_defaultManifoldResult;
50
51 btNearCallback m_nearCallback;
52
53 btPoolAllocator* m_collisionAlgorithmPoolAllocator;
54
55 btPoolAllocator* m_persistentManifoldPoolAllocator;
56
57 btCollisionAlgorithmCreateFunc* m_doubleDispatchContactPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
58
59 btCollisionAlgorithmCreateFunc* m_doubleDispatchClosestPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
60
61 btCollisionConfiguration* m_collisionConfiguration;
62
63 public:
64 enum DispatcherFlags
65 {
66 CD_STATIC_STATIC_REPORTED = 1,
67 CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2,
68 CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
69 };
70
71 int getDispatcherFlags() const
72 {
73 return m_dispatcherFlags;
74 }
75
76 void setDispatcherFlags(int flags)
77 {
78 m_dispatcherFlags = flags;
79 }
80
82 void registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
83
84 void registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
85
86 int getNumManifolds() const
87 {
88 return int(m_manifoldsPtr.size());
89 }
90
91 btPersistentManifold** getInternalManifoldPointer()
92 {
93 return m_manifoldsPtr.size() ? &m_manifoldsPtr[0] : 0;
94 }
95
96 btPersistentManifold* getManifoldByIndexInternal(int index)
97 {
98 return m_manifoldsPtr[index];
99 }
100
101 const btPersistentManifold* getManifoldByIndexInternal(int index) const
102 {
103 return m_manifoldsPtr[index];
104 }
105
106 btCollisionDispatcher(btCollisionConfiguration* collisionConfiguration);
107
108 virtual ~btCollisionDispatcher();
109
110 virtual btPersistentManifold* getNewManifold(const btCollisionObject* b0, const btCollisionObject* b1);
111
112 virtual void releaseManifold(btPersistentManifold* manifold);
113
114 virtual void clearManifold(btPersistentManifold* manifold);
115
116 btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType);
117
118 virtual bool needsCollision(const btCollisionObject* body0, const btCollisionObject* body1);
119
120 virtual bool needsResponse(const btCollisionObject* body0, const btCollisionObject* body1);
121
122 virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& dispatchInfo, btDispatcher* dispatcher);
123
124 void setNearCallback(btNearCallback nearCallback)
125 {
126 m_nearCallback = nearCallback;
127 }
128
129 btNearCallback getNearCallback() const
130 {
131 return m_nearCallback;
132 }
133
134 //by default, Bullet will use this near callback
135 static void defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
136
137 virtual void* allocateCollisionAlgorithm(int size);
138
139 virtual void freeCollisionAlgorithm(void* ptr);
140
141 btCollisionConfiguration* getCollisionConfiguration()
142 {
143 return m_collisionConfiguration;
144 }
145
146 const btCollisionConfiguration* getCollisionConfiguration() const
147 {
148 return m_collisionConfiguration;
149 }
150
151 void setCollisionConfiguration(btCollisionConfiguration* config)
152 {
153 m_collisionConfiguration = config;
154 }
155
156 virtual btPoolAllocator* getInternalManifoldPool()
157 {
158 return m_persistentManifoldPoolAllocator;
159 }
160
161 virtual const btPoolAllocator* getInternalManifoldPool() const
162 {
163 return m_persistentManifoldPoolAllocator;
164 }
165 };
166
167 #endif //BT_COLLISION__DISPATCHER_H
btCollisionDispatcher::m_persistentManifoldPoolAllocator
btPoolAllocator * m_persistentManifoldPoolAllocator
Definition: btCollisionDispatcher.h:55
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:50
btNearCallback
void(* btNearCallback)(btBroadphasePair &collisionPair, btCollisionDispatcher &dispatcher, const btDispatcherInfo &dispatchInfo)
user can override this nearcallback for collision filtering and more finegrained control over collisi...
Definition: btCollisionDispatcher.h:38
btCollisionDispatcher::getNearCallback
btNearCallback getNearCallback() const
Definition: btCollisionDispatcher.h:129
btCollisionDispatcher::getManifoldByIndexInternal
btPersistentManifold * getManifoldByIndexInternal(int index)
Definition: btCollisionDispatcher.h:96
btCollisionDispatcher::m_manifoldsPtr
btAlignedObjectArray< btPersistentManifold * > m_manifoldsPtr
Definition: btCollisionDispatcher.h:47
btCollisionDispatcher::getNumManifolds
int getNumManifolds() const
Definition: btCollisionDispatcher.h:86
btCollisionDispatcher::m_doubleDispatchClosestPoints
btCollisionAlgorithmCreateFunc * m_doubleDispatchClosestPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]
Definition: btCollisionDispatcher.h:59
btCollisionDispatcher::m_collisionConfiguration
btCollisionConfiguration * m_collisionConfiguration
Definition: btCollisionDispatcher.h:61
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:18
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:77
btCollisionDispatcher::clearManifold
virtual void clearManifold(btPersistentManifold *manifold)
Definition: btCollisionDispatcher.cpp:101
btCollisionDispatcher::m_collisionAlgorithmPoolAllocator
btPoolAllocator * m_collisionAlgorithmPoolAllocator
Definition: btCollisionDispatcher.h:53
btCollisionDispatcher::m_defaultManifoldResult
btManifoldResult m_defaultManifoldResult
Definition: btCollisionDispatcher.h:49
ebtDispatcherQueryType
ebtDispatcherQueryType
Definition: btDispatcher.h:69
btCollisionDispatcher
btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
Definition: btCollisionDispatcher.h:43
btCollisionDispatcher::getCollisionConfiguration
const btCollisionConfiguration * getCollisionConfiguration() const
Definition: btCollisionDispatcher.h:146
btCollisionDispatcher::CD_STATIC_STATIC_REPORTED
@ CD_STATIC_STATIC_REPORTED
Definition: btCollisionDispatcher.h:66
btCollisionAlgorithm
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
Definition: btCollisionAlgorithm.h:54
btCollisionAlgorithmCreateFunc
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.
Definition: btCollisionCreateFunc.h:27
btCollisionDispatcher::freeCollisionAlgorithm
virtual void freeCollisionAlgorithm(void *ptr)
Definition: btCollisionDispatcher.cpp:279
btIDebugDraw
The btIDebugDraw interface class allows hooking up a debug renderer to visually debug simulations.
Definition: btIDebugDraw.h:27
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:48
btCollisionDispatcher::m_doubleDispatchContactPoints
btCollisionAlgorithmCreateFunc * m_doubleDispatchContactPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]
Definition: btCollisionDispatcher.h:57
btCollisionDispatcher::DispatcherFlags
DispatcherFlags
Definition: btCollisionDispatcher.h:65
btCollisionDispatcher::findAlgorithm
btCollisionAlgorithm * findAlgorithm(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, btPersistentManifold *sharedManifold, ebtDispatcherQueryType queryType)
Definition: btCollisionDispatcher.cpp:128
btOverlappingPairCache
The btOverlappingPairCache provides an interface for overlapping pair management (add,...
Definition: btOverlappingPairCache.h:51
btCollisionDispatcher::getNewManifold
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)
Definition: btCollisionDispatcher.cpp:68
btCollisionDispatcher::getCollisionConfiguration
btCollisionConfiguration * getCollisionConfiguration()
Definition: btCollisionDispatcher.h:141
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:65
btManifoldResult.h
btCollisionDispatcher::getInternalManifoldPointer
btPersistentManifold ** getInternalManifoldPointer()
Definition: btCollisionDispatcher.h:91
btCollisionDispatcher::setNearCallback
void setNearCallback(btNearCallback nearCallback)
Definition: btCollisionDispatcher.h:124
MAX_BROADPHASE_COLLISION_TYPES
@ MAX_BROADPHASE_COLLISION_TYPES
Definition: btBroadphaseProxy.h:78
btCollisionDispatcher::registerCollisionCreateFunc
void registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
registerCollisionCreateFunc allows registration of custom/alternative collision create functions
Definition: btCollisionDispatcher.cpp:54
btDispatcherInfo
Definition: btDispatcher.h:31
btAlignedObjectArray< btPersistentManifold * >
btCollisionDispatcher::btCollisionDispatcher
btCollisionDispatcher(btCollisionConfiguration *collisionConfiguration)
Definition: btCollisionDispatcher.cpp:32
btCollisionDispatcher::releaseManifold
virtual void releaseManifold(btPersistentManifold *manifold)
Definition: btCollisionDispatcher.cpp:106
btDispatcher.h
btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD
@ CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD
Definition: btCollisionDispatcher.h:67
btCollisionCreateFunc.h
btCollisionDispatcher::allocateCollisionAlgorithm
virtual void * allocateCollisionAlgorithm(int size)
Definition: btCollisionDispatcher.cpp:268
btPersistentManifold.h
btBroadphaseProxy.h
btCollisionDispatcher::getInternalManifoldPool
virtual const btPoolAllocator * getInternalManifoldPool() const
Definition: btCollisionDispatcher.h:161
btCollisionDispatcher::~btCollisionDispatcher
virtual ~btCollisionDispatcher()
Definition: btCollisionDispatcher.cpp:64
btCollisionDispatcher::m_dispatcherFlags
int m_dispatcherFlags
Definition: btCollisionDispatcher.h:45
btCollisionDispatcher::setDispatcherFlags
void setDispatcherFlags(int flags)
Definition: btCollisionDispatcher.h:76
btCollisionDispatcher::dispatchAllCollisionPairs
virtual void dispatchAllCollisionPairs(btOverlappingPairCache *pairCache, const btDispatcherInfo &dispatchInfo, btDispatcher *dispatcher)
Definition: btCollisionDispatcher.cpp:216
btCollisionDispatcher::registerClosestPointsCreateFunc
void registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
Definition: btCollisionDispatcher.cpp:59
btPoolAllocator
The btPoolAllocator class allows to efficiently allocate a large pool of objects, instead of dynamica...
Definition: btPoolAllocator.h:24
btCollisionDispatcher::needsResponse
virtual bool needsResponse(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btCollisionDispatcher.cpp:147
btAlignedObjectArray.h
btCollisionDispatcher::defaultNearCallback
static void defaultNearCallback(btBroadphasePair &collisionPair, btCollisionDispatcher &dispatcher, const btDispatcherInfo &dispatchInfo)
Definition: btCollisionDispatcher.cpp:231
btCollisionDispatcher::getDispatcherFlags
int getDispatcherFlags() const
Definition: btCollisionDispatcher.h:71
btCollisionDispatcher::getInternalManifoldPool
virtual btPoolAllocator * getInternalManifoldPool()
Definition: btCollisionDispatcher.h:156
btCollisionDispatcher::CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION
@ CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION
Definition: btCollisionDispatcher.h:68
btCollisionConfiguration
btCollisionConfiguration allows to configure Bullet collision detection stack allocator size,...
Definition: btCollisionConfiguration.h:27
btCollisionDispatcher::setCollisionConfiguration
void setCollisionConfiguration(btCollisionConfiguration *config)
Definition: btCollisionDispatcher.h:151
size
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
btBroadphasePair
The btBroadphasePair class contains a pair of aabb-overlapping objects.
Definition: btBroadphaseProxy.h:179
btCollisionDispatcher::getManifoldByIndexInternal
const btPersistentManifold * getManifoldByIndexInternal(int index) const
Definition: btCollisionDispatcher.h:101
btCollisionDispatcher::m_nearCallback
btNearCallback m_nearCallback
Definition: btCollisionDispatcher.h:51
btAlignedObjectArray::size
int size() const
return the number of elements in the array
Definition: btAlignedObjectArray.h:142
btCollisionDispatcher::needsCollision
virtual bool needsCollision(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btCollisionDispatcher.cpp:158