Skip to content

Commit

Permalink
Issue 487
Browse files Browse the repository at this point in the history
Fixed anchor A formula to include the offset. This fixes the non-physical behavior.
  • Loading branch information
erincatto committed May 20, 2018
1 parent ff2fa5c commit 33af62e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Box2D/Box2D/Dynamics/Joints/b2MotorJoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
// J = [-I -r1_skew I r2_skew ]
// Identity used:
// w k % (rx i + ry j) = w * (-ry i + rx j)
//
// r1 = offset - c1
// r2 = -c2

// Angle constraint
// Cdot = w2 - w1
Expand Down Expand Up @@ -82,21 +85,23 @@ void b2MotorJoint::InitVelocityConstraints(const b2SolverData& data)
b2Rot qA(aA), qB(aB);

// Compute the effective mass matrix.
m_rA = b2Mul(qA, -m_localCenterA);
m_rA = b2Mul(qA, m_linearOffset - m_localCenterA);
m_rB = b2Mul(qB, -m_localCenterB);

// J = [-I -r1_skew I r2_skew]
// [ 0 -1 0 1]
// r_skew = [-ry; rx]

// Matlab
// K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
// [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
// [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]



float32 mA = m_invMassA, mB = m_invMassB;
float32 iA = m_invIA, iB = m_invIB;

// Upper 2 by 2 of K for point to point
b2Mat22 K;
K.ex.x = mA + mB + iA * m_rA.y * m_rA.y + iB * m_rB.y * m_rB.y;
K.ex.y = -iA * m_rA.x * m_rA.y - iB * m_rB.x * m_rB.y;
Expand All @@ -111,7 +116,7 @@ void b2MotorJoint::InitVelocityConstraints(const b2SolverData& data)
m_angularMass = 1.0f / m_angularMass;
}

m_linearError = cB + m_rB - cA - m_rA - b2Mul(qA, m_linearOffset);
m_linearError = cB + m_rB - cA - m_rA;
m_angularError = aB - aA - m_angularOffset;

if (data.step.warmStarting)
Expand Down

0 comments on commit 33af62e

Please sign in to comment.