Bullet Collision Detection & Physics Library
btPersistentManifold.h
Go to the documentation of this file.
1/*
2Bullet Continuous Collision Detection and Physics Library
3Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
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_PERSISTENT_MANIFOLD_H
17#define BT_PERSISTENT_MANIFOLD_H
18
19
22#include "btManifoldPoint.h"
25
27
30
31#ifndef SWIG
33
42#endif //SWIG
43
44//the enum starts at 1024 to avoid type conflicts with btTypedConstraint
46{
49};
50
51#define MANIFOLD_CACHE_SIZE 4
52
60
61
62//ATTRIBUTE_ALIGNED128( class) btPersistentManifold : public btTypedObject
64{
65
67
71
73
76
77
80
82
83public:
84
86
89
91
93
99 {
100 }
101
104
106 {
107 m_body0 = body0;
108 m_body1 = body1;
109 }
110
112
113#ifdef DEBUG_PERSISTENCY
114 void DebugPersistency();
115#endif //
116
120 {
122 }
123
124
126 {
127 btAssert(index < m_cachedPoints);
128 return m_pointCache[index];
129 }
130
132 {
133 btAssert(index < m_cachedPoints);
134 return m_pointCache[index];
135 }
136
139
141 {
143 }
144
146 {
148 }
149
151 {
153 }
154
155
156
157
158 int getCacheEntry(const btManifoldPoint& newPoint) const;
159
160 int addManifoldPoint( const btManifoldPoint& newPoint, bool isPredictive=false);
161
162 void removeContactPoint (int index)
163 {
165
166 int lastUsedIndex = getNumContacts() - 1;
167// m_pointCache[index] = m_pointCache[lastUsedIndex];
168 if(index != lastUsedIndex)
169 {
171 //get rid of duplicated userPersistentData pointer
178 }
179
180 btAssert(m_pointCache[lastUsedIndex].m_userPersistentData==0);
182
184 {
186 }
187 }
189 {
191
192#define MAINTAIN_PERSISTENCY 1
193#ifdef MAINTAIN_PERSISTENCY
198
199 bool replacePoint = true;
202 if (newPoint.m_contactPointFlags & BT_CONTACT_FLAG_FRICTION_ANCHOR)
203 {
204 // printf("appliedImpulse=%f\n", appliedImpulse);
205 // printf("appliedLateralImpulse1=%f\n", appliedLateralImpulse1);
206 // printf("appliedLateralImpulse2=%f\n", appliedLateralImpulse2);
207 // printf("mu = %f\n", m_pointCache[insertIndex].m_combinedFriction);
209 btScalar eps = 0; //we could allow to enlarge or shrink the tolerance to check against the friction cone a bit, say 1e-7
212 b = b * b;
213 replacePoint = (a) > (b);
214 }
215
216 if (replacePoint)
217 {
218 btAssert(lifeTime >= 0);
220
226 }
227
229#else
232
233#endif
234 }
235
237 {
238 return pt.m_distance1 <= getContactBreakingThreshold();
239 }
242
243
245 {
246 int i;
247 for (i=0;i<m_cachedPoints;i++)
248 {
250 }
251
253 {
255 }
256 m_cachedPoints = 0;
257 }
258
259
260
261}
262;
263
264
265
266
267
268#endif //BT_PERSISTENT_MANIFOLD_H
@ BT_CONTACT_FLAG_FRICTION_ANCHOR
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:29
ContactEndedCallback gContactEndedCallback
void(* ContactEndedCallback)(btPersistentManifold *const &manifold)
ContactStartedCallback gContactStartedCallback
ContactProcessedCallback gContactProcessedCallback
bool(* ContactDestroyedCallback)(void *userPersistentData)
void(* ContactStartedCallback)(btPersistentManifold *const &manifold)
btContactManifoldTypes
@ MIN_CONTACT_MANIFOLD_TYPE
@ BT_PERSISTENT_MANIFOLD_TYPE
ContactDestroyedCallback gContactDestroyedCallback
#define MANIFOLD_CACHE_SIZE
btScalar gContactBreakingThreshold
maximum contact breaking and merging threshold
bool(* ContactProcessedCallback)(btManifoldPoint &cp, void *body0, void *body1)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:292
#define ATTRIBUTE_ALIGNED16(a)
Definition btScalar.h:82
#define SIMD_FORCE_INLINE
Definition btScalar.h:81
#define btAssert(x)
Definition btScalar.h:131
btCollisionObject can be used to manage collision detection objects.
ManifoldContactPoint collects and maintains persistent contactpoints.
int getLifeTime() const
btScalar m_appliedImpulseLateral2
btScalar m_appliedImpulse
btScalar m_appliedImpulseLateral1
btScalar m_combinedFriction
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
const btCollisionObject * m_body1
const btManifoldPoint & getContactPoint(int index) const
bool validContactDistance(const btManifoldPoint &pt) const
const btCollisionObject * getBody0() const
int getCacheEntry(const btManifoldPoint &newPoint) const
void replaceContactPoint(const btManifoldPoint &newPoint, int insertIndex)
void setContactBreakingThreshold(btScalar contactBreakingThreshold)
btManifoldPoint & getContactPoint(int index)
void refreshContactPoints(const btTransform &trA, const btTransform &trB)
calculated new worldspace coordinates and depth, and reject points that exceed the collision margin
int sortCachedPoints(const btManifoldPoint &pt)
sort cached points so most isolated points come first
void setBodies(const btCollisionObject *body0, const btCollisionObject *body1)
int findContactPoint(const btManifoldPoint *unUsed, int numUnused, const btManifoldPoint &pt)
const btCollisionObject * getBody1() const
void clearUserCache(btManifoldPoint &pt)
void removeContactPoint(int index)
void setNumContacts(int cachedPoints)
the setNumContacts API is usually not used, except when you gather/fill all contacts manually
int addManifoldPoint(const btManifoldPoint &newPoint, bool isPredictive=false)
btScalar getContactBreakingThreshold() const
btScalar getContactProcessingThreshold() const
void setContactProcessingThreshold(btScalar contactProcessingThreshold)
btPersistentManifold(const btCollisionObject *body0, const btCollisionObject *body1, int, btScalar contactBreakingThreshold, btScalar contactProcessingThreshold)
const btCollisionObject * m_body0
this two body pointers can point to the physics rigidbody class.
btManifoldPoint m_pointCache[MANIFOLD_CACHE_SIZE]
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:34
rudimentary class to provide type info
Definition btScalar.h:778