Bullet Collision Detection & Physics Library
btConvexConcaveCollisionAlgorithm.cpp
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
30
32: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
33m_btConvexTriangleCallback(ci.m_dispatcher1,body0Wrap,body1Wrap,isSwapped),
34m_isSwapped(isSwapped)
35{
36}
37
39{
40}
41
43{
45 {
47 }
48}
49
50
52 m_dispatcher(dispatcher),
53 m_dispatchInfoPtr(0)
54{
55 m_convexBodyWrap = isSwapped? body1Wrap:body0Wrap;
56 m_triBodyWrap = isSwapped? body0Wrap:body1Wrap;
57
58 //
59 // create the manifold from the dispatcher 'manifold pool'
60 //
62
63 clearCache();
64}
65
67{
68 clearCache();
70
71}
72
73
75{
77}
78
79
82{
83 BT_PROFILE("btConvexTriangleCallback::processTriangle");
84
86 {
87 return;
88 }
89
90 //just for debugging purposes
91 //printf("triangle %d",m_triangleCount++);
92
93
94
97
98
99
100#if 0
101
104 {
106 btVector3 color(1,1,0);
107 btTransform& tr = ob->getWorldTransform();
111 }
112#endif
113
115 {
117 tm.setMargin(m_collisionMarginTriangle);
118
119
122
124 {
125 colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap, &triObWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
126 }
127 else
128 {
130 }
132
134 {
138 }
139 else
140 {
144 }
145
147
149 {
151 } else
152 {
154 }
155
156
157
158 colAlgo->~btCollisionAlgorithm();
159 ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
160 }
161
162}
163
164
165
167{
170
174
175 //recalc aabbs
179 //CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
181 btScalar extraMargin = collisionMarginTriangle+ resultOut->m_closestPointDistanceThreshold;
182
184
185 m_aabbMax += extra;
186 m_aabbMin -= extra;
187
188}
189
191{
193
194}
195
197{
198 BT_PROFILE("btConvexConcaveCollisionAlgorithm::processCollision");
199
200 const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
201 const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
202
203 if (triBodyWrap->getCollisionShape()->isConcave())
204 {
205
206
207
208 const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>( triBodyWrap->getCollisionShape());
209
210 if (convexBodyWrap->getCollisionShape()->isConvex())
211 {
213
214 resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
216
217 m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBodyWrap->getCollisionObject(),triBodyWrap->getCollisionObject());
218
220
221 resultOut->refreshContactPoints();
222
224
225 }
226
227 }
228
229}
230
231
233{
238
239
240 //quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
241
242 //only perform CCD above a certain threshold, this prevents blocking on the long run
243 //because object in a blocked ccd state (hitfraction<1) get their linear velocity halved each frame...
244 btScalar squareMot0 = (convexbody->getInterpolationWorldTransform().getOrigin() - convexbody->getWorldTransform().getOrigin()).length2();
245 if (squareMot0 < convexbody->getCcdSquareMotionThreshold())
246 {
247 return btScalar(1.);
248 }
249
250 //const btVector3& from = convexbody->m_worldTransform.getOrigin();
251 //btVector3 to = convexbody->m_interpolationWorldTransform.getOrigin();
252 //todo: only do if the motion exceeds the 'radius'
253
254 btTransform triInv = triBody->getWorldTransform().inverse();
255 btTransform convexFromLocal = triInv * convexbody->getWorldTransform();
256 btTransform convexToLocal = triInv * convexbody->getInterpolationWorldTransform();
257
259 {
263
265 btScalar m_hitFraction;
266
267
272 m_hitFraction(hitFraction)
273 {
274 }
275
276
277 virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
278 {
279 BT_PROFILE("processTriangle");
280 (void)partId;
282 //do a swept sphere for now
286 castResult.m_fraction = m_hitFraction;
291 //GjkConvexCast convexCaster(&pointShape,convexShape,&simplexSolver);
292 //ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
293 //local space?
294
297 {
298 if (m_hitFraction > castResult.m_fraction)
299 m_hitFraction = castResult.m_fraction;
300 }
301
302 }
303
304 };
305
306
307
308
309
310 if (triBody->getCollisionShape()->isConcave())
311 {
313 rayAabbMin.setMin(convexToLocal.getOrigin());
315 rayAabbMax.setMax(convexToLocal.getOrigin());
316 btScalar ccdRadius0 = convexbody->getCcdSweptSphereRadius();
319
320 btScalar curHitFraction = btScalar(1.); //is this available?
322 convexbody->getCcdSweptSphereRadius(),curHitFraction);
323
324 raycastCallback.m_hitFraction = convexbody->getHitFraction();
325
327
328 btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
329
330 if (triangleMesh)
331 {
333 }
334
335
336
337 if (raycastCallback.m_hitFraction < convexbody->getHitFraction())
338 {
339 convexbody->setHitFraction( raycastCallback.m_hitFraction);
340 return raycastCallback.m_hitFraction;
341 }
342 }
343
344 return btScalar(1.);
345
346}
bool TestTriangleAgainstAabb2(const btVector3 *vertices, const btVector3 &aabbMin, const btVector3 &aabbMax)
conservative test for overlap between triangle and aabb
Definition btAabbUtil2.h:59
@ BT_CLOSEST_POINT_ALGORITHMS
@ BT_CONTACT_POINT_ALGORITHMS
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:29
#define BT_PROFILE(name)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:292
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
void push_back(const T &_Val)
btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatche...
btCollisionObject can be used to manage collision detection objects.
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
bool isConvex() const
virtual void getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const =0
getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
The btConcaveShape class provides an interface for non-moving (static) concave shapes.
virtual btScalar getMargin() const
virtual void processAllTriangles(btTriangleCallback *callback, const btVector3 &aabbMin, const btVector3 &aabbMax) const =0
btConvexConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
virtual void getAllContactManifolds(btManifoldArray &manifoldArray)
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btConvexTriangleCallback(btDispatcher *dispatcher, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, bool isSwapped)
virtual void processTriangle(btVector3 *triangle, int partId, int triangleIndex)
void setTimeStepAndCounters(btScalar collisionMarginTriangle, const btDispatcherInfo &dispatchInfo, const btCollisionObjectWrapper *convexBodyWrap, const btCollisionObjectWrapper *triBodyWrap, btManifoldResult *resultOut)
const btCollisionObjectWrapper * m_convexBodyWrap
const btCollisionObjectWrapper * m_triBodyWrap
The btDispatcher interface class can be used in combination with broadphase to dispatch calculations ...
virtual void clearManifold(btPersistentManifold *manifold)=0
virtual void releaseManifold(btPersistentManifold *manifold)=0
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
virtual void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)=0
virtual int getDebugMode() const =0
btManifoldResult is a helper class to manage contact results.
virtual void setShapeIdentifiersA(int partId0, int index0)
setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material comb...
void setBody0Wrap(const btCollisionObjectWrapper *obj0Wrap)
const btCollisionObjectWrapper * getBody1Wrap() const
void setBody1Wrap(const btCollisionObjectWrapper *obj1Wrap)
const btCollisionObject * getBody0Internal() const
virtual void setShapeIdentifiersB(int partId1, int index1)
btScalar m_closestPointDistanceThreshold
const btCollisionObjectWrapper * getBody0Wrap() const
void setBodies(const btCollisionObject *body0, const btCollisionObject *body1)
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
btSubsimplexConvexCast implements Gino van den Bergens' paper "Ray Casting against bteral Convex Obje...
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition btTransform.h:34
btTransform inverse() const
Return the inverse of this transform.
void setIdentity()
Set this transformation to the identity.
The btTriangleCallback provides a callback for each overlapping triangle when calling processAllTrian...
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:84
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
Definition btVector3.h:621
void setMin(const btVector3 &other)
Set each element to the min of the current values and the values of another btVector3.
Definition btVector3.h:638
btVoronoiSimplexSolver is an implementation of the closest point distance algorithm from a 1-4 points...
const btCollisionShape * getCollisionShape() const
const btCollisionObject * getCollisionObject() const
const btTransform & getWorldTransform() const
RayResult stores the closest result alternatively, add a callback method to decide about closest/all ...
class btIDebugDraw * m_debugDraw