124 v->
wA =
b2Mul(transformA, wALocal);
125 v->
wB =
b2Mul(transformB, wBLocal);
126 v->
w = v->
wB - v->
wA;
134 float metric1 = cache->
metric;
135 float metric2 = GetMetric();
136 if (metric2 < 0.5
f * metric1 || 2.0
f * metric1 < metric2 || metric2 <
b2_epsilon)
151 v->
wA =
b2Mul(transformA, wALocal);
152 v->
wB =
b2Mul(transformB, wBLocal);
153 v->
w = v->
wB - v->
wA;
161 cache->
metric = GetMetric();
180 b2Vec2 e12 = m_v2.w - m_v1.w;
181 float sgn =
b2Cross(e12, -m_v1.w);
212 return m_v1.a * m_v1.w + m_v2.a * m_v2.w;
237 *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA;
238 *pB = m_v1.a * m_v1.wB + m_v2.a * m_v2.wB;
242 *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA + m_v3.a * m_v3.wA;
267 return b2Cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
313 float d12_2 = -
b2Dot(w1, e12);
323 float d12_1 =
b2Dot(w2, e12);
334 float inv_d12 = 1.0f / (d12_1 + d12_2);
335 m_v1.a = d12_1 * inv_d12;
336 m_v2.a = d12_2 * inv_d12;
356 float w1e12 =
b2Dot(w1, e12);
357 float w2e12 =
b2Dot(w2, e12);
359 float d12_2 = -w1e12;
366 float w1e13 =
b2Dot(w1, e13);
367 float w3e13 =
b2Dot(w3, e13);
369 float d13_2 = -w1e13;
376 float w2e23 =
b2Dot(w2, e23);
377 float w3e23 =
b2Dot(w3, e23);
379 float d23_2 = -w2e23;
382 float n123 =
b2Cross(e12, e13);
384 float d123_1 = n123 *
b2Cross(w2, w3);
385 float d123_2 = n123 *
b2Cross(w3, w1);
386 float d123_3 = n123 *
b2Cross(w1, w2);
389 if (d12_2 <= 0.0
f && d13_2 <= 0.0
f)
397 if (d12_1 > 0.0
f && d12_2 > 0.0
f && d123_3 <= 0.0
f)
399 float inv_d12 = 1.0f / (d12_1 + d12_2);
400 m_v1.a = d12_1 * inv_d12;
401 m_v2.a = d12_2 * inv_d12;
407 if (d13_1 > 0.0
f && d13_2 > 0.0
f && d123_2 <= 0.0
f)
409 float inv_d13 = 1.0f / (d13_1 + d13_2);
410 m_v1.a = d13_1 * inv_d13;
411 m_v3.a = d13_2 * inv_d13;
418 if (d12_1 <= 0.0
f && d23_2 <= 0.0
f)
427 if (d13_1 <= 0.0
f && d23_1 <= 0.0
f)
436 if (d23_1 > 0.0
f && d23_2 > 0.0
f && d123_1 <= 0.0
f)
438 float inv_d23 = 1.0f / (d23_1 + d23_2);
439 m_v2.a = d23_1 * inv_d23;
440 m_v3.a = d23_2 * inv_d23;
447 float inv_d123 = 1.0f / (d123_1 + d123_2 + d123_3);
448 m_v1.a = d123_1 * inv_d123;
449 m_v2.a = d123_2 * inv_d123;
450 m_v3.a = d123_3 * inv_d123;
468 simplex.
ReadCache(cache, proxyA, transformA, proxyB, transformB);
472 const int32 k_maxIters = 20;
476 int32 saveA[3], saveB[3];
481 while (iter < k_maxIters)
485 for (
int32 i = 0; i < saveCount; ++i)
487 saveA[i] = vertices[i].
indexA;
488 saveB[i] = vertices[i].
indexB;
535 vertex->
w = vertex->
wB - vertex->
wA;
542 bool duplicate =
false;
543 for (
int32 i = 0; i < saveCount; ++i)
545 if (vertex->
indexA == saveA[i] && vertex->
indexB == saveB[i])
585 output->
pointA += rA * normal;
586 output->
pointB -= rB * normal;
615 float radius = radiusA + radiusB;
643 const int32 k_maxIters = 20;
645 while (iter < k_maxIters && v.Length() - sigma > tolerance)
662 float vp =
b2Dot(v, p);
663 float vr =
b2Dot(v, r);
664 if (vp - sigma > lambda * vr)
671 lambda = (vp - sigma) / vr;
687 vertex->
wA = wB + lambda * r;
690 vertex->
w = vertex->
wB - vertex->
wA;
735 if (v.LengthSquared() > 0.0f)
741 output->
point = pointA + radiusA * n;
b2Vec2 * m_vertices
The vertices. Owned by this class.
void Set(const b2Shape *shape, int32 index)
b2Vec2 b2Mul(const b2Mat22 &A, const b2Vec2 &v)
void ReadCache(const b2SimplexCache *cache, const b2DistanceProxy *proxyA, const b2Transform &transformA, const b2DistanceProxy *proxyB, const b2Transform &transformB)
B2_API const b2Vec2 b2Vec2_zero
Useful constant.
float b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
uint8 indexA[3]
vertices on shape A
B2_API int32 b2_gjkMaxIters
int32 iterations
number of GJK iterations used
void SetZero()
Set this vector to all zeros.
b2Vec2 pointB
closest point on shapeB
b2Vec2 pointA
closest point on shapeA
void GetWitnessPoints(b2Vec2 *pA, b2Vec2 *pB) const
int32 GetSupport(const b2Vec2 &d) const
Get the supporting vertex index in the given direction.
float LengthSquared() const
float 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]
Output results for b2ShapeCast.
const b2Vec2 * m_vertices
uint8 indexB[3]
vertices on shape B
void WriteCache(b2SimplexCache *cache) const
b2Vec2 GetClosestPoint() const
b2Vec2 b2MulT(const b2Mat22 &A, const b2Vec2 &v)
b2Vec2 m_vertex1
These are the edge vertices.
float Normalize()
Convert this vector into a unit vector. Returns the length.
int32 m_count
The vertex count.
bool b2ShapeCast(b2ShapeCastOutput *output, const b2ShapeCastInput *input)
const b2Vec2 & GetVertex(int32 index) const
Get a vertex by index. Used by b2Distance.
b2Vec2 GetSearchDirection() const
void b2Distance(b2DistanceOutput *output, b2SimplexCache *cache, const b2DistanceInput *input)
float metric
length or area