text: module.exports = LockConstraint;
  
  var Constraint = require('./Constraint');
  var PointToPointConstraint = require('./PointToPointConstraint');
  var RotationalEquation = require('../equations/RotationalEquation');
  var RotationalMotorEquation = require('../equations/RotationalMotorEquation');
  var ContactEquation = require('../equations/ContactEquation');
  var Vec3 = require('../math/Vec3');
  
  /**
   * Lock constraint. Will remove all degrees of freedom between the bodies.
   * @class LockConstraint
   * @constructor
   * @author schteppe
   * @param {Body} bodyA
   * @param {Body} bodyB
   * @param {object} [options]
   * @param {Number} [options.maxForce=1e6]
   * @extends PointToPointConstraint
   */
  function LockConstraint(bodyA, bodyB, options){
      options = options || {};
      var maxForce = typeof(options.maxForce) !== 'undefined' ? options.maxForce : 1e6;
  
      // Set pivot point in between
      var pivotA = new Vec3();
      var pivotB = new Vec3();
      var halfWay = new Vec3();
      bodyA.position.vadd(bodyB.position, halfWay);
      halfWay.scale(0.5, halfWay);
      bodyB.pointToLocalFrame(halfWay, pivotB);
      bodyA.pointToLocalFrame(halfWay, pivotA);
  
      // The point-to-point constraint will keep a point shared between the bodies
      PointToPointConstraint.call(this, bodyA, pivotA, bodyB, pivotB, maxForce);
  
      // Store initial rotation of the bodies as unit vectors in the local body spaces
      this.xA = bodyA.vectorToLocalFrame(Vec3.UNIT_X);
      this.xB = bodyB.vectorToLocalFrame(Vec3.UNIT_X);
      this.yA = bodyA.vectorToLocalFrame(Vec3.UNIT_Y);
      this.yB = bodyB.vectorToLocalFrame(Vec3.UNIT_Y);
      this.zA = bodyA.vectorToLocalFrame(Vec3.UNIT_Z);
      this.zB = bodyB.vectorToLocalFrame(Vec3.UNIT_Z);
  
      // ...and the following rotational equations will keep all rotational DOF's in place
  
      /**
       * @property {RotationalEquation} rotationalEquation1
       */
      var r1 = this.rotationalEquation1 = new RotationalEquation(bodyA,bodyB,options);
  
      /**
       * @property {RotationalEquation} rotationalEquation2
       */
      var r2 = this.rotationalEquation2 = new RotationalEquation(bodyA,bodyB,options);
  
      /**
       * @property {RotationalEquation} rotationalEquation3
       */
      var r3 = this.rotationalEquation3 = new RotationalEquation(bodyA,bodyB,options);
  
      this.equations.push(r1, r2, r3);
  }
  LockConstraint.prototype = new PointToPointConstraint();
  LockConstraint.constructor = LockConstraint;
  
  var LockConstraint_update_tmpVec1 = new Vec3();
  var LockConstraint_update_tmpVec2 = new Vec3();
  
  LockConstraint.prototype.update = function(){
      var bodyA = this.bodyA,
          bodyB = this.bodyB,
          motor = this.motorEquation,
          r1 = this.rotationalEquation1,
          r2 = this.rotationalEquation2,
          r3 = this.rotationalEquation3,
          worldAxisA = LockConstraint_update_tmpVec1,
          worldAxisB = LockConstraint_update_tmpVec2;
  
      PointToPointConstraint.prototype.update.call(this);
  
      // These vector pairs must be orthogonal
      bodyA.vectorToWorldFrame(this.xA, r1.axisA);
      bodyB.vectorToWorldFrame(this.yB, r1.axisB);
  
      bodyA.vectorToWorldFrame(this.yA, r2.axisA);
      bodyB.vectorToWorldFrame(this.zB, r2.axisB);
  
      bodyA.vectorToWorldFrame(this.zA, r3.axisA);
      bodyB.vectorToWorldFrame(this.xB, r3.axisB);
  };
  
  