27#define USE_PERSISTENT_CONTACTS 1
86#define b2Dot(a, b) (a).dot(b)
87#define b2Mul(a, b) (a) * (b)
88#define b2MulT(a, b) (a).transpose() * (b)
89#define b2Cross(a, b) (a).cross(b)
90#define btCrossS(a, s) btVector3(s* a.getY(), -s* a.getX(), 0.f)
105 if (distance0 <= 0.0f) vOut[numOut++] = vIn[0];
106 if (distance1 <= 0.0f) vOut[numOut++] = vIn[1];
109 if (distance0 * distance1 < 0.0f)
112 btScalar interp = distance0 / (distance0 - distance1);
113 vOut[numOut].
v = vIn[0].
v + interp * (vIn[1].
v - vIn[0].
v);
114 if (distance0 > 0.0f)
116 vOut[numOut].
id = vIn[0].
id;
120 vOut[numOut].
id = vIn[1].
id;
138 btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
149 index = (int)normal1.
minDot(vertices2, count2, minDot);
173 edge = (int)dLocal1.
maxDot(normals1, count1, maxDot);
183 int prevEdge = edge - 1 >= 0 ? edge - 1 : count1 - 1;
191 int nextEdge = edge + 1 < count1 ? edge + 1 : 0;
202 if (sPrev > s && sPrev > sNext)
206 bestSeparation = sPrev;
212 bestSeparation = sNext;
224 edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
226 edge = bestEdge + 1 < count1 ? bestEdge + 1 : 0;
234 if (s > bestSeparation)
245 *edgeIndex = bestEdge;
246 return bestSeparation;
259 btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
267 for (
int i = 0; i < count2; ++i)
279 int i2 = i1 + 1 < count2 ? i1 + 1 : 0;
281 c[0].
v =
b2Mul(xf2, vertices2[i1]);
286 c[1].
v =
b2Mul(xf2, vertices2[i2]);
305 if (separationA > 0.0f)
310 if (separationB > 0.0f)
318 const btScalar k_relativeTol = 0.98f;
319 const btScalar k_absoluteTol = 0.001f;
322 if (separationB > k_relativeTol * separationA + k_absoluteTol)
348 btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1 + 1] : vertices1[0];
355 v11 =
b2Mul(xf1, v11);
356 v12 =
b2Mul(xf1, v12);
388 btVector3 manifoldNormal = flip ? -frontNormal : frontNormal;
393 btScalar separation =
b2Dot(frontNormal, clipPoints2[i].v) - frontOffset;
395 if (separation <= 0.0f)
402 manifold->
addContactPoint(-manifoldNormal, clipPoints2[i].v, separation);
static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2], const btVector3 &normal, btScalar offset)
static btScalar EdgeSeparation(const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
static void FindIncidentEdge(ClipVertex c[2], const btBox2dShape *poly1, const btTransform &xf1, int edge1, const btBox2dShape *poly2, const btTransform &xf2)
static btScalar FindMaxSeparation(int *edgeIndex, const btBox2dShape *poly1, const btTransform &xf1, const btBox2dShape *poly2, const btTransform &xf2)
void b2CollidePolygons(btManifoldResult *manifold, const btBox2dShape *polyA, const btTransform &xfA, const btBox2dShape *polyB, const btTransform &xfB)
btScalar dot(const btQuaternion &q1, const btQuaternion &q2)
Calculate the dot product between two quaternions.
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
This class is not enabled yet (work-in-progress) to more aggressively activate objects.
virtual void processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
virtual ~btBox2dBox2dCollisionAlgorithm()
virtual btScalar calculateTimeOfImpact(btCollisionObject *body0, btCollisionObject *body1, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut)
btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo &ci)
btPersistentManifold * m_manifoldPtr
The btBox2dShape is a box primitive around the origin, its sides axis aligned with length specified b...
const btVector3 * getVertices() const
int getVertexCount() const
const btVector3 & getCentroid() const
const btVector3 * getNormals() const
btDispatcher * m_dispatcher
btCollisionObject can be used to manage collision detection objects.
virtual void releaseManifold(btPersistentManifold *manifold)=0
virtual bool needsCollision(const btCollisionObject *body0, const btCollisionObject *body1)=0
virtual btPersistentManifold * getNewManifold(const btCollisionObject *b0, const btCollisionObject *b1)=0
btManifoldResult is a helper class to manage contact results.
void setPersistentManifold(btPersistentManifold *manifoldPtr)
void refreshContactPoints()
virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth)
btPersistentManifold is a contact point cache, it stays persistent as long as objects are overlapping...
btVector3 can be used to represent 3D points and vectors.
long minDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of minimum dot product between this and vectors in array[]
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
long maxDot(const btVector3 *array, long array_count, btScalar &dotOut) const
returns index of maximum dot product between this and vectors in array[]
btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
const btCollisionShape * getCollisionShape() const
const btCollisionObject * getCollisionObject() const
const btTransform & getWorldTransform() const