55 if (dd > radius * radius)
93 if (dd > radius * radius)
128 b2Vec2 P = (1.0f / den) * (u * A + v * B);
131 if (dd > radius * radius)
137 if (
b2Dot(n, Q - A) < 0.0
f)
199 b2EPAxis ComputePolygonSeparation();
245 b2Vec2 edge1 = m_v2 - m_v1;
247 m_normal1.Set(edge1.
y, -edge1.
x);
249 float32 offset0 = 0.0f, offset2 = 0.0f;
250 bool convex1 =
false, convex2 =
false;
255 b2Vec2 edge0 = m_v1 - m_v0;
257 m_normal0.Set(edge0.
y, -edge0.
x);
258 convex1 =
b2Cross(edge0, edge1) >= 0.0f;
259 offset0 =
b2Dot(m_normal0, m_centroidB - m_v0);
265 b2Vec2 edge2 = m_v3 - m_v2;
267 m_normal2.Set(edge2.
y, -edge2.
x);
268 convex2 =
b2Cross(edge1, edge2) > 0.0f;
269 offset2 =
b2Dot(m_normal2, m_centroidB - m_v2);
273 if (hasVertex0 && hasVertex3)
275 if (convex1 && convex2)
277 m_front = offset0 >= 0.0f || offset1 >= 0.0f || offset2 >= 0.0f;
280 m_normal = m_normal1;
281 m_lowerLimit = m_normal0;
282 m_upperLimit = m_normal2;
286 m_normal = -m_normal1;
287 m_lowerLimit = -m_normal1;
288 m_upperLimit = -m_normal1;
293 m_front = offset0 >= 0.0f || (offset1 >= 0.0f && offset2 >= 0.0f);
296 m_normal = m_normal1;
297 m_lowerLimit = m_normal0;
298 m_upperLimit = m_normal1;
302 m_normal = -m_normal1;
303 m_lowerLimit = -m_normal2;
304 m_upperLimit = -m_normal1;
309 m_front = offset2 >= 0.0f || (offset0 >= 0.0f && offset1 >= 0.0f);
312 m_normal = m_normal1;
313 m_lowerLimit = m_normal1;
314 m_upperLimit = m_normal2;
318 m_normal = -m_normal1;
319 m_lowerLimit = -m_normal1;
320 m_upperLimit = -m_normal0;
325 m_front = offset0 >= 0.0f && offset1 >= 0.0f && offset2 >= 0.0f;
328 m_normal = m_normal1;
329 m_lowerLimit = m_normal1;
330 m_upperLimit = m_normal1;
334 m_normal = -m_normal1;
335 m_lowerLimit = -m_normal2;
336 m_upperLimit = -m_normal0;
344 m_front = offset0 >= 0.0f || offset1 >= 0.0f;
347 m_normal = m_normal1;
348 m_lowerLimit = m_normal0;
349 m_upperLimit = -m_normal1;
353 m_normal = -m_normal1;
354 m_lowerLimit = m_normal1;
355 m_upperLimit = -m_normal1;
360 m_front = offset0 >= 0.0f && offset1 >= 0.0f;
363 m_normal = m_normal1;
364 m_lowerLimit = m_normal1;
365 m_upperLimit = -m_normal1;
369 m_normal = -m_normal1;
370 m_lowerLimit = m_normal1;
371 m_upperLimit = -m_normal0;
379 m_front = offset1 >= 0.0f || offset2 >= 0.0f;
382 m_normal = m_normal1;
383 m_lowerLimit = -m_normal1;
384 m_upperLimit = m_normal2;
388 m_normal = -m_normal1;
389 m_lowerLimit = -m_normal1;
390 m_upperLimit = m_normal1;
395 m_front = offset1 >= 0.0f && offset2 >= 0.0f;
398 m_normal = m_normal1;
399 m_lowerLimit = -m_normal1;
400 m_upperLimit = m_normal1;
404 m_normal = -m_normal1;
405 m_lowerLimit = -m_normal2;
406 m_upperLimit = m_normal1;
412 m_front = offset1 >= 0.0f;
415 m_normal = m_normal1;
416 m_lowerLimit = -m_normal1;
417 m_upperLimit = -m_normal1;
421 m_normal = -m_normal1;
422 m_lowerLimit = m_normal1;
423 m_upperLimit = m_normal1;
428 m_polygonB.count = polygonB->
m_count;
439 b2EPAxis edgeAxis = ComputeEdgeSeparation();
452 b2EPAxis polygonAxis = ComputePolygonSeparation();
459 const float32 k_relativeTol = 0.98f;
460 const float32 k_absoluteTol = 0.001f;
465 primaryAxis = edgeAxis;
469 primaryAxis = polygonAxis;
473 primaryAxis = edgeAxis;
484 float32 bestValue =
b2Dot(m_normal, m_polygonB.normals[0]);
485 for (
int32 i = 1; i < m_polygonB.count; ++i)
488 if (value < bestValue)
495 int32 i1 = bestIndex;
496 int32 i2 = i1 + 1 < m_polygonB.count ? i1 + 1 : 0;
498 ie[0].
v = m_polygonB.vertices[i1];
504 ie[1].
v = m_polygonB.vertices[i2];
544 rf.
i2 = rf.
i1 + 1 < m_polygonB.count ? rf.
i1 + 1 : 0;
545 rf.
v1 = m_polygonB.vertices[rf.
i1];
546 rf.
v2 = m_polygonB.vertices[rf.
i2];
547 rf.
normal = m_polygonB.normals[rf.
i1];
588 int32 pointCount = 0;
595 if (separation <= m_radius)
602 cp->
id = clipPoints2[i].
id;
624 axis.
index = m_front ? 0 : 1;
627 for (
int32 i = 0; i < m_polygonB.count; ++i)
646 b2Vec2 perp(-m_normal.y, m_normal.x);
648 for (
int32 i = 0; i < m_polygonB.count; ++i)
650 b2Vec2 n = -m_polygonB.normals[i];
666 if (
b2Dot(n, perp) >= 0.0
f)
697 collider.
Collide(manifold, edgeA, xfA, polygonB, xfB);
float32 b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
b2Vec2 b2Mul(const b2Mat22 &A, const b2Vec2 &v)
Used for computing contact manifolds.
b2Vec2 localNormal
not use for Type::e_points
b2ContactID id
uniquely identifies a contact point between two shapes
#define b2_maxManifoldPoints
void Collide(b2Manifold *manifold, const b2EdgeShape *edgeA, const b2Transform &xfA, const b2PolygonShape *polygonB, const b2Transform &xfB)
b2Vec2 m_vertex0
Optional adjacent vertices. These are used for smooth collision.
void b2CollideEdgeAndCircle(b2Manifold *manifold, const b2EdgeShape *edgeA, const b2Transform &xfA, const b2CircleShape *circleB, const b2Transform &xfB)
Compute the collision manifold between an edge and a circle.
void SetZero()
Set this vector to all zeros.
float32 b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
b2Vec2 m_vertices[b2_maxPolygonVertices]
int32 pointCount
the number of manifold points
#define b2_maxPolygonVertices
void b2CollideEdgeAndPolygon(b2Manifold *manifold, const b2EdgeShape *edgeA, const b2Transform &xfA, const b2PolygonShape *polygonB, const b2Transform &xfB)
Compute the collision manifold between an edge and a circle.
b2Vec2 localPoint
usage depends on manifold type
b2Vec2 b2MulT(const b2Mat22 &A, const b2Vec2 &v)
b2Vec2 localPoint
usage depends on manifold type
b2ManifoldPoint points[b2_maxManifoldPoints]
the points of contact
b2EPAxis ComputePolygonSeparation()
b2Vec2 m_vertex1
These are the edge vertices.
int32 b2ClipSegmentToLine(b2ClipVertex vOut[2], const b2ClipVertex vIn[2], const b2Vec2 &normal, float32 offset, int32 vertexIndexA)
Clipping for contact manifolds.
b2EPAxis ComputeEdgeSeparation()
float32 Normalize()
Convert this vector into a unit vector. Returns the length.
void Set(float32 x_, float32 y_)
Set this vector to some specified coordinates.
b2Vec2 m_normals[b2_maxPolygonVertices]