Fix for bug #17589: removing a lamp in the game engine with glsl
[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
21
22 /// btDispatcher uses these types
23 /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
24 /// to facilitate type checking
25 enum BroadphaseNativeTypes
26 {
27 // polyhedral convex shapes
28         BOX_SHAPE_PROXYTYPE,
29         TRIANGLE_SHAPE_PROXYTYPE,
30         TETRAHEDRAL_SHAPE_PROXYTYPE,
31         CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
32         CONVEX_HULL_SHAPE_PROXYTYPE,
33 //implicit convex shapes
34 IMPLICIT_CONVEX_SHAPES_START_HERE,
35         SPHERE_SHAPE_PROXYTYPE,
36         MULTI_SPHERE_SHAPE_PROXYTYPE,
37         CAPSULE_SHAPE_PROXYTYPE,
38         CONE_SHAPE_PROXYTYPE,
39         CONVEX_SHAPE_PROXYTYPE,
40         CYLINDER_SHAPE_PROXYTYPE,
41         MINKOWSKI_SUM_SHAPE_PROXYTYPE,
42         MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
43 //concave shapes
44 CONCAVE_SHAPES_START_HERE,
45         //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
46         TRIANGLE_MESH_SHAPE_PROXYTYPE,
47         ///used for demo integration FAST/Swift collision library and Bullet
48         FAST_CONCAVE_MESH_PROXYTYPE,
49         //terrain
50         TERRAIN_SHAPE_PROXYTYPE,
51 ///Used for GIMPACT Trimesh integration
52         GIMPACT_SHAPE_PROXYTYPE,
53         
54         EMPTY_SHAPE_PROXYTYPE,
55         STATIC_PLANE_PROXYTYPE,
56 CONCAVE_SHAPES_END_HERE,
57
58         COMPOUND_SHAPE_PROXYTYPE,
59
60         MAX_BROADPHASE_COLLISION_TYPES
61 };
62
63
64 ///btBroadphaseProxy
65 struct btBroadphaseProxy
66 {
67         
68         ///optional filtering to cull potential collisions
69         enum CollisionFilterGroups
70         {
71                 DefaultFilter = 1,
72                 StaticFilter = 2,
73                 KinematicFilter = 4,
74                 DebrisFilter = 8,
75                         SensorTrigger = 16,
76                 AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
77         };
78
79         //Usually the client btCollisionObject or Rigidbody class
80         void*   m_clientObject;
81         short int m_collisionFilterGroup;
82         short int m_collisionFilterMask;
83
84         //used for memory pools
85         btBroadphaseProxy() :m_clientObject(0){}
86
87         btBroadphaseProxy(void* userPtr,short int collisionFilterGroup, short int collisionFilterMask)
88                 :m_clientObject(userPtr),
89                 m_collisionFilterGroup(collisionFilterGroup),
90                 m_collisionFilterMask(collisionFilterMask)
91         {
92         }
93
94         static inline bool isPolyhedral(int proxyType)
95         {
96                 return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
97         }
98
99         static inline bool      isConvex(int proxyType)
100         {
101                 return (proxyType < CONCAVE_SHAPES_START_HERE);
102         }
103
104         static inline bool      isConcave(int proxyType)
105         {
106                 return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
107                         (proxyType < CONCAVE_SHAPES_END_HERE));
108         }
109         static inline bool      isCompound(int proxyType)
110         {
111                 return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
112         }
113         static inline bool isInfinite(int proxyType)
114         {
115                 return (proxyType == STATIC_PLANE_PROXYTYPE);
116         }
117         
118 }
119 ;
120
121 class btCollisionAlgorithm;
122
123 struct btBroadphaseProxy;
124
125
126
127 /// contains a pair of aabb-overlapping objects
128 struct btBroadphasePair
129 {
130         btBroadphasePair ()
131                 :
132         m_pProxy0(0),
133                 m_pProxy1(0),
134                 m_algorithm(0),
135                 m_userInfo(0)
136         {
137         }
138
139         btBroadphasePair(const btBroadphasePair& other)
140                 :               m_pProxy0(other.m_pProxy0),
141                                 m_pProxy1(other.m_pProxy1),
142                                 m_algorithm(other.m_algorithm),
143                                 m_userInfo(other.m_userInfo)
144         {
145         }
146         btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
147         {
148
149                 //keep them sorted, so the std::set operations work
150                 if (&proxy0 < &proxy1)
151         { 
152             m_pProxy0 = &proxy0; 
153             m_pProxy1 = &proxy1; 
154         }
155         else 
156         { 
157                         m_pProxy0 = &proxy1; 
158             m_pProxy1 = &proxy0; 
159         }
160
161                 m_algorithm = 0;
162                 m_userInfo = 0;
163
164         }
165         
166         btBroadphaseProxy* m_pProxy0;
167         btBroadphaseProxy* m_pProxy1;
168         
169         mutable btCollisionAlgorithm* m_algorithm;
170         mutable void* m_userInfo;
171
172 };
173
174 /*
175 //comparison for set operation, see Solid DT_Encounter
176 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 
177
178     return a.m_pProxy0 < b.m_pProxy0 || 
179         (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 
180 }
181 */
182
183
184 class btBroadphasePairSortPredicate
185 {
186         public:
187
188                 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
189                 {
190                          return a.m_pProxy0 > b.m_pProxy0 || 
191                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 > b.m_pProxy1) ||
192                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
193                 }
194 };
195
196
197 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
198 {
199          return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
200 }
201
202
203 #endif //BROADPHASE_PROXY_H
204