Bullet Collision Detection & Physics Library
btConvex2dConvex2dAlgorithm.cpp
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
17
18//#include <stdio.h>
24
30
35
38
40
44
46{
49}
50
52{
53}
54
56 : btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
62{
63 (void)body0Wrap;
64 (void)body1Wrap;
65}
66
68{
69 if (m_ownManifold)
70 {
71 if (m_manifoldPtr)
73 }
74}
75
76void btConvex2dConvex2dAlgorithm ::setLowLevelOfDetail(bool useLowLevel)
77{
78 m_lowLevelOfDetail = useLowLevel;
79}
80
82
83//
84// Convex-Convex collision algorithm
85//
86void btConvex2dConvex2dAlgorithm ::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
87{
88 if (!m_manifoldPtr)
89 {
90 //swapped?
91 m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject());
92 m_ownManifold = true;
93 }
94 resultOut->setPersistentManifold(m_manifoldPtr);
95
96 //comment-out next line to test multi-contact generation
97 //resultOut->getPersistentManifold()->clearManifold();
98
99 const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
100 const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
101
104
105 {
107
108 btGjkPairDetector gjkPairDetector(min0, min1, m_simplexSolver, m_pdSolver);
109 //TODO: if (dispatchInfo.m_useContinuous)
110 gjkPairDetector.setMinkowskiA(min0);
111 gjkPairDetector.setMinkowskiB(min1);
112
113 {
114 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
115 input.m_maximumDistanceSquared *= input.m_maximumDistanceSquared;
116 }
117
118 input.m_transformA = body0Wrap->getWorldTransform();
119 input.m_transformB = body1Wrap->getWorldTransform();
120
121 gjkPairDetector.getClosestPoints(input, *resultOut, dispatchInfo.m_debugDraw);
122
123 btVector3 v0, v1;
125 }
126
127 if (m_ownManifold)
128 {
129 resultOut->refreshContactPoints();
130 }
131}
132
134{
138
142
143 btScalar squareMot0 = (col0->getInterpolationWorldTransform().getOrigin() - col0->getWorldTransform().getOrigin()).length2();
144 btScalar squareMot1 = (col1->getInterpolationWorldTransform().getOrigin() - col1->getWorldTransform().getOrigin()).length2();
145
146 if (squareMot0 < col0->getCcdSquareMotionThreshold() &&
147 squareMot1 < col1->getCcdSquareMotionThreshold())
148 return resultFraction;
149
150 //An adhoc way of testing the Continuous Collision Detection algorithms
151 //One object is approximated as a sphere, to simplify things
152 //Starting in penetration should report no time of impact
153 //For proper CCD, better accuracy and handling of 'allowed' penetration should be added
154 //also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies)
155
157 {
158 btConvexShape* convex0 = static_cast<btConvexShape*>(col0->getCollisionShape());
159
160 btSphereShape sphere1(col1->getCcdSweptSphereRadius()); //todo: allow non-zero sphere sizes, for better approximation
163 //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
166 //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
167 if (ccd1.calcTimeOfImpact(col0->getWorldTransform(), col0->getInterpolationWorldTransform(),
168 col1->getWorldTransform(), col1->getInterpolationWorldTransform(), result))
169 {
170 //store result.m_fraction in both bodies
171
172 if (col0->getHitFraction() > result.m_fraction)
173 col0->setHitFraction(result.m_fraction);
174
175 if (col1->getHitFraction() > result.m_fraction)
176 col1->setHitFraction(result.m_fraction);
177
178 if (resultFraction > result.m_fraction)
179 resultFraction = result.m_fraction;
180 }
181 }
182
184 {
185 btConvexShape* convex1 = static_cast<btConvexShape*>(col1->getCollisionShape());
186
187 btSphereShape sphere0(col0->getCcdSweptSphereRadius()); //todo: allow non-zero sphere sizes, for better approximation
190 //SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
193 //ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
194 if (ccd1.calcTimeOfImpact(col0->getWorldTransform(), col0->getInterpolationWorldTransform(),
195 col1->getWorldTransform(), col1->getInterpolationWorldTransform(), result))
196 {
197 //store result.m_fraction in both bodies
198
199 if (col0->getHitFraction() > result.m_fraction)
200 col0->setHitFraction(result.m_fraction);
201
202 if (col1->getHitFraction() > result.m_fraction)
203 col1->setHitFraction(result.m_fraction);
204
205 if (resultFraction > result.m_fraction)
206 resultFraction = result.m_fraction;
207 }
208 }
209
210 return resultFraction;
211}
btScalar gContactBreakingThreshold
const T & btMax(const T &a, const T &b)
Definition btMinMax.h:27
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:314
#define btSimplexSolverInterface
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
btCollisionObject can be used to manage collision detection objects.
btConvexPenetrationDepthSolver * m_pdSolver
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btConvex2dConvex2dAlgorithm(btPersistentManifold *mf, const btCollisionAlgorithmConstructionInfo &ci, const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, btSimplexSolverInterface *simplexSolver, btConvexPenetrationDepthSolver *pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold)
btSimplexSolverInterface * m_simplexSolver
ConvexPenetrationDepthSolver provides an interface for penetration depth calculation.
The btConvexShape is an abstract shape interface, implemented by all convex shapes such as btBoxShape...
virtual void releaseManifold(btPersistentManifold *manifold)=0
GjkConvexCast performs a raycast on a convex object using support mapping.
btGjkPairDetector uses GJK to implement the btDiscreteCollisionDetectorInterface
btManifoldResult is a helper class to manage contact results.
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
The btSphereShape implements an implicit sphere, centered around a local origin with radius.
btVector3 can be used to represent 3D points and vectors.
Definition btVector3.h:82
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
CreateFunc(btSimplexSolverInterface *simplexSolver, btConvexPenetrationDepthSolver *pdSolver)
RayResult stores the closest result alternatively, add a callback method to decide about closest/all ...