2 Bullet Continuous Collision Detection and Physics Library
3 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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:
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.
16 #ifndef BT_BROADPHASE_PROXY_H
17 #define BT_BROADPHASE_PROXY_H
19 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
20 #include "LinearMath/btVector3.h"
21 #include "LinearMath/btAlignedAllocator.h"
24 /// btDispatcher uses these types
25 /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
26 /// to facilitate type checking
27 /// CUSTOM_POLYHEDRAL_SHAPE_TYPE,CUSTOM_CONVEX_SHAPE_TYPE and CUSTOM_CONCAVE_SHAPE_TYPE can be used to extend Bullet without modifying source code
28 enum BroadphaseNativeTypes
30 // polyhedral convex shapes
32 TRIANGLE_SHAPE_PROXYTYPE,
33 TETRAHEDRAL_SHAPE_PROXYTYPE,
34 CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE,
35 CONVEX_HULL_SHAPE_PROXYTYPE,
36 CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
37 CUSTOM_POLYHEDRAL_SHAPE_TYPE,
38 //implicit convex shapes
39 IMPLICIT_CONVEX_SHAPES_START_HERE,
40 SPHERE_SHAPE_PROXYTYPE,
41 MULTI_SPHERE_SHAPE_PROXYTYPE,
42 CAPSULE_SHAPE_PROXYTYPE,
44 CONVEX_SHAPE_PROXYTYPE,
45 CYLINDER_SHAPE_PROXYTYPE,
46 UNIFORM_SCALING_SHAPE_PROXYTYPE,
47 MINKOWSKI_SUM_SHAPE_PROXYTYPE,
48 MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE,
49 BOX_2D_SHAPE_PROXYTYPE,
50 CONVEX_2D_SHAPE_PROXYTYPE,
51 CUSTOM_CONVEX_SHAPE_TYPE,
53 CONCAVE_SHAPES_START_HERE,
54 //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
55 TRIANGLE_MESH_SHAPE_PROXYTYPE,
56 SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
57 ///used for demo integration FAST/Swift collision library and Bullet
58 FAST_CONCAVE_MESH_PROXYTYPE,
60 TERRAIN_SHAPE_PROXYTYPE,
61 ///Used for GIMPACT Trimesh integration
62 GIMPACT_SHAPE_PROXYTYPE,
64 MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
66 EMPTY_SHAPE_PROXYTYPE,
67 STATIC_PLANE_PROXYTYPE,
68 CUSTOM_CONCAVE_SHAPE_TYPE,
69 CONCAVE_SHAPES_END_HERE,
71 COMPOUND_SHAPE_PROXYTYPE,
73 SOFTBODY_SHAPE_PROXYTYPE,
74 HFFLUID_SHAPE_PROXYTYPE,
75 HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE,
76 INVALID_SHAPE_PROXYTYPE,
78 MAX_BROADPHASE_COLLISION_TYPES
83 ///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
84 ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
85 ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
88 BT_DECLARE_ALIGNED_ALLOCATOR();
90 ///optional filtering to cull potential collisions
91 enum CollisionFilterGroups
99 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
102 //Usually the client btCollisionObject or Rigidbody class
103 void* m_clientObject;
104 short int m_collisionFilterGroup;
105 short int m_collisionFilterMask;
106 void* m_multiSapParentProxy;
107 int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
112 SIMD_FORCE_INLINE int getUid() const
117 //used for memory pools
118 btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0)
122 btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0)
123 :m_clientObject(userPtr),
124 m_collisionFilterGroup(collisionFilterGroup),
125 m_collisionFilterMask(collisionFilterMask),
129 m_multiSapParentProxy = multiSapParentProxy;
134 static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
136 return (proxyType < IMPLICIT_CONVEX_SHAPES_START_HERE);
139 static SIMD_FORCE_INLINE bool isConvex(int proxyType)
141 return (proxyType < CONCAVE_SHAPES_START_HERE);
144 static SIMD_FORCE_INLINE bool isNonMoving(int proxyType)
146 return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE));
149 static SIMD_FORCE_INLINE bool isConcave(int proxyType)
151 return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
152 (proxyType < CONCAVE_SHAPES_END_HERE));
154 static SIMD_FORCE_INLINE bool isCompound(int proxyType)
156 return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
159 static SIMD_FORCE_INLINE bool isSoftBody(int proxyType)
161 return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
164 static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
166 return (proxyType == STATIC_PLANE_PROXYTYPE);
169 static SIMD_FORCE_INLINE bool isConvex2d(int proxyType)
171 return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE);
178 class btCollisionAlgorithm;
180 struct btBroadphaseProxy;
184 ///The btBroadphasePair class contains a pair of aabb-overlapping objects.
185 ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
186 ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
197 BT_DECLARE_ALIGNED_ALLOCATOR();
199 btBroadphasePair(const btBroadphasePair& other)
200 : m_pProxy0(other.m_pProxy0),
201 m_pProxy1(other.m_pProxy1),
202 m_algorithm(other.m_algorithm),
203 m_internalInfo1(other.m_internalInfo1)
206 btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
209 //keep them sorted, so the std::set operations work
210 if (proxy0.m_uniqueId < proxy1.m_uniqueId)
226 btBroadphaseProxy* m_pProxy0;
227 btBroadphaseProxy* m_pProxy1;
229 mutable btCollisionAlgorithm* m_algorithm;
230 union { void* m_internalInfo1; int m_internalTmpValue;};//don't use this data, it will be removed in future version.
235 //comparison for set operation, see Solid DT_Encounter
236 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b)
238 return a.m_pProxy0 < b.m_pProxy0 ||
239 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1);
245 class btBroadphasePairSortPredicate
249 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) const
251 const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
252 const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
253 const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
254 const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
256 return uidA0 > uidB0 ||
257 (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
258 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);
263 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b)
265 return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
269 #endif //BT_BROADPHASE_PROXY_H