Created a KX_SoftBodyDeformer for real-time soft bodies.
[blender.git] / extern / bullet2 / src / BulletCollision / BroadphaseCollision / btBroadphaseProxy.h
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 BROADPHASE_PROXY_H
17 #define BROADPHASE_PROXY_H
18
19 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
20 #include "LinearMath/btAlignedAllocator.h"
21
22
23 /// btDispatcher uses these types
24 /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
25 /// to facilitate type checking
26 enum BroadphaseNativeTypes
27 {
28 // polyhedral convex shapes
29         BOX_SHAPE_PROXYTYPE,
30         TRIANGLE_SHAPE_PROXYTYPE,
31         TETRAHEDRAL_SHAPE_PROXYTYPE,
32         CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
33         CONVEX_HULL_SHAPE_PROXYTYPE,
34 //implicit convex shapes
35 IMPLICIT_CONVEX_SHAPES_START_HERE,
36         SPHERE_SHAPE_PROXYTYPE,
37         MULTI_SPHERE_SHAPE_PROXYTYPE,
38         CAPSULE_SHAPE_PROXYTYPE,
39         CONE_SHAPE_PROXYTYPE,
40         CONVEX_SHAPE_PROXYTYPE,
41         CYLINDER_SHAPE_PROXYTYPE,
42         UNIFORM_SCALING_SHAPE_PROXYTYPE,
43         MINKOWSKI_SUM_SHAPE_PROXYTYPE,
44         MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
45 //concave shapes
46 CONCAVE_SHAPES_START_HERE,
47         //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
48         TRIANGLE_MESH_SHAPE_PROXYTYPE,
49         SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
50         ///used for demo integration FAST/Swift collision library and Bullet
51         FAST_CONCAVE_MESH_PROXYTYPE,
52         //terrain
53         TERRAIN_SHAPE_PROXYTYPE,
54 ///Used for GIMPACT Trimesh integration
55         GIMPACT_SHAPE_PROXYTYPE,
56 ///Multimaterial mesh
57     MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
58         
59         EMPTY_SHAPE_PROXYTYPE,
60         STATIC_PLANE_PROXYTYPE,
61 CONCAVE_SHAPES_END_HERE,
62
63         COMPOUND_SHAPE_PROXYTYPE,
64
65         SOFTBODY_SHAPE_PROXYTYPE,
66
67         MAX_BROADPHASE_COLLISION_TYPES
68 };
69
70
71 ///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases. 
72 ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
73 ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
74 {
75
76 BT_DECLARE_ALIGNED_ALLOCATOR();
77         
78         ///optional filtering to cull potential collisions
79         enum CollisionFilterGroups
80         {
81                 DefaultFilter = 1,
82                 StaticFilter = 2,
83                 KinematicFilter = 4,
84                 DebrisFilter = 8,
85                         SensorTrigger = 16,
86                 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
87         };
88
89         //Usually the client btCollisionObject or Rigidbody class
90         void*   m_clientObject;
91
92         short int m_collisionFilterGroup;
93         short int m_collisionFilterMask;
94
95         void*   m_multiSapParentProxy;          
96
97
98         int                     m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
99
100         SIMD_FORCE_INLINE int getUid() const
101         {
102                 return m_uniqueId;
103         }
104
105         //used for memory pools
106         btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0)
107         {
108         }
109
110         btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
111                 :m_clientObject(userPtr),
112                 m_collisionFilterGroup(collisionFilterGroup),
113                 m_collisionFilterMask(collisionFilterMask)
114         {
115                 m_multiSapParentProxy = multiSapParentProxy;
116         }
117
118         
119
120         static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
121         {
122                 return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
123         }
124
125         static SIMD_FORCE_INLINE bool   isConvex(int proxyType)
126         {
127                 return (proxyType < CONCAVE_SHAPES_START_HERE);
128         }
129
130         static SIMD_FORCE_INLINE bool   isConcave(int proxyType)
131         {
132                 return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
133                         (proxyType < CONCAVE_SHAPES_END_HERE));
134         }
135         static SIMD_FORCE_INLINE bool   isCompound(int proxyType)
136         {
137                 return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
138         }
139         static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
140         {
141                 return (proxyType == STATIC_PLANE_PROXYTYPE);
142         }
143         
144 }
145 ;
146
147 class btCollisionAlgorithm;
148
149 struct btBroadphaseProxy;
150
151
152
153 ///The btBroadphasePair class contains a pair of aabb-overlapping objects.
154 ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
155 ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
156 {
157         btBroadphasePair ()
158                 :
159         m_pProxy0(0),
160                 m_pProxy1(0),
161                 m_algorithm(0),
162                 m_userInfo(0)
163         {
164         }
165
166 BT_DECLARE_ALIGNED_ALLOCATOR();
167
168         btBroadphasePair(const btBroadphasePair& other)
169                 :               m_pProxy0(other.m_pProxy0),
170                                 m_pProxy1(other.m_pProxy1),
171                                 m_algorithm(other.m_algorithm),
172                                 m_userInfo(other.m_userInfo)
173         {
174         }
175         btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
176         {
177
178                 //keep them sorted, so the std::set operations work
179                 if (&proxy0 < &proxy1)
180         { 
181             m_pProxy0 = &proxy0; 
182             m_pProxy1 = &proxy1; 
183         }
184         else 
185         { 
186                         m_pProxy0 = &proxy1; 
187             m_pProxy1 = &proxy0; 
188         }
189
190                 m_algorithm = 0;
191                 m_userInfo = 0;
192
193         }
194         
195         btBroadphaseProxy* m_pProxy0;
196         btBroadphaseProxy* m_pProxy1;
197         
198         mutable btCollisionAlgorithm* m_algorithm;
199         mutable void* m_userInfo;
200
201 };
202
203 /*
204 //comparison for set operation, see Solid DT_Encounter
205 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 
206
207     return a.m_pProxy0 < b.m_pProxy0 || 
208         (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 
209 }
210 */
211
212
213
214 class btBroadphasePairSortPredicate
215 {
216         public:
217
218                 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
219                 {
220                          return a.m_pProxy0 > b.m_pProxy0 || 
221                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) ||
222                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
223                 }
224 };
225
226
227 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
228 {
229          return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
230 }
231
232
233 #endif //BROADPHASE_PROXY_H
234