diff options
author | Jose Antonio Marquez | 2012-02-09 12:09:09 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-09 12:09:09 -0800 |
commit | 44c65bc6bbd5b754f9073f93a3afca8dd9acc864 (patch) | |
tree | 0e9ac4c8b2f8ce3246739ab06053e9986e8c9b51 /js/helper-classes/3D | |
parent | d7e198f5a95011679fa2c536780edbdc533a4893 (diff) | |
parent | ce81a3f4387d80f9ac406e73b843fb5dbe9cf432 (diff) | |
download | ninja-44c65bc6bbd5b754f9073f93a3afca8dd9acc864.tar.gz |
Merge branch 'refs/heads/NinjaInternal' into FileIO
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-x | 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 100755 --- 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]; |