lib/joint/MotorJoint.js
function MotorJoint(def, bodyA, bodyB) {
  if (!(this instanceof MotorJoint)) {
    return new MotorJoint(def, bodyA, bodyB);
  }

  def = options(def, DEFAULTS);
  Joint.call(this, def, bodyA, bodyB);
  bodyA = this.m_bodyA;
  bodyB = this.m_bodyB;

  this.m_type = MotorJoint.TYPE;

  this.m_linearOffset = def.linearOffset ? def.linearOffset : bodyA.getLocalPoint(bodyB.getPosition());

  var angleA = bodyA.getAngle();
  var angleB = bodyB.getAngle();
  this.m_angularOffset = angleB - angleA;

  this.m_linearImpulse = Vec2.zero();
  this.m_angularImpulse = 0.0;

  this.m_maxForce = def.maxForce;
  this.m_maxTorque = def.maxTorque;
  this.m_correctionFactor = def.correctionFactor;

  // Solver temp
  this.m_rA; // Vec2
  this.m_rB; // Vec2
  this.m_localCenterA; // Vec2
  this.m_localCenterB; // Vec2
  this.m_linearError; // Vec2
  this.m_angularError; // float
  this.m_invMassA; // float
  this.m_invMassB; // float
  this.m_invIA; // float
  this.m_invIB; // float
  this.m_linearMass; // Mat22
  this.m_angularMass; // float

  // Point-to-point constraint
  // Cdot = v2 - v1
  // = v2 + cross(w2, r2) - v1 - cross(w1, r1)
  // J = [-I -r1_skew I r2_skew ]
  // Identity used:
  // w k % (rx i + ry j) = w * (-ry i + rx j)

  // Angle constraint
  // Cdot = w2 - w1
  // J = [0 0 -1 0 0 1]
  // K = invI1 + invI2
}
function MotorJoint(def, bodyA, bodyB) {
  if (!(this instanceof MotorJoint)) {
    return new MotorJoint(def, bodyA, bodyB);
  }

  def = options(def, DEFAULTS);
  Joint.call(this, def, bodyA, bodyB);
  bodyA = this.m_bodyA;
  bodyB = this.m_bodyB;

  this.m_type = MotorJoint.TYPE;

  this.m_linearOffset = def.linearOffset ? def.linearOffset : bodyA.getLocalPoint(bodyB.getPosition());

  var angleA = bodyA.getAngle();
  var angleB = bodyB.getAngle();
  this.m_angularOffset = angleB - angleA;

  this.m_linearImpulse = Vec2.zero();
  this.m_angularImpulse = 0.0;

  this.m_maxForce = def.maxForce;
  this.m_maxTorque = def.maxTorque;
  this.m_correctionFactor = def.correctionFactor;

  // Solver temp
  this.m_rA; // Vec2
  this.m_rB; // Vec2
  this.m_localCenterA; // Vec2
  this.m_localCenterB; // Vec2
  this.m_linearError; // Vec2
  this.m_angularError; // float
  this.m_invMassA; // float
  this.m_invMassB; // float
  this.m_invIA; // float
  this.m_invIB; // float
  this.m_linearMass; // Mat22
  this.m_angularMass; // float

  // Point-to-point constraint
  // Cdot = v2 - v1
  // = v2 + cross(w2, r2) - v1 - cross(w1, r1)
  // J = [-I -r1_skew I r2_skew ]
  // Identity used:
  // w k % (rx i + ry j) = w * (-ry i + rx j)

  // Angle constraint
  // Cdot = w2 - w1
  // J = [0 0 -1 0 0 1]
  // K = invI1 + invI2
}
function MotorJoint ( def , bodyA , bodyB ) { if ( ! ( this instanceof MotorJoint ) ) { return new MotorJoint ( def , bodyA , bodyB ) ; } def = options ( def , DEFAULTS ) ; Joint . call ( this , def , bodyA , bodyB ) ; bodyA = this . m_bodyA ; bodyB = this . m_bodyB ; this . m_type = MotorJoint . TYPE ; this . m_linearOffset = def . linearOffset ? def . linearOffset : bodyA . getLocalPoint ( bodyB . getPosition ( ) ) ; var angleA = bodyA . getAngle ( ) ; var angleB = bodyB . getAngle ( ) ; this . m_angularOffset = angleB - angleA ; this . m_linearImpulse = Vec2 . zero ( ) ; this . m_angularImpulse = 0.0 ; this . m_maxForce = def . maxForce ; this . m_maxTorque = def . maxTorque ; this . m_correctionFactor = def . correctionFactor ; // Solver temp this . m_rA ; // Vec2 this . m_rB ; // Vec2 this . m_localCenterA ; // Vec2 this . m_localCenterB ; // Vec2 this . m_linearError ; // Vec2 this . m_angularError ; // float this . m_invMassA ; // float this . m_invMassB ; // float this . m_invIA ; // float this . m_invIB ; // float this . m_linearMass ; // Mat22 this . m_angularMass ; // float // Point-to-point constraint // Cdot = v2 - v1 // = v2 + cross(w2, r2) - v1 - cross(w1, r1) // J = [-I -r1_skew I r2_skew ] // Identity used: // w k % (rx i + ry j) = w * (-ry i + rx j) // Angle constraint // Cdot = w2 - w1 // J = [0 0 -1 0 0 1] // K = invI1 + invI2 }
A motor joint is used to control the relative motion between two bodies. A
typical usage is to control the movement of a dynamic body with respect to
the ground.

@param {MotorJointDef} def
@param {Body} bodyA
@param {Body} bodyB
A motor joint is used to control the relative motion between two bodies . A typical usage is to control the movement of a dynamic body with respect to the ground .