svn merge -r 16411:16453 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[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         ///used for demo integration FAST/Swift collision library and Bullet
50         FAST_CONCAVE_MESH_PROXYTYPE,
51         //terrain
52         TERRAIN_SHAPE_PROXYTYPE,
53 ///Used for GIMPACT Trimesh integration
54         GIMPACT_SHAPE_PROXYTYPE,
55 ///Multimaterial mesh
56     MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
57         
58         EMPTY_SHAPE_PROXYTYPE,
59         STATIC_PLANE_PROXYTYPE,
60 CONCAVE_SHAPES_END_HERE,
61
62         COMPOUND_SHAPE_PROXYTYPE,
63
64         SOFTBODY_SHAPE_PROXYTYPE,
65
66         MAX_BROADPHASE_COLLISION_TYPES
67 };
68
69
70 ///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases. 
71 ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
72 ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
73 {
74
75 BT_DECLARE_ALIGNED_ALLOCATOR();
76         
77         ///optional filtering to cull potential collisions
78         enum CollisionFilterGroups
79         {
80                 DefaultFilter = 1,
81                 StaticFilter = 2,
82                 KinematicFilter = 4,
83                 DebrisFilter = 8,
84                         SensorTrigger = 16,
85                 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
86         };
87
88         //Usually the client btCollisionObject or Rigidbody class
89         void*   m_clientObject;
90
91         short int m_collisionFilterGroup;
92         short int m_collisionFilterMask;
93
94         void*   m_multiSapParentProxy;          
95
96
97         int                     m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
98
99         SIMD_FORCE_INLINE int getUid() const
100         {
101                 return m_uniqueId;
102         }
103
104         //used for memory pools
105         btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0)
106         {
107         }
108
109         btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
110                 :m_clientObject(userPtr),
111                 m_collisionFilterGroup(collisionFilterGroup),
112                 m_collisionFilterMask(collisionFilterMask)
113         {
114                 m_multiSapParentProxy = multiSapParentProxy;
115         }
116
117         
118
119         static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
120         {
121                 return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
122         }
123
124         static SIMD_FORCE_INLINE bool   isConvex(int proxyType)
125         {
126                 return (proxyType < CONCAVE_SHAPES_START_HERE);
127         }
128
129         static SIMD_FORCE_INLINE bool   isConcave(int proxyType)
130         {
131                 return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
132                         (proxyType < CONCAVE_SHAPES_END_HERE));
133         }
134         static SIMD_FORCE_INLINE bool   isCompound(int proxyType)
135         {
136                 return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
137         }
138         static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
139         {
140                 return (proxyType == STATIC_PLANE_PROXYTYPE);
141         }
142         
143 }
144 ;
145
146 class btCollisionAlgorithm;
147
148 struct btBroadphaseProxy;
149
150
151
152 ///The btBroadphasePair class contains a pair of aabb-overlapping objects.
153 ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
154 ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
155 {
156         btBroadphasePair ()
157                 :
158         m_pProxy0(0),
159                 m_pProxy1(0),
160                 m_algorithm(0),
161                 m_userInfo(0)
162         {
163         }
164
165 BT_DECLARE_ALIGNED_ALLOCATOR();
166
167         btBroadphasePair(const btBroadphasePair& other)
168                 :               m_pProxy0(other.m_pProxy0),
169                                 m_pProxy1(other.m_pProxy1),
170                                 m_algorithm(other.m_algorithm),
171                                 m_userInfo(other.m_userInfo)
172         {
173         }
174         btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
175         {
176
177                 //keep them sorted, so the std::set operations work
178                 if (&proxy0 < &proxy1)
179         { 
180             m_pProxy0 = &proxy0; 
181             m_pProxy1 = &proxy1; 
182         }
183         else 
184         { 
185                         m_pProxy0 = &proxy1; 
186             m_pProxy1 = &proxy0; 
187         }
188
189                 m_algorithm = 0;
190                 m_userInfo = 0;
191
192         }
193         
194         btBroadphaseProxy* m_pProxy0;
195         btBroadphaseProxy* m_pProxy1;
196         
197         mutable btCollisionAlgorithm* m_algorithm;
198         mutable void* m_userInfo;
199
200 };
201
202 /*
203 //comparison for set operation, see Solid DT_Encounter
204 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 
205
206     return a.m_pProxy0 < b.m_pProxy0 || 
207         (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 
208 }
209 */
210
211
212
213 class btBroadphasePairSortPredicate
214 {
215         public:
216
217                 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
218                 {
219                          return a.m_pProxy0 > b.m_pProxy0 || 
220                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) ||
221                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
222                 }
223 };
224
225
226 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
227 {
228          return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
229 }
230
231
232 #endif //BROADPHASE_PROXY_H
233