Skip to content

Commit

Permalink
fixed initial orientation bug in LockConstraint
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Apr 24, 2015
1 parent 16c2a8b commit 20b7eee
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/constraints/LockConstraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ function LockConstraint(bodyA, bodyB, options){
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
*/
Expand Down Expand Up @@ -67,13 +79,14 @@ LockConstraint.prototype.update = function(){

PointToPointConstraint.prototype.update.call(this);

bodyA.vectorToWorldFrame(Vec3.UNIT_X, r1.axisA);
bodyB.vectorToWorldFrame(Vec3.UNIT_Y, r1.axisB);
// These vector pairs must be orthogonal
bodyA.vectorToWorldFrame(this.xA, r1.axisA);
bodyB.vectorToWorldFrame(this.yB, r1.axisB);

bodyA.vectorToWorldFrame(Vec3.UNIT_Y, r2.axisA);
bodyB.vectorToWorldFrame(Vec3.UNIT_Z, r2.axisB);
bodyA.vectorToWorldFrame(this.yA, r2.axisA);
bodyB.vectorToWorldFrame(this.zB, r2.axisB);

bodyA.vectorToWorldFrame(Vec3.UNIT_Z, r3.axisA);
bodyB.vectorToWorldFrame(Vec3.UNIT_X, r3.axisB);
bodyA.vectorToWorldFrame(this.zA, r3.axisA);
bodyB.vectorToWorldFrame(this.xB, r3.axisB);
};

0 comments on commit 20b7eee

Please sign in to comment.