Blender V2.61 - r43446
|
00001 /* 00002 Bullet Continuous Collision Detection and Physics Library 00003 Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ 00004 00005 This software is provided 'as-is', without any express or implied warranty. 00006 In no event will the authors be held liable for any damages arising from the use of this software. 00007 Permission is granted to anyone to use this software for any purpose, 00008 including commercial applications, and to alter it and redistribute it freely, 00009 subject to the following restrictions: 00010 00011 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. 00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00013 3. This notice may not be removed or altered from any source distribution. 00014 */ 00015 00016 #ifndef BROADPHASE_PROXY_H 00017 #define BROADPHASE_PROXY_H 00018 00019 #include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE 00020 #include "LinearMath/btVector3.h" 00021 #include "LinearMath/btAlignedAllocator.h" 00022 00023 00028 enum BroadphaseNativeTypes 00029 { 00030 // polyhedral convex shapes 00031 BOX_SHAPE_PROXYTYPE, 00032 TRIANGLE_SHAPE_PROXYTYPE, 00033 TETRAHEDRAL_SHAPE_PROXYTYPE, 00034 CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE, 00035 CONVEX_HULL_SHAPE_PROXYTYPE, 00036 CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE, 00037 CUSTOM_POLYHEDRAL_SHAPE_TYPE, 00038 //implicit convex shapes 00039 IMPLICIT_CONVEX_SHAPES_START_HERE, 00040 SPHERE_SHAPE_PROXYTYPE, 00041 MULTI_SPHERE_SHAPE_PROXYTYPE, 00042 CAPSULE_SHAPE_PROXYTYPE, 00043 CONE_SHAPE_PROXYTYPE, 00044 CONVEX_SHAPE_PROXYTYPE, 00045 CYLINDER_SHAPE_PROXYTYPE, 00046 UNIFORM_SCALING_SHAPE_PROXYTYPE, 00047 MINKOWSKI_SUM_SHAPE_PROXYTYPE, 00048 MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE, 00049 BOX_2D_SHAPE_PROXYTYPE, 00050 CONVEX_2D_SHAPE_PROXYTYPE, 00051 CUSTOM_CONVEX_SHAPE_TYPE, 00052 //concave shapes 00053 CONCAVE_SHAPES_START_HERE, 00054 //keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy! 00055 TRIANGLE_MESH_SHAPE_PROXYTYPE, 00056 SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE, 00058 FAST_CONCAVE_MESH_PROXYTYPE, 00059 //terrain 00060 TERRAIN_SHAPE_PROXYTYPE, 00062 GIMPACT_SHAPE_PROXYTYPE, 00064 MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE, 00065 00066 EMPTY_SHAPE_PROXYTYPE, 00067 STATIC_PLANE_PROXYTYPE, 00068 CUSTOM_CONCAVE_SHAPE_TYPE, 00069 CONCAVE_SHAPES_END_HERE, 00070 00071 COMPOUND_SHAPE_PROXYTYPE, 00072 00073 SOFTBODY_SHAPE_PROXYTYPE, 00074 HFFLUID_SHAPE_PROXYTYPE, 00075 HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE, 00076 INVALID_SHAPE_PROXYTYPE, 00077 00078 MAX_BROADPHASE_COLLISION_TYPES 00079 00080 }; 00081 00082 00085 ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy 00086 { 00087 00088 BT_DECLARE_ALIGNED_ALLOCATOR(); 00089 00091 enum CollisionFilterGroups 00092 { 00093 DefaultFilter = 1, 00094 StaticFilter = 2, 00095 KinematicFilter = 4, 00096 DebrisFilter = 8, 00097 SensorTrigger = 16, 00098 CharacterFilter = 32, 00099 AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger 00100 }; 00101 00102 //Usually the client btCollisionObject or Rigidbody class 00103 void* m_clientObject; 00104 short int m_collisionFilterGroup; 00105 short int m_collisionFilterMask; 00106 void* m_multiSapParentProxy; 00107 int m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc. 00108 00109 btVector3 m_aabbMin; 00110 btVector3 m_aabbMax; 00111 00112 SIMD_FORCE_INLINE int getUid() const 00113 { 00114 return m_uniqueId; 00115 } 00116 00117 //used for memory pools 00118 btBroadphaseProxy() :m_clientObject(0),m_multiSapParentProxy(0) 00119 { 00120 } 00121 00122 btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr,short int collisionFilterGroup, short int collisionFilterMask,void* multiSapParentProxy=0) 00123 :m_clientObject(userPtr), 00124 m_collisionFilterGroup(collisionFilterGroup), 00125 m_collisionFilterMask(collisionFilterMask), 00126 m_aabbMin(aabbMin), 00127 m_aabbMax(aabbMax) 00128 { 00129 m_multiSapParentProxy = multiSapParentProxy; 00130 } 00131 00132 00133 00134 static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType) 00135 { 00136 return (proxyType < IMPLICIT_CONVEX_SHAPES_START_HERE); 00137 } 00138 00139 static SIMD_FORCE_INLINE bool isConvex(int proxyType) 00140 { 00141 return (proxyType < CONCAVE_SHAPES_START_HERE); 00142 } 00143 00144 static SIMD_FORCE_INLINE bool isNonMoving(int proxyType) 00145 { 00146 return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE)); 00147 } 00148 00149 static SIMD_FORCE_INLINE bool isConcave(int proxyType) 00150 { 00151 return ((proxyType > CONCAVE_SHAPES_START_HERE) && 00152 (proxyType < CONCAVE_SHAPES_END_HERE)); 00153 } 00154 static SIMD_FORCE_INLINE bool isCompound(int proxyType) 00155 { 00156 return (proxyType == COMPOUND_SHAPE_PROXYTYPE); 00157 } 00158 00159 static SIMD_FORCE_INLINE bool isSoftBody(int proxyType) 00160 { 00161 return (proxyType == SOFTBODY_SHAPE_PROXYTYPE); 00162 } 00163 00164 static SIMD_FORCE_INLINE bool isInfinite(int proxyType) 00165 { 00166 return (proxyType == STATIC_PLANE_PROXYTYPE); 00167 } 00168 00169 static SIMD_FORCE_INLINE bool isConvex2d(int proxyType) 00170 { 00171 return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE); 00172 } 00173 00174 00175 } 00176 ; 00177 00178 class btCollisionAlgorithm; 00179 00180 struct btBroadphaseProxy; 00181 00182 00183 00186 ATTRIBUTE_ALIGNED16(struct) btBroadphasePair 00187 { 00188 btBroadphasePair () 00189 : 00190 m_pProxy0(0), 00191 m_pProxy1(0), 00192 m_algorithm(0), 00193 m_internalInfo1(0) 00194 { 00195 } 00196 00197 BT_DECLARE_ALIGNED_ALLOCATOR(); 00198 00199 btBroadphasePair(const btBroadphasePair& other) 00200 : m_pProxy0(other.m_pProxy0), 00201 m_pProxy1(other.m_pProxy1), 00202 m_algorithm(other.m_algorithm), 00203 m_internalInfo1(other.m_internalInfo1) 00204 { 00205 } 00206 btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1) 00207 { 00208 00209 //keep them sorted, so the std::set operations work 00210 if (proxy0.m_uniqueId < proxy1.m_uniqueId) 00211 { 00212 m_pProxy0 = &proxy0; 00213 m_pProxy1 = &proxy1; 00214 } 00215 else 00216 { 00217 m_pProxy0 = &proxy1; 00218 m_pProxy1 = &proxy0; 00219 } 00220 00221 m_algorithm = 0; 00222 m_internalInfo1 = 0; 00223 00224 } 00225 00226 btBroadphaseProxy* m_pProxy0; 00227 btBroadphaseProxy* m_pProxy1; 00228 00229 mutable btCollisionAlgorithm* m_algorithm; 00230 union { void* m_internalInfo1; int m_internalTmpValue;};//don't use this data, it will be removed in future version. 00231 00232 }; 00233 00234 /* 00235 //comparison for set operation, see Solid DT_Encounter 00236 SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePair& b) 00237 { 00238 return a.m_pProxy0 < b.m_pProxy0 || 00239 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 < b.m_pProxy1); 00240 } 00241 */ 00242 00243 00244 00245 class btBroadphasePairSortPredicate 00246 { 00247 public: 00248 00249 bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) 00250 { 00251 const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1; 00252 const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1; 00253 const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1; 00254 const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1; 00255 00256 return uidA0 > uidB0 || 00257 (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) || 00258 (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 00259 } 00260 }; 00261 00262 00263 SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 00264 { 00265 return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1); 00266 } 00267 00268 00269 #endif //BROADPHASE_PROXY_H 00270