Skip to content

Commit

Permalink
Correct rotationAxis for frame and hand, fixes #191
Browse files Browse the repository at this point in the history
  • Loading branch information
pehrlich committed Nov 14, 2014
1 parent 5f9c18c commit 17631ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,14 @@ Frame.prototype.rotationAngle = function(sinceFrame, axis) {
*/
Frame.prototype.rotationAxis = function(sinceFrame) {
if (!this.valid || !sinceFrame.valid) return vec3.create();

var rotation = Leap.mat3.create();
Leap.mat3.multiply(rotation, this._rotation, sinceFrame._rotation);

return vec3.normalize(vec3.create(), [
this._rotation[7] - sinceFrame._rotation[5],
this._rotation[2] - sinceFrame._rotation[6],
this._rotation[3] - sinceFrame._rotation[1]
rotation[7] - rotation[5],
rotation[2] - rotation[6],
rotation[3] - rotation[1]
]);
}

Expand Down
12 changes: 8 additions & 4 deletions lib/hand.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,16 @@ Hand.prototype.rotationAxis = function(sinceFrame) {
if (!this.valid || !sinceFrame.valid) return vec3.create();
var sinceHand = sinceFrame.hand(this.id);
if (!sinceHand.valid) return vec3.create();

var rotation = Leap.mat3.create();
Leap.mat3.multiply(rotation, this._rotation, sinceHand._rotation);

return vec3.normalize(vec3.create(), [
this._rotation[7] - sinceHand._rotation[5],
this._rotation[2] - sinceHand._rotation[6],
this._rotation[3] - sinceHand._rotation[1]
rotation[7] - rotation[5],
rotation[2] - rotation[6],
rotation[3] - rotation[1]
]);
}
};

/**
* The transform matrix expressing the rotation derived from the change in
Expand Down

0 comments on commit 17631ed

Please sign in to comment.