| 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/btVector3.h" | 
|---|
| 21 | #include "LinearMath/btAlignedAllocator.h" | 
|---|
| 22 |  | 
|---|
| 23 |  | 
|---|
| 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 | 
|---|
| 29 | { | 
|---|
| 30 |         // polyhedral convex shapes | 
|---|
| 31 |         BOX_SHAPE_PROXYTYPE, | 
|---|
| 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, | 
|---|
| 43 |         CONE_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 |         CUSTOM_CONVEX_SHAPE_TYPE, | 
|---|
| 50 | //concave shapes | 
|---|
| 51 | CONCAVE_SHAPES_START_HERE, | 
|---|
| 52 |         //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! | 
|---|
| 53 |         TRIANGLE_MESH_SHAPE_PROXYTYPE, | 
|---|
| 54 |         SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE, | 
|---|
| 55 |         ///used for demo integration FAST/Swift collision library and Bullet | 
|---|
| 56 |         FAST_CONCAVE_MESH_PROXYTYPE, | 
|---|
| 57 |         //terrain | 
|---|
| 58 |         TERRAIN_SHAPE_PROXYTYPE, | 
|---|
| 59 | ///Used for GIMPACT Trimesh integration | 
|---|
| 60 |         GIMPACT_SHAPE_PROXYTYPE, | 
|---|
| 61 | ///Multimaterial mesh | 
|---|
| 62 |     MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE, | 
|---|
| 63 |          | 
|---|
| 64 |         EMPTY_SHAPE_PROXYTYPE, | 
|---|
| 65 |         STATIC_PLANE_PROXYTYPE, | 
|---|
| 66 |         CUSTOM_CONCAVE_SHAPE_TYPE, | 
|---|
| 67 | CONCAVE_SHAPES_END_HERE, | 
|---|
| 68 |  | 
|---|
| 69 |         COMPOUND_SHAPE_PROXYTYPE, | 
|---|
| 70 |  | 
|---|
| 71 |         SOFTBODY_SHAPE_PROXYTYPE, | 
|---|
| 72 |         HFFLUID_SHAPE_PROXYTYPE, | 
|---|
| 73 |         HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE, | 
|---|
| 74 |         INVALID_SHAPE_PROXYTYPE, | 
|---|
| 75 |  | 
|---|
| 76 |         MAX_BROADPHASE_COLLISION_TYPES | 
|---|
| 77 |          | 
|---|
| 78 | }; | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 | ///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.  | 
|---|
| 82 | ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody. | 
|---|
| 83 | ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy | 
|---|
| 84 | { | 
|---|
| 85 |  | 
|---|
| 86 | BT_DECLARE_ALIGNED_ALLOCATOR(); | 
|---|
| 87 |          | 
|---|
| 88 |         ///optional filtering to cull potential collisions | 
|---|
| 89 |         enum CollisionFilterGroups | 
|---|
| 90 |         { | 
|---|
| 91 |                 DefaultFilter = 1, | 
|---|
| 92 |                 StaticFilter = 2, | 
|---|
| 93 |                 KinematicFilter = 4, | 
|---|
| 94 |                 DebrisFilter = 8, | 
|---|
| 95 |                         SensorTrigger = 16, | 
|---|
| 96 |                         CharacterFilter = 32, | 
|---|
| 97 |                 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger | 
|---|
| 98 |         }; | 
|---|
| 99 |  | 
|---|
| 100 |         //Usually the client btCollisionObject or Rigidbody class | 
|---|
| 101 |         void*   m_clientObject; | 
|---|
| 102 |         short int m_collisionFilterGroup; | 
|---|
| 103 |         short int m_collisionFilterMask; | 
|---|
| 104 |         void*   m_multiSapParentProxy;           | 
|---|
| 105 |         int                     m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc. | 
|---|
| 106 |  | 
|---|
| 107 |         btVector3       m_aabbMin; | 
|---|
| 108 |         btVector3       m_aabbMax; | 
|---|
| 109 |  | 
|---|
| 110 |         SIMD_FORCE_INLINE int getUid() const | 
|---|
| 111 |         { | 
|---|
| 112 |                 return m_uniqueId; | 
|---|
| 113 |         } | 
|---|
| 114 |  | 
|---|
| 115 |         //used for memory pools | 
|---|
| 116 |         btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0) | 
|---|
| 117 |         { | 
|---|
| 118 |         } | 
|---|
| 119 |  | 
|---|
| 120 |         btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0) | 
|---|
| 121 |                 :m_clientObject(userPtr), | 
|---|
| 122 |                 m_collisionFilterGroup(collisionFilterGroup), | 
|---|
| 123 |                 m_collisionFilterMask(collisionFilterMask), | 
|---|
| 124 |                 m_aabbMin(aabbMin), | 
|---|
| 125 |                 m_aabbMax(aabbMax) | 
|---|
| 126 |         { | 
|---|
| 127 |                 m_multiSapParentProxy = multiSapParentProxy; | 
|---|
| 128 |         } | 
|---|
| 129 |  | 
|---|
| 130 |          | 
|---|
| 131 |  | 
|---|
| 132 |         static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType) | 
|---|
| 133 |         { | 
|---|
| 134 |                 return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE); | 
|---|
| 135 |         } | 
|---|
| 136 |  | 
|---|
| 137 |         static SIMD_FORCE_INLINE bool   isConvex(int proxyType) | 
|---|
| 138 |         { | 
|---|
| 139 |                 return (proxyType < CONCAVE_SHAPES_START_HERE); | 
|---|
| 140 |         } | 
|---|
| 141 |  | 
|---|
| 142 |         static SIMD_FORCE_INLINE bool   isConcave(int proxyType) | 
|---|
| 143 |         { | 
|---|
| 144 |                 return ((proxyType > CONCAVE_SHAPES_START_HERE) && | 
|---|
| 145 |                         (proxyType < CONCAVE_SHAPES_END_HERE)); | 
|---|
| 146 |         } | 
|---|
| 147 |         static SIMD_FORCE_INLINE bool   isCompound(int proxyType) | 
|---|
| 148 |         { | 
|---|
| 149 |                 return (proxyType == COMPOUND_SHAPE_PROXYTYPE); | 
|---|
| 150 |         } | 
|---|
| 151 |         static SIMD_FORCE_INLINE bool isInfinite(int proxyType) | 
|---|
| 152 |         { | 
|---|
| 153 |                 return (proxyType == STATIC_PLANE_PROXYTYPE); | 
|---|
| 154 |         } | 
|---|
| 155 |          | 
|---|
| 156 | } | 
|---|
| 157 | ; | 
|---|
| 158 |  | 
|---|
| 159 | class btCollisionAlgorithm; | 
|---|
| 160 |  | 
|---|
| 161 | struct btBroadphaseProxy; | 
|---|
| 162 |  | 
|---|
| 163 |  | 
|---|
| 164 |  | 
|---|
| 165 | ///The btBroadphasePair class contains a pair of aabb-overlapping objects. | 
|---|
| 166 | ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes. | 
|---|
| 167 | ATTRIBUTE_ALIGNED16(struct) btBroadphasePair | 
|---|
| 168 | { | 
|---|
| 169 |         btBroadphasePair () | 
|---|
| 170 |                 : | 
|---|
| 171 |         m_pProxy0(0), | 
|---|
| 172 |                 m_pProxy1(0), | 
|---|
| 173 |                 m_algorithm(0), | 
|---|
| 174 |                 m_internalInfo1(0) | 
|---|
| 175 |         { | 
|---|
| 176 |         } | 
|---|
| 177 |  | 
|---|
| 178 | BT_DECLARE_ALIGNED_ALLOCATOR(); | 
|---|
| 179 |  | 
|---|
| 180 |         btBroadphasePair(const btBroadphasePair& other) | 
|---|
| 181 |                 :               m_pProxy0(other.m_pProxy0), | 
|---|
| 182 |                                 m_pProxy1(other.m_pProxy1), | 
|---|
| 183 |                                 m_algorithm(other.m_algorithm), | 
|---|
| 184 |                                 m_internalInfo1(other.m_internalInfo1) | 
|---|
| 185 |         { | 
|---|
| 186 |         } | 
|---|
| 187 |         btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1) | 
|---|
| 188 |         { | 
|---|
| 189 |  | 
|---|
| 190 |                 //keep them sorted, so the std::set operations work | 
|---|
| 191 |                 if (proxy0.m_uniqueId < proxy1.m_uniqueId) | 
|---|
| 192 |         {  | 
|---|
| 193 |             m_pProxy0 = &proxy0;  | 
|---|
| 194 |             m_pProxy1 = &proxy1;  | 
|---|
| 195 |         } | 
|---|
| 196 |         else  | 
|---|
| 197 |         {  | 
|---|
| 198 |                         m_pProxy0 = &proxy1;  | 
|---|
| 199 |             m_pProxy1 = &proxy0;  | 
|---|
| 200 |         } | 
|---|
| 201 |  | 
|---|
| 202 |                 m_algorithm = 0; | 
|---|
| 203 |                 m_internalInfo1 = 0; | 
|---|
| 204 |  | 
|---|
| 205 |         } | 
|---|
| 206 |          | 
|---|
| 207 |         btBroadphaseProxy* m_pProxy0; | 
|---|
| 208 |         btBroadphaseProxy* m_pProxy1; | 
|---|
| 209 |          | 
|---|
| 210 |         mutable btCollisionAlgorithm* m_algorithm; | 
|---|
| 211 |         union { void* m_internalInfo1; int m_internalTmpValue;};//don't use this data, it will be removed in future version. | 
|---|
| 212 |  | 
|---|
| 213 | }; | 
|---|
| 214 |  | 
|---|
| 215 | /* | 
|---|
| 216 | //comparison for set operation, see Solid DT_Encounter | 
|---|
| 217 | SIMD_FORCE_INLINE 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 | } | 
|---|
| 222 | */ | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 |  | 
|---|
| 226 | class btBroadphasePairSortPredicate | 
|---|
| 227 | { | 
|---|
| 228 |         public: | 
|---|
| 229 |  | 
|---|
| 230 |                 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) | 
|---|
| 231 |                 { | 
|---|
| 232 |                         const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1; | 
|---|
| 233 |                         const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1; | 
|---|
| 234 |                         const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1; | 
|---|
| 235 |                         const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1; | 
|---|
| 236 |  | 
|---|
| 237 |                          return uidA0 > uidB0 ||  | 
|---|
| 238 |                                 (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) || | 
|---|
| 239 |                                 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);  | 
|---|
| 240 |                 } | 
|---|
| 241 | }; | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b)  | 
|---|
| 245 | { | 
|---|
| 246 |          return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1); | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 |  | 
|---|
| 250 | #endif //BROADPHASE_PROXY_H | 
|---|
| 251 |  | 
|---|