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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

btPersistentManifold.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_PERSISTENT_MANIFOLD_H
17 #define BT_PERSISTENT_MANIFOLD_H
18
19
20 #include "LinearMath/btVector3.h"
21 #include "LinearMath/btTransform.h"
22 #include "btManifoldPoint.h"
23 class btCollisionObject;
24 #include "LinearMath/btAlignedAllocator.h"
25
26 struct btCollisionResult;
27
29 extern btScalar gContactBreakingThreshold;
30
31 typedef bool (*ContactDestroyedCallback)(void* userPersistentData);
32 typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1);
33 extern ContactDestroyedCallback gContactDestroyedCallback;
34 extern ContactProcessedCallback gContactProcessedCallback;
35
36 //the enum starts at 1024 to avoid type conflicts with btTypedConstraint
37 enum btContactManifoldTypes
38 {
39 MIN_CONTACT_MANIFOLD_TYPE = 1024,
40 BT_PERSISTENT_MANIFOLD_TYPE
41 };
42
43 #define MANIFOLD_CACHE_SIZE 4
44
52
53
54 ATTRIBUTE_ALIGNED128( class) btPersistentManifold : public btTypedObject
55 //ATTRIBUTE_ALIGNED16( class) btPersistentManifold : public btTypedObject
56 {
57
58 btManifoldPoint m_pointCache[MANIFOLD_CACHE_SIZE];
59
61 const btCollisionObject* m_body0;
62 const btCollisionObject* m_body1;
63
64 int m_cachedPoints;
65
66 btScalar m_contactBreakingThreshold;
67 btScalar m_contactProcessingThreshold;
68
69
71 int sortCachedPoints(const btManifoldPoint& pt);
72
73 int findContactPoint(const btManifoldPoint* unUsed, int numUnused,const btManifoldPoint& pt);
74
75 public:
76
77 BT_DECLARE_ALIGNED_ALLOCATOR();
78
79 int m_companionIdA;
80 int m_companionIdB;
81
82 int m_index1a;
83
84 btPersistentManifold();
85
86 btPersistentManifold(const btCollisionObject* body0,const btCollisionObject* body1,int , btScalar contactBreakingThreshold,btScalar contactProcessingThreshold)
87 : btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE),
88 m_body0(body0),m_body1(body1),m_cachedPoints(0),
89 m_contactBreakingThreshold(contactBreakingThreshold),
90 m_contactProcessingThreshold(contactProcessingThreshold)
91 {
92 }
93
94 SIMD_FORCE_INLINE const btCollisionObject* getBody0() const { return m_body0;}
95 SIMD_FORCE_INLINE const btCollisionObject* getBody1() const { return m_body1;}
96
97 void setBodies(const btCollisionObject* body0,const btCollisionObject* body1)
98 {
99 m_body0 = body0;
100 m_body1 = body1;
101 }
102
103 void clearUserCache(btManifoldPoint& pt);
104
105 #ifdef DEBUG_PERSISTENCY
106 void DebugPersistency();
107 #endif //
108
109 SIMD_FORCE_INLINE int getNumContacts() const { return m_cachedPoints;}
111 void setNumContacts(int cachedPoints)
112 {
113 m_cachedPoints = cachedPoints;
114 }
115
116
117 SIMD_FORCE_INLINE const btManifoldPoint& getContactPoint(int index) const
118 {
119 btAssert(index < m_cachedPoints);
120 return m_pointCache[index];
121 }
122
123 SIMD_FORCE_INLINE btManifoldPoint& getContactPoint(int index)
124 {
125 btAssert(index < m_cachedPoints);
126 return m_pointCache[index];
127 }
128
130 btScalar getContactBreakingThreshold() const;
131
132 btScalar getContactProcessingThreshold() const
133 {
134 return m_contactProcessingThreshold;
135 }
136
137 void setContactBreakingThreshold(btScalar contactBreakingThreshold)
138 {
139 m_contactBreakingThreshold = contactBreakingThreshold;
140 }
141
142 void setContactProcessingThreshold(btScalar contactProcessingThreshold)
143 {
144 m_contactProcessingThreshold = contactProcessingThreshold;
145 }
146
147
148
149
150 int getCacheEntry(const btManifoldPoint& newPoint) const;
151
152 int addManifoldPoint( const btManifoldPoint& newPoint, bool isPredictive=false);
153
154 void removeContactPoint (int index)
155 {
156 clearUserCache(m_pointCache[index]);
157
158 int lastUsedIndex = getNumContacts() - 1;
159 // m_pointCache[index] = m_pointCache[lastUsedIndex];
160 if(index != lastUsedIndex)
161 {
162 m_pointCache[index] = m_pointCache[lastUsedIndex];
163 //get rid of duplicated userPersistentData pointer
164 m_pointCache[lastUsedIndex].m_userPersistentData = 0;
165 m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f;
166 m_pointCache[lastUsedIndex].m_lateralFrictionInitialized = false;
167 m_pointCache[lastUsedIndex].m_appliedImpulseLateral1 = 0.f;
168 m_pointCache[lastUsedIndex].m_appliedImpulseLateral2 = 0.f;
169 m_pointCache[lastUsedIndex].m_lifeTime = 0;
170 }
171
172 btAssert(m_pointCache[lastUsedIndex].m_userPersistentData==0);
173 m_cachedPoints--;
174 }
175 void replaceContactPoint(const btManifoldPoint& newPoint,int insertIndex)
176 {
177 btAssert(validContactDistance(newPoint));
178
179 #define MAINTAIN_PERSISTENCY 1
180 #ifdef MAINTAIN_PERSISTENCY
181 int lifeTime = m_pointCache[insertIndex].getLifeTime();
182 btScalar appliedImpulse = m_pointCache[insertIndex].m_appliedImpulse;
183 btScalar appliedLateralImpulse1 = m_pointCache[insertIndex].m_appliedImpulseLateral1;
184 btScalar appliedLateralImpulse2 = m_pointCache[insertIndex].m_appliedImpulseLateral2;
185 // bool isLateralFrictionInitialized = m_pointCache[insertIndex].m_lateralFrictionInitialized;
186
187
188
189 btAssert(lifeTime>=0);
190 void* cache = m_pointCache[insertIndex].m_userPersistentData;
191
192 m_pointCache[insertIndex] = newPoint;
193
194 m_pointCache[insertIndex].m_userPersistentData = cache;
195 m_pointCache[insertIndex].m_appliedImpulse = appliedImpulse;
196 m_pointCache[insertIndex].m_appliedImpulseLateral1 = appliedLateralImpulse1;
197 m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2;
198
199
200 m_pointCache[insertIndex].m_lifeTime = lifeTime;
201 #else
202 clearUserCache(m_pointCache[insertIndex]);
203 m_pointCache[insertIndex] = newPoint;
204
205 #endif
206 }
207
208
209 bool validContactDistance(const btManifoldPoint& pt) const
210 {
211 return pt.m_distance1 <= getContactBreakingThreshold();
212 }
214 void refreshContactPoints( const btTransform& trA,const btTransform& trB);
215
216
217 SIMD_FORCE_INLINE void clearManifold()
218 {
219 int i;
220 for (i=0;i<m_cachedPoints;i++)
221 {
222 clearUserCache(m_pointCache[i]);
223 }
224 m_cachedPoints = 0;
225 }
226
227
228
229 }
230 ;
231
232
233
234
235
236 #endif //BT_PERSISTENT_MANIFOLD_H
btPersistentManifold::m_companionIdA
int m_companionIdA
Definition: btPersistentManifold.h:79
btPersistentManifold
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
Definition: btPersistentManifold.h:54
btPersistentManifold::m_body1
const btCollisionObject * m_body1
Definition: btPersistentManifold.h:62
BT_PERSISTENT_MANIFOLD_TYPE
Definition: btPersistentManifold.h:40
btVector3.h
btManifoldPoint::m_appliedImpulseLateral1
btScalar m_appliedImpulseLateral1
Definition: btManifoldPoint.h:107
ATTRIBUTE_ALIGNED128
#define ATTRIBUTE_ALIGNED128(a)
Definition: btScalar.h:66
MIN_CONTACT_MANIFOLD_TYPE
Definition: btPersistentManifold.h:39
btManifoldPoint::getLifeTime
int getLifeTime() const
Definition: btManifoldPoint.h:126
btManifoldPoint::m_appliedImpulse
btScalar m_appliedImpulse
Definition: btManifoldPoint.h:106
btAssert
#define btAssert(x)
Definition: btScalar.h:113
SIMD_FORCE_INLINE
#define SIMD_FORCE_INLINE
Definition: btScalar.h:63
gContactDestroyedCallback
ContactDestroyedCallback gContactDestroyedCallback
Definition: btPersistentManifold.cpp:22
btTransform.h
btManifoldPoint
ManifoldContactPoint collects and maintains persistent contactpoints.
Definition: btManifoldPoint.h:42
btPersistentManifold::getBody0
const btCollisionObject * getBody0() const
Definition: btPersistentManifold.h:94
MANIFOLD_CACHE_SIZE
#define MANIFOLD_CACHE_SIZE
Definition: btPersistentManifold.h:43
btAlignedAllocator.h
btPersistentManifold::m_cachedPoints
int m_cachedPoints
Definition: btPersistentManifold.h:64
btPersistentManifold::setNumContacts
void setNumContacts(int cachedPoints)
the setNumContacts API is usually not used, except when you gather/fill all contacts manually ...
Definition: btPersistentManifold.h:111
btManifoldPoint::m_userPersistentData
void * m_userPersistentData
Definition: btManifoldPoint.h:103
btPersistentManifold::m_companionIdB
int m_companionIdB
Definition: btPersistentManifold.h:80
btPersistentManifold::getContactPoint
btManifoldPoint & getContactPoint(int index)
Definition: btPersistentManifold.h:123
btManifoldPoint::m_appliedImpulseLateral2
btScalar m_appliedImpulseLateral2
Definition: btManifoldPoint.h:108
gContactBreakingThreshold
btScalar gContactBreakingThreshold
maximum contact breaking and merging threshold
Definition: btPersistentManifold.cpp:21
btContactManifoldTypes
btContactManifoldTypes
Definition: btPersistentManifold.h:37
btManifoldPoint::m_lifeTime
int m_lifeTime
Definition: btManifoldPoint.h:114
btCollisionObject
btCollisionObject can be used to manage collision detection objects.
Definition: btCollisionObject.h:49
btPersistentManifold::getContactProcessingThreshold
btScalar getContactProcessingThreshold() const
Definition: btPersistentManifold.h:132
btPersistentManifold::m_index1a
int m_index1a
Definition: btPersistentManifold.h:82
btPersistentManifold::getContactPoint
const btManifoldPoint & getContactPoint(int index) const
Definition: btPersistentManifold.h:117
ContactDestroyedCallback
bool(* ContactDestroyedCallback)(void *userPersistentData)
Definition: btPersistentManifold.h:31
btPersistentManifold::removeContactPoint
void removeContactPoint(int index)
Definition: btPersistentManifold.h:154
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:34
gContactProcessedCallback
ContactProcessedCallback gContactProcessedCallback
Definition: btPersistentManifold.cpp:23
btManifoldPoint::m_distance1
btScalar m_distance1
Definition: btManifoldPoint.h:92
btPersistentManifold::clearManifold
void clearManifold()
Definition: btPersistentManifold.h:217
ContactProcessedCallback
bool(* ContactProcessedCallback)(btManifoldPoint &cp, void *body0, void *body1)
Definition: btPersistentManifold.h:32
btTypedObject
rudimentary class to provide type info
Definition: btScalar.h:744
btPersistentManifold::getNumContacts
int getNumContacts() const
Definition: btPersistentManifold.h:109
BT_DECLARE_ALIGNED_ALLOCATOR
#define BT_DECLARE_ALIGNED_ALLOCATOR()
Definition: btScalar.h:388
btManifoldPoint::m_lateralFrictionInitialized
bool m_lateralFrictionInitialized
Definition: btManifoldPoint.h:104
btPersistentManifold::m_contactProcessingThreshold
btScalar m_contactProcessingThreshold
Definition: btPersistentManifold.h:67
btPersistentManifold::setContactProcessingThreshold
void setContactProcessingThreshold(btScalar contactProcessingThreshold)
Definition: btPersistentManifold.h:142
btPersistentManifold::m_contactBreakingThreshold
btScalar m_contactBreakingThreshold
Definition: btPersistentManifold.h:66
btPersistentManifold::btPersistentManifold
btPersistentManifold(const btCollisionObject *body0, const btCollisionObject *body1, int, btScalar contactBreakingThreshold, btScalar contactProcessingThreshold)
Definition: btPersistentManifold.h:86
btPersistentManifold::replaceContactPoint
void replaceContactPoint(const btManifoldPoint &newPoint, int insertIndex)
Definition: btPersistentManifold.h:175
btPersistentManifold::setContactBreakingThreshold
void setContactBreakingThreshold(btScalar contactBreakingThreshold)
Definition: btPersistentManifold.h:137
btManifoldPoint.h
btPersistentManifold::m_body0
const btCollisionObject * m_body0
this two body pointers can point to the physics rigidbody class.
Definition: btPersistentManifold.h:61
btPersistentManifold::getBody1
const btCollisionObject * getBody1() const
Definition: btPersistentManifold.h:95
btPersistentManifold::setBodies
void setBodies(const btCollisionObject *body0, const btCollisionObject *body1)
Definition: btPersistentManifold.h:97
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btPersistentManifold::validContactDistance
bool validContactDistance(const btManifoldPoint &pt) const
Definition: btPersistentManifold.h:209