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 COLLISION__DISPATCHER_H |
---|
17 | #define 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; |
---|
37 | ///user can override this nearcallback for collision filtering and more finegrained control over collision detection |
---|
38 | typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo); |
---|
39 | |
---|
40 | |
---|
41 | ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs. |
---|
42 | ///Time of Impact, Closest Points and Penetration Depth. |
---|
43 | class btCollisionDispatcher : public btDispatcher |
---|
44 | { |
---|
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_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]; |
---|
58 | |
---|
59 | btCollisionConfiguration* m_collisionConfiguration; |
---|
60 | |
---|
61 | |
---|
62 | public: |
---|
63 | |
---|
64 | enum DispatcherFlags |
---|
65 | { |
---|
66 | CD_STATIC_STATIC_REPORTED = 1, |
---|
67 | CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2 |
---|
68 | }; |
---|
69 | |
---|
70 | int getDispatcherFlags() const |
---|
71 | { |
---|
72 | return m_dispatcherFlags; |
---|
73 | } |
---|
74 | |
---|
75 | void setDispatcherFlags(int flags) |
---|
76 | { |
---|
77 | (void) flags; |
---|
78 | m_dispatcherFlags = 0; |
---|
79 | } |
---|
80 | |
---|
81 | ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions |
---|
82 | void registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc); |
---|
83 | |
---|
84 | int getNumManifolds() const |
---|
85 | { |
---|
86 | return int( m_manifoldsPtr.size()); |
---|
87 | } |
---|
88 | |
---|
89 | btPersistentManifold** getInternalManifoldPointer() |
---|
90 | { |
---|
91 | return &m_manifoldsPtr[0]; |
---|
92 | } |
---|
93 | |
---|
94 | btPersistentManifold* getManifoldByIndexInternal(int index) |
---|
95 | { |
---|
96 | return m_manifoldsPtr[index]; |
---|
97 | } |
---|
98 | |
---|
99 | const btPersistentManifold* getManifoldByIndexInternal(int index) const |
---|
100 | { |
---|
101 | return m_manifoldsPtr[index]; |
---|
102 | } |
---|
103 | |
---|
104 | btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration); |
---|
105 | |
---|
106 | virtual ~btCollisionDispatcher(); |
---|
107 | |
---|
108 | virtual btPersistentManifold* getNewManifold(void* b0,void* b1); |
---|
109 | |
---|
110 | virtual void releaseManifold(btPersistentManifold* manifold); |
---|
111 | |
---|
112 | |
---|
113 | virtual void clearManifold(btPersistentManifold* manifold); |
---|
114 | |
---|
115 | |
---|
116 | btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0); |
---|
117 | |
---|
118 | virtual bool needsCollision(btCollisionObject* body0,btCollisionObject* body1); |
---|
119 | |
---|
120 | virtual bool needsResponse(btCollisionObject* body0,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 | }; |
---|
157 | |
---|
158 | #endif //COLLISION__DISPATCHER_H |
---|
159 | |
---|