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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btSoftBodyConcaveCollisionAlgorithm.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans https://bulletphysics.org
4
5This software is provided 'as-is', without any express or implied warranty.
6In no event will the authors be held liable for any damages arising from the use of this software.
7Permission is granted to anyone to use this software for any purpose,
8including commercial applications, and to alter it and redistribute it freely,
9subject to the following restrictions:
10
111. 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.
122. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
133. 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"
24class btDispatcher;
25#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
26#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
27class btSoftBody;
28class 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
64 class btSoftBodyTriangleCallback : public btTriangleCallback
65{
66 btSoftBody* m_softBody;
67 const btCollisionObject* m_triBody;
68
69 btVector3 m_aabbMin;
70 btVector3 m_aabbMax;
71
72 btManifoldResult* m_resultOut;
73
74 btDispatcher* m_dispatcher;
75 const btDispatcherInfo* m_dispatchInfoPtr;
76 btScalar m_collisionMarginTriangle;
77
78 btHashMap<btHashKey<btTriIndex>, btTriIndex> m_shapeCache;
79
80public:
81 int m_triangleCount;
82
83 // btPersistentManifold* m_manifoldPtr;
84
85 btSoftBodyTriangleCallback(btDispatcher* dispatcher, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
86
87 void setTimeStepAndCounters(btScalar collisionMarginTriangle, const btCollisionObjectWrapper* triObjWrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
88
89 virtual ~btSoftBodyTriangleCallback();
90
91 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
92
93 void clearCache();
94
95 SIMD_FORCE_INLINE const btVector3& getAabbMin() const
96 {
97 return m_aabbMin;
98 }
99 SIMD_FORCE_INLINE const btVector3& getAabbMax() const
100 {
101 return m_aabbMax;
102 }
103};
104
106 class btSoftBodyConcaveCollisionAlgorithm : public btCollisionAlgorithm
107{
108 bool m_isSwapped;
109
110 btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback;
111
112public:
113 btSoftBodyConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
114
115 virtual ~btSoftBodyConcaveCollisionAlgorithm();
116
117 virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
118
119 btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
120
121 virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
122 {
123 //we don't add any manifolds
124 }
125
126 void clearCache();
127
128 struct CreateFunc : public btCollisionAlgorithmCreateFunc
129 {
130 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
131 {
132 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
133 return new (mem) btSoftBodyConcaveCollisionAlgorithm(ci, body0Wrap, body1Wrap, false);
134 }
135 };
136
137 struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc
138 {
139 virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
140 {
141 void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSoftBodyConcaveCollisionAlgorithm));
142 return new (mem) btSoftBodyConcaveCollisionAlgorithm(ci, body0Wrap, body1Wrap, true);
143 }
144 };
145};
146
147#endif //BT_SOFT_BODY_CONCAVE_COLLISION_ALGORITHM_H
btBroadphaseInterface.h
btBroadphaseProxy.h
btCollisionAlgorithm.h
btCollisionCreateFunc.h
btDispatcher.h
btHashMap.h
btPersistentManifold.h
btQuantizedBvh.h
MAX_NUM_PARTS_IN_BITS
#define MAX_NUM_PARTS_IN_BITS
Definition btQuantizedBvh.h:51
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition btScalar.h:98
btTriangleCallback.h
btAlignedObjectArray< btPersistentManifold * >
btCollisionAlgorithm
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
Definition btCollisionAlgorithm.h:54
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition btCollisionObject.h:51
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
Definition btCollisionShape.h:28
btDispatcher
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
Definition btDispatcher.h:77
btDispatcher::allocateCollisionAlgorithm
virtual void * allocateCollisionAlgorithm(int size)=0
btHashMap
The btHashMap template class implements a generic and lightweight hashmap.
Definition btHashMap.h:220
btManifoldResult
btManifoldResult is a helper class to manage contact results.
Definition btManifoldResult.h:48
btSoftBodyConcaveCollisionAlgorithm
btSoftBodyConcaveCollisionAlgorithm supports collision between soft body shapes and (concave) triange...
Definition btSoftBodyConcaveCollisionAlgorithm.h:107
btSoftBodyConcaveCollisionAlgorithm::clearCache
void clearCache()
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:186
btSoftBodyConcaveCollisionAlgorithm::processCollision
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:191
btSoftBodyConcaveCollisionAlgorithm::m_btSoftBodyTriangleCallback
btSoftBodyTriangleCallback m_btSoftBodyTriangleCallback
Definition btSoftBodyConcaveCollisionAlgorithm.h:110
btSoftBodyConcaveCollisionAlgorithm::btSoftBodyConcaveCollisionAlgorithm
btSoftBodyConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:35
btSoftBodyConcaveCollisionAlgorithm::getAllContactManifolds
virtual void getAllContactManifolds(btManifoldArray &manifoldArray)
Definition btSoftBodyConcaveCollisionAlgorithm.h:121
btSoftBodyConcaveCollisionAlgorithm::m_isSwapped
bool m_isSwapped
Definition btSoftBodyConcaveCollisionAlgorithm.h:108
btSoftBodyConcaveCollisionAlgorithm::calculateTimeOfImpact
btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:214
btSoftBodyConcaveCollisionAlgorithm::~btSoftBodyConcaveCollisionAlgorithm
virtual ~btSoftBodyConcaveCollisionAlgorithm()
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:42
btSoftBodyTriangleCallback
For each triangle in the concave mesh that overlaps with the AABB of a soft body (m_softBody),...
Definition btSoftBodyConcaveCollisionAlgorithm.h:65
btSoftBodyTriangleCallback::m_triBody
const btCollisionObject * m_triBody
Definition btSoftBodyConcaveCollisionAlgorithm.h:67
btSoftBodyTriangleCallback::processTriangle
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:79
btSoftBodyTriangleCallback::m_dispatchInfoPtr
const btDispatcherInfo * m_dispatchInfoPtr
Definition btSoftBodyConcaveCollisionAlgorithm.h:75
btSoftBodyTriangleCallback::btSoftBodyTriangleCallback
btSoftBodyTriangleCallback(btDispatcher *dispatcher, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:46
btSoftBodyTriangleCallback::m_shapeCache
btHashMap< btHashKey< btTriIndex >, btTriIndex > m_shapeCache
Definition btSoftBodyConcaveCollisionAlgorithm.h:78
btSoftBodyTriangleCallback::getAabbMax
const btVector3 & getAabbMax() const
Definition btSoftBodyConcaveCollisionAlgorithm.h:99
btSoftBodyTriangleCallback::m_aabbMax
btVector3 m_aabbMax
Definition btSoftBodyConcaveCollisionAlgorithm.h:70
btSoftBodyTriangleCallback::m_aabbMin
btVector3 m_aabbMin
Definition btSoftBodyConcaveCollisionAlgorithm.h:69
btSoftBodyTriangleCallback::m_collisionMarginTriangle
btScalar m_collisionMarginTriangle
Definition btSoftBodyConcaveCollisionAlgorithm.h:76
btSoftBodyTriangleCallback::clearCache
void clearCache()
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:66
btSoftBodyTriangleCallback::m_resultOut
btManifoldResult * m_resultOut
Definition btSoftBodyConcaveCollisionAlgorithm.h:72
btSoftBodyTriangleCallback::m_softBody
btSoftBody * m_softBody
Definition btSoftBodyConcaveCollisionAlgorithm.h:66
btSoftBodyTriangleCallback::~btSoftBodyTriangleCallback
virtual ~btSoftBodyTriangleCallback()
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:60
btSoftBodyTriangleCallback::getAabbMin
const btVector3 & getAabbMin() const
Definition btSoftBodyConcaveCollisionAlgorithm.h:95
btSoftBodyTriangleCallback::m_triangleCount
int m_triangleCount
Definition btSoftBodyConcaveCollisionAlgorithm.h:81
btSoftBodyTriangleCallback::setTimeStepAndCounters
void setTimeStepAndCounters(btScalar collisionMarginTriangle, const btCollisionObjectWrapper *triObjWrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
Definition btSoftBodyConcaveCollisionAlgorithm.cpp:166
btSoftBodyTriangleCallback::m_dispatcher
btDispatcher * m_dispatcher
Definition btSoftBodyConcaveCollisionAlgorithm.h:74
btSoftBody
The btSoftBody is an class to simulate cloth and volumetric soft bodies.
Definition btSoftBody.h:75
btTriangleCallback
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
Definition btTriangleCallback.h:24
btVector3
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
btCollisionAlgorithmConstructionInfo
Definition btCollisionAlgorithm.h:33
btCollisionAlgorithmConstructionInfo::m_dispatcher1
btDispatcher * m_dispatcher1
Definition btCollisionAlgorithm.h:45
btCollisionAlgorithmCreateFunc
Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm.
Definition btCollisionCreateFunc.h:27
btCollisionObjectWrapper
Definition btCollisionObjectWrapper.h:18
btDispatcherInfo
Definition btDispatcher.h:31
btSoftBodyConcaveCollisionAlgorithm::CreateFunc
Definition btSoftBodyConcaveCollisionAlgorithm.h:129
btSoftBodyConcaveCollisionAlgorithm::CreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition btSoftBodyConcaveCollisionAlgorithm.h:130
btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc
Definition btSoftBodyConcaveCollisionAlgorithm.h:138
btSoftBodyConcaveCollisionAlgorithm::SwappedCreateFunc::CreateCollisionAlgorithm
virtual btCollisionAlgorithm * CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap)
Definition btSoftBodyConcaveCollisionAlgorithm.h:139
btTriIndex
Definition btSoftBodyConcaveCollisionAlgorithm.h:35
btTriIndex::getUid
int getUid() const
Definition btSoftBodyConcaveCollisionAlgorithm.h:57
btTriIndex::getPartId
int getPartId() const
Definition btSoftBodyConcaveCollisionAlgorithm.h:52
btTriIndex::getTriangleIndex
int getTriangleIndex() const
Definition btSoftBodyConcaveCollisionAlgorithm.h:45
btTriIndex::m_childShape
class btCollisionShape * m_childShape
Definition btSoftBodyConcaveCollisionAlgorithm.h:37
btTriIndex::btTriIndex
btTriIndex(int partId, int triangleIndex, btCollisionShape *shape)
Definition btSoftBodyConcaveCollisionAlgorithm.h:39
btTriIndex::m_PartIdTriangleIndex
int m_PartIdTriangleIndex
Definition btSoftBodyConcaveCollisionAlgorithm.h:36