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 SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H 00017 #define SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H 00018 00019 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 00020 #include "BulletCollision/BroadphaseCollision/btDispatcher.h" 00021 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 00022 #include "BulletCollision/CollisionShapes/btTriangleCallback.h" 00023 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 00024 class btDispatcher; 00025 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" 00026 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h" 00027 class btSoftBody; 00028 class btCollisionShape; 00029 00030 #include "LinearMath/btHashMap.h" 00031 00032 #include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h" //for definition of MAX_NUM_PARTS_IN_BITS 00033 00034 struct btTriIndex 00035 { 00036 int m_PartIdTriangleIndex; 00037 class btCollisionShape* m_childShape; 00038 00039 btTriIndex(int partId,int triangleIndex,btCollisionShape* shape) 00040 { 00041 m_PartIdTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex; 00042 m_childShape = shape; 00043 } 00044 00045 int getTriangleIndex() const 00046 { 00047 // Get only the lower bits where the triangle index is stored 00048 return (m_PartIdTriangleIndex&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS))); 00049 } 00050 int getPartId() const 00051 { 00052 // Get only the highest bits where the part index is stored 00053 return (m_PartIdTriangleIndex>>(31-MAX_NUM_PARTS_IN_BITS)); 00054 } 00055 int getUid() const 00056 { 00057 return m_PartIdTriangleIndex; 00058 } 00059 }; 00060 00061 00063 class btSoftBodyTriangleCallback : public btTriangleCallback 00064 { 00065 btSoftBody* m_softBody; 00066 btCollisionObject* m_triBody; 00067 00068 btVector3 m_aabbMin; 00069 btVector3 m_aabbMax ; 00070 00071 btManifoldResult* m_resultOut; 00072 00073 btDispatcher* m_dispatcher; 00074 const btDispatcherInfo* m_dispatchInfoPtr; 00075 btScalar m_collisionMarginTriangle; 00076 00077 btHashMap<btHashKey<btTriIndex>,btTriIndex> m_shapeCache; 00078 00079 public: 00080 int m_triangleCount; 00081 00082 // btPersistentManifold* m_manifoldPtr; 00083 00084 btSoftBodyTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped); 00085 00086 void setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 00087 00088 virtual ~btSoftBodyTriangleCallback(); 00089 00090 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex); 00091 00092 void clearCache(); 00093 00094 SIMD_FORCE_INLINE const btVector3& getAabbMin() const 00095 { 00096 return m_aabbMin; 00097 } 00098 SIMD_FORCE_INLINE const btVector3& getAabbMax() const 00099 { 00100 return m_aabbMax; 00101 } 00102 00103 }; 00104 00105 00106 00107 00109 class btSoftBodyConcaveCollisionAlgorithm : public btCollisionAlgorithm 00110 { 00111 00112 bool m_isSwapped; 00113 00114 btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback; 00115 00116 public: 00117 00118 btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped); 00119 00120 virtual ~btSoftBodyConcaveCollisionAlgorithm(); 00121 00122 virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 00123 00124 btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut); 00125 00126 virtual void getAllContactManifolds(btManifoldArray& manifoldArray) 00127 { 00128 //we don't add any manifolds 00129 } 00130 00131 void clearCache(); 00132 00133 struct CreateFunc :public btCollisionAlgorithmCreateFunc 00134 { 00135 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) 00136 { 00137 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm)); 00138 return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,false); 00139 } 00140 }; 00141 00142 struct SwappedCreateFunc :public btCollisionAlgorithmCreateFunc 00143 { 00144 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1) 00145 { 00146 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm)); 00147 return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0,body1,true); 00148 } 00149 }; 00150 00151 }; 00152 00153 #endif //SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H