diff --git a/App/quaternion.js b/App/quaternion.js index 23d9b10..e068a67 100644 --- a/App/quaternion.js +++ b/App/quaternion.js @@ -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Ā³ diff --git a/App/trackball.js b/App/trackball.js index 4632c29..6fb34a1 100644 --- a/App/trackball.js +++ b/App/trackball.js @@ -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); }