Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
00017 #define BT_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"
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
00048 return (m_PartIdTriangleIndex&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS)));
00049 }
00050 int getPartId() const
00051 {
00052
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
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
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 //BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H