Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
Normalize trackball quartenion
Browse files Browse the repository at this point in the history
  • Loading branch information
renatocf committed May 12, 2015
1 parent fe7cf28 commit 58c0bcc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions App/quaternion.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ Quaternion.prototype.norm = function() {
return dot(this.toVec4(), this.toVec4());
}

/**
* @return Normalized version of this quartenion
*/
Quaternion.prototype.normalize = function() {
return new this.constructor(
this.s/this.norm(),
scalar(1/this.norm(), this.v)
);
}

/**
* Operator q()q^-1
* Use quartenion properties to represent a rotation in IR³
Expand Down
2 changes: 1 addition & 1 deletion App/trackball.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Trackball.prototype.rotation = function(x1, y1, x2, y2, mORq) {
if (N[0] == 0 && N[1] == 0 && N[2] == 0) theta = 0;

if (mORq == 'q') // return a quaternion
return createRotationQuaternionFromAngleAndAxis(theta, N);
return createRotationQuaternionFromAngleAndAxis(theta, N).normalize();
else // return a matrix
return rotate(theta, N);
}
Expand Down

0 comments on commit 58c0bcc

Please sign in to comment.