Blender V2.61 - r43446
|
00001 00004 /* 00005 This source file is part of GIMPACT Library. 00006 00007 For the latest info, see http://gimpact.sourceforge.net/ 00008 00009 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371. 00010 email: projectileman@yahoo.com 00011 00012 00013 This software is provided 'as-is', without any express or implied warranty. 00014 In no event will the authors be held liable for any damages arising from the use of this software. 00015 Permission is granted to anyone to use this software for any purpose, 00016 including commercial applications, and to alter it and redistribute it freely, 00017 subject to the following restrictions: 00018 00019 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. 00020 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 00021 3. This notice may not be removed or altered from any source distribution. 00022 */ 00023 00024 #ifndef BVH_CONCAVE_COLLISION_ALGORITHM_H 00025 #define BVH_CONCAVE_COLLISION_ALGORITHM_H 00026 00027 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h" 00028 #include "BulletCollision/BroadphaseCollision/btDispatcher.h" 00029 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 00030 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 00031 class btDispatcher; 00032 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" 00033 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h" 00034 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" 00035 00036 #include "LinearMath/btAlignedObjectArray.h" 00037 00038 #include "btGImpactShape.h" 00039 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 00040 #include "BulletCollision/CollisionShapes/btCompoundShape.h" 00041 #include "BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h" 00042 #include "LinearMath/btIDebugDraw.h" 00043 00044 00045 00047 00054 class btGImpactCollisionAlgorithm : public btActivatingCollisionAlgorithm 00055 { 00056 protected: 00057 btCollisionAlgorithm * m_convex_algorithm; 00058 btPersistentManifold * m_manifoldPtr; 00059 btManifoldResult* m_resultOut; 00060 const btDispatcherInfo * m_dispatchInfo; 00061 int m_triface0; 00062 int m_part0; 00063 int m_triface1; 00064 int m_part1; 00065 00066 00068 SIMD_FORCE_INLINE btPersistentManifold* newContactManifold(btCollisionObject* body0,btCollisionObject* body1) 00069 { 00070 m_manifoldPtr = m_dispatcher->getNewManifold(body0,body1); 00071 return m_manifoldPtr; 00072 } 00073 00074 SIMD_FORCE_INLINE void destroyConvexAlgorithm() 00075 { 00076 if(m_convex_algorithm) 00077 { 00078 m_convex_algorithm->~btCollisionAlgorithm(); 00079 m_dispatcher->freeCollisionAlgorithm( m_convex_algorithm); 00080 m_convex_algorithm = NULL; 00081 } 00082 } 00083 00084 SIMD_FORCE_INLINE void destroyContactManifolds() 00085 { 00086 if(m_manifoldPtr == NULL) return; 00087 m_dispatcher->releaseManifold(m_manifoldPtr); 00088 m_manifoldPtr = NULL; 00089 } 00090 00091 SIMD_FORCE_INLINE void clearCache() 00092 { 00093 destroyContactManifolds(); 00094 destroyConvexAlgorithm(); 00095 00096 m_triface0 = -1; 00097 m_part0 = -1; 00098 m_triface1 = -1; 00099 m_part1 = -1; 00100 } 00101 00102 SIMD_FORCE_INLINE btPersistentManifold* getLastManifold() 00103 { 00104 return m_manifoldPtr; 00105 } 00106 00107 00108 // Call before process collision 00109 SIMD_FORCE_INLINE void checkManifold(btCollisionObject* body0,btCollisionObject* body1) 00110 { 00111 if(getLastManifold() == 0) 00112 { 00113 newContactManifold(body0,body1); 00114 } 00115 00116 m_resultOut->setPersistentManifold(getLastManifold()); 00117 } 00118 00119 // Call before process collision 00120 SIMD_FORCE_INLINE btCollisionAlgorithm * newAlgorithm(btCollisionObject* body0,btCollisionObject* body1) 00121 { 00122 checkManifold(body0,body1); 00123 00124 btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm( 00125 body0,body1,getLastManifold()); 00126 return convex_algorithm ; 00127 } 00128 00129 // Call before process collision 00130 SIMD_FORCE_INLINE void checkConvexAlgorithm(btCollisionObject* body0,btCollisionObject* body1) 00131 { 00132 if(m_convex_algorithm) return; 00133 m_convex_algorithm = newAlgorithm(body0,body1); 00134 } 00135 00136 00137 00138 00139 void addContactPoint(btCollisionObject * body0, 00140 btCollisionObject * body1, 00141 const btVector3 & point, 00142 const btVector3 & normal, 00143 btScalar distance); 00144 00147 00148 void collide_gjk_triangles(btCollisionObject * body0, 00149 btCollisionObject * body1, 00150 btGImpactMeshShapePart * shape0, 00151 btGImpactMeshShapePart * shape1, 00152 const int * pairs, int pair_count); 00153 00154 void collide_sat_triangles(btCollisionObject * body0, 00155 btCollisionObject * body1, 00156 btGImpactMeshShapePart * shape0, 00157 btGImpactMeshShapePart * shape1, 00158 const int * pairs, int pair_count); 00159 00160 00161 00162 00163 void shape_vs_shape_collision( 00164 btCollisionObject * body0, 00165 btCollisionObject * body1, 00166 btCollisionShape * shape0, 00167 btCollisionShape * shape1); 00168 00169 void convex_vs_convex_collision(btCollisionObject * body0, 00170 btCollisionObject * body1, 00171 btCollisionShape * shape0, 00172 btCollisionShape * shape1); 00173 00174 00175 00176 void gimpact_vs_gimpact_find_pairs( 00177 const btTransform & trans0, 00178 const btTransform & trans1, 00179 btGImpactShapeInterface * shape0, 00180 btGImpactShapeInterface * shape1,btPairSet & pairset); 00181 00182 void gimpact_vs_shape_find_pairs( 00183 const btTransform & trans0, 00184 const btTransform & trans1, 00185 btGImpactShapeInterface * shape0, 00186 btCollisionShape * shape1, 00187 btAlignedObjectArray<int> & collided_primitives); 00188 00189 00190 void gimpacttrimeshpart_vs_plane_collision( 00191 btCollisionObject * body0, 00192 btCollisionObject * body1, 00193 btGImpactMeshShapePart * shape0, 00194 btStaticPlaneShape * shape1,bool swapped); 00195 00196 00197 public: 00198 00199 btGImpactCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1); 00200 00201 virtual ~btGImpactCollisionAlgorithm(); 00202 00203 virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 00204 00205 btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 00206 00207 virtual void getAllContactManifolds(btManifoldArray& manifoldArray) 00208 { 00209 if (m_manifoldPtr) 00210 manifoldArray.push_back(m_manifoldPtr); 00211 } 00212 00213 00214 struct CreateFunc :public btCollisionAlgorithmCreateFunc 00215 { 00216 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) 00217 { 00218 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btGImpactCollisionAlgorithm)); 00219 return new(mem) btGImpactCollisionAlgorithm(ci,body0,body1); 00220 } 00221 }; 00222 00224 static void registerAlgorithm(btCollisionDispatcher * dispatcher); 00225 #ifdef TRI_COLLISION_PROFILING 00226 00227 static float getAverageTreeCollisionTime(); 00228 00230 static float getAverageTriangleCollisionTime(); 00231 #endif //TRI_COLLISION_PROFILING 00232 00234 00239 void gimpact_vs_gimpact(btCollisionObject * body0, 00240 btCollisionObject * body1, 00241 btGImpactShapeInterface * shape0, 00242 btGImpactShapeInterface * shape1); 00243 00244 void gimpact_vs_shape(btCollisionObject * body0, 00245 btCollisionObject * body1, 00246 btGImpactShapeInterface * shape0, 00247 btCollisionShape * shape1,bool swapped); 00248 00249 void gimpact_vs_compoundshape(btCollisionObject * body0, 00250 btCollisionObject * body1, 00251 btGImpactShapeInterface * shape0, 00252 btCompoundShape * shape1,bool swapped); 00253 00254 void gimpact_vs_concave( 00255 btCollisionObject * body0, 00256 btCollisionObject * body1, 00257 btGImpactShapeInterface * shape0, 00258 btConcaveShape * shape1,bool swapped); 00259 00260 00261 00262 00264 void setFace0(int value) 00265 { 00266 m_triface0 = value; 00267 } 00268 int getFace0() 00269 { 00270 return m_triface0; 00271 } 00272 void setFace1(int value) 00273 { 00274 m_triface1 = value; 00275 } 00276 int getFace1() 00277 { 00278 return m_triface1; 00279 } 00280 void setPart0(int value) 00281 { 00282 m_part0 = value; 00283 } 00284 int getPart0() 00285 { 00286 return m_part0; 00287 } 00288 void setPart1(int value) 00289 { 00290 m_part1 = value; 00291 } 00292 int getPart1() 00293 { 00294 return m_part1; 00295 } 00296 00297 }; 00298 00299 00300 //algorithm details 00301 //#define BULLET_TRIANGLE_COLLISION 1 00302 #define GIMPACT_VS_PLANE_COLLISION 1 00303 00304 00305 00306 #endif //BVH_CONCAVE_COLLISION_ALGORITHM_H