Bullet Collision Detection & Physics Library: btSoftBodyConcaveCollisionAlgorithm.h Source File

Bullet Collision Detection & Physics Library

btSoftBodyConcaveCollisionAlgorithm.h
Go to the documentation of this file.
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 BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
17 #define BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
18
19 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
20 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
21 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
22 #include "BulletCollision/CollisionShapes/btTriangleCallback.h"
23 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
24 class btDispatcher;
25 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
26 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
27 class btSoftBody;
28 class btCollisionShape;
29
30 #include "LinearMath/btHashMap.h"
31
32 #include "BulletCollision/BroadphaseCollision/btQuantizedBvh.h" //for definition of MAX_NUM_PARTS_IN_BITS
33
34 struct btTriIndex
35 {
36 int m_PartIdTriangleIndex;
37 class btCollisionShape* m_childShape;
38
39 btTriIndex(int partId,int triangleIndex,btCollisionShape* shape)
40 {
41 m_PartIdTriangleIndex = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
42 m_childShape = shape;
43 }
44
45 int getTriangleIndex() const
46 {
47 // Get only the lower bits where the triangle index is stored
48 unsigned int x = 0;
49 unsigned int y = (~(x&0))<<(31-MAX_NUM_PARTS_IN_BITS);
50 return (m_PartIdTriangleIndex&~(y));
51 }
52 int getPartId() const
53 {
54 // Get only the highest bits where the part index is stored
55 return (m_PartIdTriangleIndex>>(31-MAX_NUM_PARTS_IN_BITS));
56 }
57 int getUid() const
58 {
59 return m_PartIdTriangleIndex;
60 }
61 };
62
63
65 class btSoftBodyTriangleCallback : public btTriangleCallback
66 {
67 btSoftBody* m_softBody;
68 const btCollisionObject* m_triBody;
69
70 btVector3 m_aabbMin;
71 btVector3 m_aabbMax ;
72
73 btManifoldResult* m_resultOut;
74
75 btDispatcher* m_dispatcher;
76 const btDispatcherInfo* m_dispatchInfoPtr;
77 btScalar m_collisionMarginTriangle;
78
79 btHashMap<btHashKey<btTriIndex>,btTriIndex> m_shapeCache;
80
81 public:
82 int m_triangleCount;
83
84 // btPersistentManifold* m_manifoldPtr;
85
86 btSoftBodyTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
87
88 void setTimeStepAndCounters(btScalar collisionMarginTriangle,const btCollisionObjectWrapper* triObjWrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
89
90 virtual ~btSoftBodyTriangleCallback();
91
92 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
93
94 void clearCache();
95
96 SIMD_FORCE_INLINE const btVector3& getAabbMin() const
97 {
98 return m_aabbMin;
99 }
100 SIMD_FORCE_INLINE const btVector3& getAabbMax() const
101 {
102 return m_aabbMax;
103 }
104
105 };
106
107
108
109
111 class btSoftBodyConcaveCollisionAlgorithm : public btCollisionAlgorithm
112 {
113
114 bool m_isSwapped;
115
116 btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback;
117
118 public:
119
120 btSoftBodyConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
121
122 virtual ~btSoftBodyConcaveCollisionAlgorithm();
123
124 virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
125
126 btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
127
128 virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
129 {
130 //we don't add any manifolds
131 }
132
133 void clearCache();
134
135 struct CreateFunc :public btCollisionAlgorithmCreateFunc
136 {
137 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
138 {
139 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
140 return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
141 }
142 };
143
144 struct SwappedCreateFunc :public btCollisionAlgorithmCreateFunc
145 {
146 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
147 {
148 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
149 return new(mem) btSoftBodyConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
150 }
151 };
152
153 };
154
155 #endif //BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
btSoftBodyConcaveCollisionAlgorithm::CreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition: btSoftBodyConcaveCollisionAlgorithm.h:137
btTriIndex::m_PartIdTriangleIndex
int m_PartIdTriangleIndex
Definition: btSoftBodyConcaveCollisionAlgorithm.h:36
btSoftBodyTriangleCallback::m_triBody
const btCollisionObject * m_triBody
Definition: btSoftBodyConcaveCollisionAlgorithm.h:68
btAlignedObjectArray
The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods It...
Definition: btAlignedObjectArray.h:53
btSoftBodyTriangleCallback::m_dispatchInfoPtr
const btDispatcherInfo * m_dispatchInfoPtr
Definition: btSoftBodyConcaveCollisionAlgorithm.h:76
btTriIndex::btTriIndex
btTriIndex(int partId, int triangleIndex, btCollisionShape *shape)
Definition: btSoftBodyConcaveCollisionAlgorithm.h:39
btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition: btSoftBodyConcaveCollisionAlgorithm.h:146
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
Definition: btCollisionShape.h:27
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:64
btPersistentManifold.h
btSoftBodyTriangleCallback::m_collisionMarginTriangle
btScalar m_collisionMarginTriangle
Definition: btSoftBodyConcaveCollisionAlgorithm.h:77
btTriIndex::getPartId
int getPartId() const
Definition: btSoftBodyConcaveCollisionAlgorithm.h:52
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition: btManifoldResult.h:39
btTriIndex::getUid
int getUid() const
Definition: btSoftBodyConcaveCollisionAlgorithm.h:57
btSoftBodyTriangleCallback::m_resultOut
btManifoldResult * m_resultOut
Definition: btSoftBodyConcaveCollisionAlgorithm.h:73
btCollisionCreateFunc.h
btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc
Definition: btSoftBodyConcaveCollisionAlgorithm.h:144
btBroadphaseInterface.h
btHashMap
The btHashMap template class implements a generic and lightweight hashmap.
Definition: btHashMap.h:220
MAX_NUM_PARTS_IN_BITS
#define MAX_NUM_PARTS_IN_BITS
Definition: btQuantizedBvh.h:54
btDispatcher::allocateCollisionAlgorithm
virtual void * allocateCollisionAlgorithm(int size)=0
btTriangleCallback.h
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition: btTriangleCallback.h:24
btSoftBodyTriangleCallback::m_aabbMin
btVector3 m_aabbMin
Definition: btSoftBodyConcaveCollisionAlgorithm.h:70
btCollisionAlgorithmCreateFunc
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.
Definition: btCollisionCreateFunc.h:26
btSoftBodyTriangleCallback::m_softBody
btSoftBody * m_softBody
Definition: btSoftBodyConcaveCollisionAlgorithm.h:67
btSoftBodyTriangleCallback::getAabbMin
const btVector3 & getAabbMin() const
Definition: btSoftBodyConcaveCollisionAlgorithm.h:96
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
processCollision
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btBroadphaseProxy.h
calculateTimeOfImpact
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btSoftBodyTriangleCallback::m_aabbMax
btVector3 m_aabbMax
Definition: btSoftBodyConcaveCollisionAlgorithm.h:71
btSoftBodyConcaveCollisionAlgorithm::CreateFunc
Definition: btSoftBodyConcaveCollisionAlgorithm.h:135
btSoftBodyConcaveCollisionAlgorithm
btSoftBodyConcaveCollisionAlgorithm supports collision between soft body shapes and (concave) triange...
Definition: btSoftBodyConcaveCollisionAlgorithm.h:111
btSoftBodyConcaveCollisionAlgorithm::getAllContactManifolds
virtual void getAllContactManifolds(btManifoldArray &manifoldArray)
Definition: btSoftBodyConcaveCollisionAlgorithm.h:128
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
btSoftBodyTriangleCallback::m_dispatcher
btDispatcher * m_dispatcher
Definition: btSoftBodyConcaveCollisionAlgorithm.h:75
btSoftBodyConcaveCollisionAlgorithm::m_isSwapped
bool m_isSwapped
Definition: btSoftBodyConcaveCollisionAlgorithm.h:114
btTriIndex::getTriangleIndex
int getTriangleIndex() const
Definition: btSoftBodyConcaveCollisionAlgorithm.h:45
btSoftBodyTriangleCallback::m_triangleCount
int m_triangleCount
Definition: btSoftBodyConcaveCollisionAlgorithm.h:82
btSoftBodyConcaveCollisionAlgorithm::m_btSoftBodyTriangleCallback
btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback
Definition: btSoftBodyConcaveCollisionAlgorithm.h:116
btTriIndex
Definition: btSoftBodyConcaveCollisionAlgorithm.h:34
btQuantizedBvh.h
btDispatcherInfo
Definition: btDispatcher.h:30
btCollisionAlgorithmConstructionInfo::m_dispatcher1
btDispatcher * m_dispatcher1
Definition: btCollisionAlgorithm.h:45
btSoftBodyTriangleCallback::m_shapeCache
btHashMap< btHashKey< btTriIndex >, btTriIndex > m_shapeCache
Definition: btSoftBodyConcaveCollisionAlgorithm.h:79
btSoftBodyTriangleCallback::getAabbMax
const btVector3 & getAabbMax() const
Definition: btSoftBodyConcaveCollisionAlgorithm.h:100
btTriIndex::m_childShape
class btCollisionShape * m_childShape
Definition: btSoftBodyConcaveCollisionAlgorithm.h:37
btSoftBodyTriangleCallback
For each triangle in the concave mesh that overlaps with the AABB of a soft body (m_softBody), processTriangle is called.
Definition: btSoftBodyConcaveCollisionAlgorithm.h:65
btCollisionAlgorithmConstructionInfo
Definition: btCollisionAlgorithm.h:32
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition: btSoftBody.h:71
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition: btDispatcher.h:75
btCollisionAlgorithm
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
Definition: btCollisionAlgorithm.h:55
btHashMap.h
btCollisionObjectWrapper
Definition: btCollisionObjectWrapper.h:17
btDispatcher.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btCollisionAlgorithm.h