114 v->
wA =
b2Mul(transformA, wALocal);
115 v->
wB =
b2Mul(transformB, wBLocal);
116 v->
w = v->
wB - v->
wA;
126 if (metric2 < 0.5
f * metric1 || 2.0
f * metric1 < metric2 || metric2 <
b2_epsilon)
141 v->
wA =
b2Mul(transformA, wALocal);
142 v->
wB =
b2Mul(transformB, wBLocal);
143 v->
w = v->
wB - v->
wA;
151 cache->
metric = GetMetric();
170 b2Vec2 e12 = m_v2.w - m_v1.w;
202 return m_v1.a * m_v1.w + m_v2.a * m_v2.w;
227 *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA;
228 *pB = m_v1.a * m_v1.wB + m_v2.a * m_v2.wB;
232 *pA = m_v1.a * m_v1.wA + m_v2.a * m_v2.wA + m_v3.a * m_v3.wA;
257 return b2Cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
324 float32 inv_d12 = 1.0f / (d12_1 + d12_2);
325 m_v1.a = d12_1 * inv_d12;
326 m_v2.a = d12_2 * inv_d12;
379 if (d12_2 <= 0.0
f && d13_2 <= 0.0
f)
387 if (d12_1 > 0.0
f && d12_2 > 0.0
f && d123_3 <= 0.0
f)
389 float32 inv_d12 = 1.0f / (d12_1 + d12_2);
390 m_v1.a = d12_1 * inv_d12;
391 m_v2.a = d12_2 * inv_d12;
397 if (d13_1 > 0.0
f && d13_2 > 0.0
f && d123_2 <= 0.0
f)
399 float32 inv_d13 = 1.0f / (d13_1 + d13_2);
400 m_v1.a = d13_1 * inv_d13;
401 m_v3.a = d13_2 * inv_d13;
408 if (d12_1 <= 0.0
f && d23_2 <= 0.0
f)
417 if (d13_1 <= 0.0
f && d23_1 <= 0.0
f)
426 if (d23_1 > 0.0
f && d23_2 > 0.0
f && d123_1 <= 0.0
f)
428 float32 inv_d23 = 1.0f / (d23_1 + d23_2);
429 m_v2.a = d23_1 * inv_d23;
430 m_v3.a = d23_2 * inv_d23;
437 float32 inv_d123 = 1.0f / (d123_1 + d123_2 + d123_3);
438 m_v1.a = d123_1 * inv_d123;
439 m_v2.a = d123_2 * inv_d123;
440 m_v3.a = d123_3 * inv_d123;
458 simplex.
ReadCache(cache, proxyA, transformA, proxyB, transformB);
462 const int32 k_maxIters = 20;
466 int32 saveA[3], saveB[3];
470 float32 distanceSqr2 = distanceSqr1;
474 while (iter < k_maxIters)
478 for (
int32 i = 0; i < saveCount; ++i)
480 saveA[i] = vertices[i].
indexA;
481 saveB[i] = vertices[i].
indexB;
512 if (distanceSqr2 >= distanceSqr1)
516 distanceSqr1 = distanceSqr2;
540 vertex->
w = vertex->
wB - vertex->
wA;
547 bool duplicate =
false;
548 for (
int32 i = 0; i < saveCount; ++i)
550 if (vertex->
indexA == saveA[i] && vertex->
indexB == saveB[i])
590 output->
pointA += rA * normal;
591 output->
pointB -= rB * normal;
float32 b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
const b2Vec2 b2Vec2_zero(0.0f, 0.0f)
Useful constant.
b2Vec2 b2Mul(const b2Mat22 &A, const b2Vec2 &v)
b2Vec2 * m_vertices
The vertices. Owned by this class.
void Set(const b2Shape *shape, int32 index)
void ReadCache(const b2SimplexCache *cache, const b2DistanceProxy *proxyA, const b2Transform &transformA, const b2DistanceProxy *proxyB, const b2Transform &transformB)
b2Vec2 GetSearchDirection() const
uint8 indexA[3]
vertices on shape A
void GetWitnessPoints(b2Vec2 *pA, b2Vec2 *pB) const
float32 LengthSquared() const
int32 iterations
number of GJK iterations used
b2Vec2 pointB
closest point on shapeB
const b2Vec2 & GetVertex(int32 index) const
Get a vertex by index. Used by b2Distance.
b2Vec2 pointA
closest point on shapeA
float32 b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
b2Vec2 GetClosestPoint() const
b2Vec2 m_vertices[b2_maxPolygonVertices]
int32 GetSupport(const b2Vec2 &d) const
Get the supporting vertex index in the given direction.
float32 GetMetric() const
const b2Vec2 * m_vertices
void WriteCache(b2SimplexCache *cache) const
b2Vec2 b2MulT(const b2Mat22 &A, const b2Vec2 &v)
float32 metric
length or area
uint8 indexB[3]
vertices on shape B
void b2Distance(b2DistanceOutput *output, b2SimplexCache *cache, const b2DistanceInput *input)
b2Vec2 m_vertex1
These are the edge vertices.
int32 m_count
The vertex count.
float32 Normalize()
Convert this vector into a unit vector. Returns the length.