27 #define USE_PERSISTENT_CONTACTS 1
92 #define b2Dot(a,b) (a).dot(b)
93 #define b2Mul(a,b) (a)*(b)
94 #define b2MulT(a,b) (a).transpose()*(b)
95 #define b2Cross(a,b) (a).cross(b)
96 #define btCrossS(a,s) btVector3(s * a.getY(), -s * a.getX(),0.f)
111 if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
112 if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
115 if (distance0 * distance1 < 0.0f)
118 btScalar interp = distance0 / (distance0 - distance1);
119 vOut[numOut].
v = vIn[0].
v + interp * (vIn[1].
v - vIn[0].
v);
120 if (distance0 > 0.0f)
122 vOut[numOut].
id = vIn[0].
id;
126 vOut[numOut].
id = vIn[1].
id;
144 btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
155 index = (int) normal1.minDot( vertices2, count2, minDot);
179 edge = (int) dLocal1.maxDot( normals1, count1, maxDot);
189 int prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
197 int nextEdge = edge + 1 < count1 ? edge + 1 : 0;
208 if (sPrev > s && sPrev > sNext)
212 bestSeparation = sPrev;
218 bestSeparation = sNext;
230 edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
232 edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;
240 if (s > bestSeparation)
251 *edgeIndex = bestEdge;
252 return bestSeparation;
265 btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
273 for (
int i = 0; i < count2; ++i)
285 int i2 = i1 + 1 < count2 ? i1 + 1 : 0;
287 c[0].
v =
b2Mul(xf2, vertices2[i1]);
292 c[1].
v =
b2Mul(xf2, vertices2[i2]);
312 if (separationA > 0.0f)
317 if (separationB > 0.0f)
325 const btScalar k_relativeTol = 0.98f;
326 const btScalar k_absoluteTol = 0.001f;
329 if (separationB > k_relativeTol * separationA + k_absoluteTol)
355 btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0];
363 v11 =
b2Mul(xf1, v11);
364 v12 =
b2Mul(xf1, v12);
397 btVector3 manifoldNormal = flip ? -frontNormal : frontNormal;
402 btScalar separation =
b2Dot(frontNormal, clipPoints2[i].v) - frontOffset;
404 if (separation <= 0.0f)
412 manifold->
addContactPoint(-manifoldNormal,clipPoints2[i].v,separation);
virtual void releaseManifold(btPersistentManifold *manifold)=0
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
btPersistentManifold * m_manifoldPtr
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
void setPersistentManifold(btPersistentManifold *manifoldPtr)
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2], const btVector3 &normal, btScalar offset)
void refreshContactPoints()
btManifoldResult is a helper class to manage contact results.
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btDispatcher * m_dispatcher
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
void b2CollidePolygons(btManifoldResult *manifold, const btBox2dShape *polyA, const btTransform &xfA, const btBox2dShape *polyB, const btTransform &xfB)
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)
static btScalar FindMaxSeparation(int *edgeIndex, const btBox2dShape *poly1, const btTransform &xf1, const btBox2dShape *poly2, const btTransform &xf2)
const btVector3 * getVertices() const
const btTransform & getWorldTransform() const
btCollisionObject can be used to manage collision detection objects.
static void FindIncidentEdge(ClipVertex c[2], const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
const btCollisionShape * getCollisionShape() const
btVector3 can be used to represent 3D points and vectors.
static btScalar EdgeSeparation(const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
const btVector3 & getCentroid() const
int getVertexCount() const
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
virtual ~btBox2dBox2dCollisionAlgorithm()
const btVector3 * getNormals() const
virtual bool needsCollision(const btCollisionObject *body0, const btCollisionObject *body1)=0
The btBox2dShape is a box primitive around the origin, its sides axis aligned with length specified b...
btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
const btCollisionObject * getCollisionObject() const