diff options
author | Valerio Virgillito | 2012-02-09 11:57:35 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-09 11:57:35 -0800 |
commit | ce81a3f4387d80f9ac406e73b843fb5dbe9cf432 (patch) | |
tree | 292934c613d7d6952cddac618a7db13a04c48bb3 /js/helper-classes/3D | |
parent | e78f4312c194d9e8188075cf1fe87e4be22b24e4 (diff) | |
parent | fba39dbb3bd64eddf6162fbf57232089e446fb06 (diff) | |
download | ninja-ce81a3f4387d80f9ac406e73b843fb5dbe9cf432.tar.gz |
Merge pull request #26 from pushkarjoshi/pentool
Pentool
Diffstat (limited to 'js/helper-classes/3D')
-rw-r--r-- | js/helper-classes/3D/math-utils.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 71ed62a0..3d24f76e 100644 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js | |||
@@ -802,19 +802,21 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { | |||
802 | getAxisAngleBetween3DVectors: { | 802 | getAxisAngleBetween3DVectors: { |
803 | value: function (vec1, vec2, axis) { | 803 | value: function (vec1, vec2, axis) { |
804 | //compute magnitudes of the vectors | 804 | //compute magnitudes of the vectors |
805 | var mag1 = VecUtils.vecMag(3, vec1); | 805 | var v1n = VecUtils.vecNormalize(3, vec1, 1.0); |
806 | var mag2 = VecUtils.vecMag(3, vec2); | 806 | var v2n = VecUtils.vecNormalize(3, vec2, 1.0); |
807 | |||
808 | if (mag1 < this.EPSILON || mag2 < this.EPSILON) { | ||
809 | return 0; //if angle 0 is returned nothing from this function should be used | ||
810 | } | ||
811 | //angle between the vectors (acos for now...) | 807 | //angle between the vectors (acos for now...) |
812 | var angle = Math.acos(VecUtils.vecDot(3, vec1, vec2) / (mag1 * mag2)); | 808 | var angle = Math.acos(VecUtils.vecDot(3, v1n, v2n)); |
813 | if (Math.abs(angle) < this.EPSILON) { | 809 | if (Math.abs(angle) < this.EPSILON) { |
814 | return 0; | 810 | return 0; |
815 | } | 811 | } |
812 | //TODO testing...remove this block | ||
813 | console.log("getAxisAngleBetween3DVectors Angle: "+angle); | ||
814 | if (isNaN(angle)){ | ||
815 | console.log("getAxisAngleBetween3DVectors Angle is NaN"); | ||
816 | } | ||
817 | //TODO end testing block | ||
816 | //optionally, if axis is provided, create the axis of rotation as well | 818 | //optionally, if axis is provided, create the axis of rotation as well |
817 | var rotAxis = VecUtils.vecCross(3, vec1, vec2); | 819 | var rotAxis = VecUtils.vecCross(3, v1n, v2n); |
818 | rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); | 820 | rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); |
819 | axis[0] = rotAxis[0]; | 821 | axis[0] = rotAxis[0]; |
820 | axis[1] = rotAxis[1]; | 822 | axis[1] = rotAxis[1]; |