32 #define B2_DEBUG_SOLVER 0 63 for (
int32 i = 0; i < m_count; ++i)
117 if (m_step.warmStarting)
141 m_allocator->Free(m_velocityConstraints);
142 m_allocator->Free(m_positionConstraints);
148 for (
int32 i = 0; i < m_count; ++i)
162 float iA = vc->
invIA;
163 float iB = vc->
invIB;
168 float aA = m_positions[
indexA].a;
170 float wA = m_velocities[
indexA].w;
173 float aB = m_positions[
indexB].a;
175 float wB = m_velocities[
indexB].w;
182 xfA.
p = cA -
b2Mul(xfA.
q, localCenterA);
183 xfB.
p = cB -
b2Mul(xfB.
q, localCenterB);
186 worldManifold.
Initialize(manifold, xfA, radiusA, xfB, radiusB);
195 vcp->
rA = worldManifold.
points[j] - cA;
196 vcp->
rB = worldManifold.
points[j] - cB;
201 float kNormal = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
203 vcp->
normalMass = kNormal > 0.0f ? 1.0f / kNormal : 0.0f;
210 float kTangent = mA + mB + iA * rtA * rtA + iB * rtB * rtB;
212 vcp->
tangentMass = kTangent > 0.0f ? 1.0f / kTangent : 0.0f;
217 if (vRel < -vc->threshold)
234 float k11 = mA + mB + iA * rn1A * rn1A + iB * rn1B * rn1B;
235 float k22 = mA + mB + iA * rn2A * rn2A + iB * rn2B * rn2B;
236 float k12 = mA + mB + iA * rn1A * rn2A + iB * rn1B * rn2B;
239 const float k_maxConditionNumber = 1000.0f;
240 if (k11 * k11 < k_maxConditionNumber * (k11 * k22 - k12 * k12))
260 for (
int32 i = 0; i < m_count; ++i)
267 float iA = vc->
invIA;
269 float iB = vc->
invIB;
273 float wA = m_velocities[
indexA].w;
275 float wB = m_velocities[
indexB].w;
290 m_velocities[
indexA].v = vA;
291 m_velocities[
indexA].w = wA;
292 m_velocities[
indexB].v = vB;
293 m_velocities[
indexB].w = wB;
299 for (
int32 i = 0; i < m_count; ++i)
306 float iA = vc->
invIA;
308 float iB = vc->
invIB;
312 float wA = m_velocities[
indexA].w;
314 float wB = m_velocities[
indexB].w;
320 b2Assert(pointCount == 1 || pointCount == 2);
342 b2Vec2 P = lambda * tangent;
362 float vn =
b2Dot(dv, normal);
371 b2Vec2 P = lambda * normal;
425 float vn1 =
b2Dot(dv1, normal);
426 float vn2 =
b2Dot(dv2, normal);
435 const float k_errorTol = 1e-3
f;
451 if (x.
x >= 0.0f && x.
y >= 0.0f)
459 vA -= mA * (P1 + P2);
462 vB += mB * (P1 + P2);
469 #if B2_DEBUG_SOLVER == 1 475 vn1 =
b2Dot(dv1, normal);
476 vn2 =
b2Dot(dv2, normal);
493 vn2 = vc->
K.
ex.
y * x.
x + b.
y;
494 if (x.
x >= 0.0f && vn2 >= 0.0f)
502 vA -= mA * (P1 + P2);
505 vB += mB * (P1 + P2);
512 #if B2_DEBUG_SOLVER == 1 517 vn1 =
b2Dot(dv1, normal);
533 vn1 = vc->
K.
ey.
x * x.
y + b.
x;
536 if (x.
y >= 0.0f && vn1 >= 0.0f)
544 vA -= mA * (P1 + P2);
547 vB += mB * (P1 + P2);
554 #if B2_DEBUG_SOLVER == 1 559 vn2 =
b2Dot(dv2, normal);
576 if (vn1 >= 0.0f && vn2 >= 0.0f )
584 vA -= mA * (P1 + P2);
587 vB += mB * (P1 + P2);
602 m_velocities[
indexA].v = vA;
603 m_velocities[
indexA].w = wA;
604 m_velocities[
indexB].v = vB;
605 m_velocities[
indexB].w = wB;
611 for (
int32 i = 0; i < m_count; ++i)
636 normal = pointB - pointA;
638 point = 0.5f * (pointA + pointB);
678 float minSeparation = 0.0f;
680 for (
int32 i = 0; i < m_count; ++i)
688 float iA = pc->
invIA;
691 float iB = pc->
invIB;
695 float aA = m_positions[
indexA].a;
698 float aB = m_positions[
indexB].a;
706 xfA.
p = cA -
b2Mul(xfA.
q, localCenterA);
707 xfB.
p = cB -
b2Mul(xfB.
q, localCenterB);
720 minSeparation =
b2Min(minSeparation, separation);
726 float rnA =
b2Cross(rA, normal);
727 float rnB =
b2Cross(rB, normal);
728 float K = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
731 float impulse = K > 0.0f ? - C / K : 0.0f;
733 b2Vec2 P = impulse * normal;
742 m_positions[
indexA].c = cA;
743 m_positions[
indexA].a = aA;
745 m_positions[
indexB].c = cB;
746 m_positions[
indexB].a = aB;
757 float minSeparation = 0.0f;
759 for (
int32 i = 0; i < m_count; ++i)
771 if (indexA == toiIndexA || indexA == toiIndexB)
779 if (indexB == toiIndexA || indexB == toiIndexB)
786 float aA = m_positions[
indexA].a;
789 float aB = m_positions[
indexB].a;
797 xfA.
p = cA -
b2Mul(xfA.
q, localCenterA);
798 xfB.
p = cB -
b2Mul(xfB.
q, localCenterB);
811 minSeparation =
b2Min(minSeparation, separation);
817 float rnA =
b2Cross(rA, normal);
818 float rnB =
b2Cross(rB, normal);
819 float K = mA + mB + iA * rnA * rnA + iB * rnB * rnB;
822 float impulse = K > 0.0f ? - C / K : 0.0f;
824 b2Vec2 P = impulse * normal;
833 m_positions[
indexA].c = cA;
834 m_positions[
indexA].a = aA;
836 m_positions[
indexB].c = cB;
837 m_positions[
indexB].a = aB;
void Initialize(const b2Manifold *manifold, const b2Transform &xfA, float radiusA, const b2Transform &xfB, float radiusB)
b2Vec2 b2Mul(const b2Mat22 &A, const b2Vec2 &v)
float b2Dot(const b2Vec2 &a, const b2Vec2 &b)
Perform the dot product on two vectors.
b2Vec2 localNormal
not use for Type::e_points
b2Vec2 points[b2_maxManifoldPoints]
world contact point (point of intersection)
void SetZero()
Set this matrix to all zeros.
b2Vec2 normal
world vector pointing from A to B
#define b2_maxManifoldPoints
void SetZero()
Set this vector to all zeros.
b2Vec2 localCenter
local center of mass position
void Initialize(b2ContactPositionConstraint *pc, const b2Transform &xfA, const b2Transform &xfB, int32 index)
A rigid body. These are created via b2World::CreateBody.
b2Mat22 GetInverse() const
#define b2_maxLinearCorrection
float tangentImpulse
the friction impulse
void Set(float x_, float y_)
Set this vector to some specified coordinates.
float b2Cross(const b2Vec2 &a, const b2Vec2 &b)
Perform the cross product on two vectors. In 2D this produces a scalar.
int32 pointCount
the number of manifold points
b2Vec2 localPoint
usage depends on manifold type
T b2Clamp(T a, T low, T high)
float normalImpulse
the non-penetration impulse
b2Vec2 localPoint
usage depends on manifold type
b2ManifoldPoint points[b2_maxManifoldPoints]
the points of contact
float Normalize()
Convert this vector into a unit vector. Returns the length.
void Set(float angle)
Set using an angle in radians.
This is used to compute the current state of a contact manifold.