aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes')
-rw-r--r--js/helper-classes/3D/math-utils.js54
1 files changed, 29 insertions, 25 deletions
diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js
index 49c77c41..71ed62a0 100644
--- a/js/helper-classes/3D/math-utils.js
+++ b/js/helper-classes/3D/math-utils.js
@@ -891,36 +891,32 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
891 } 891 }
892 }, 892 },
893 893
894/**
895* decompose matrix in javascript found at https://github.com/joelambert/morf/blob/master/js/src/WebkitCSSMatrix.ext.js
896* used with permission from Joe Lambert: "as long as the original licence text and attribution is left in then you're
897* good to use it as you see fit."
898*
899* WebKitCSSMatrix Extensions
900*
901* Copyright 2011, Joe Lambert (http://www.joelambert.co.uk)
902* Free to use under the MIT license.
903* http://joelambert.mit-license.org/
904*/
905
906/**
907* Decomposes the matrix into its component parts.
908* A Javascript implementation of the pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition
909* @author Joe Lambert
910* @returns {Object} An object with each of the components of the matrix (perspective, translate, skew, scale, rotate) or identity matrix on failure
911*/
912
894// Input: matrix ; a 4x4 matrix 913// Input: matrix ; a 4x4 matrix
895// Output: translation ; a 3 component vector 914// Output: translation ; a 3 component vector
896// rotation ; Euler angles, represented as a 3 component vector 915// rotation ; Euler angles, represented as a 3 component vector
897// scale ; a 3 component vector 916// scale ; a 3 component vector
898// skew ; skew factors XY,XZ,YZ represented as a 3 component vector 917// skew ; skew factors XY,XZ,YZ represented as a 3 component vector
899// perspective ; a 4 component vector 918// perspective ; a 4 component vector
900// Returns false if the matrix cannot be decomposed, an object with the above output values if it can 919// Returns false if the matrix cannot be decomposed. An object with the above output values if it can.
901//
902// Supporting functions (point is a 3 component vector, matrix is a 4x4 matrix):
903// float determinant(matrix) returns the 4x4 determinant of the matrix
904// matrix inverse(matrix) returns the inverse of the passed matrix
905// matrix transpose(matrix) returns the transpose of the passed matrix
906// point multVecMatrix(point, matrix) multiplies the passed point by the passed matrix
907// and returns the transformed point
908// float length(point) returns the length of the passed vector
909// point normalize(point) normalizes the length of the passed point to 1
910// float dot(point, point) returns the dot product of the passed points
911// float cos(float) returns the cosine of the passed angle in radians
912// float asin(float) returns the arcsine in radians of the passed value
913// float atan2(float y, float x) returns the principal value of the arc tangent of
914// y/x, using the signs of both arguments to determine
915// the quadrant of the return value
916//
917// Decomposition also makes use of the following function:
918// point combine(point a, point b, float ascl, float bscl)
919// result[0] = (ascl * a[0]) + (bscl * b[0])
920// result[1] = (ascl * a[1]) + (bscl * b[1])
921// result[2] = (ascl * a[2]) + (bscl * b[2])
922// return result
923//
924 decomposeMatrix2: { 920 decomposeMatrix2: {
925 value: function(m) 921 value: function(m)
926 { 922 {
@@ -1077,7 +1073,6 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
1077 rotate[2] = 0; 1073 rotate[2] = 0;
1078 } 1074 }
1079 1075
1080// return true;
1081 return {translation: translate, 1076 return {translation: translate,
1082 rotation: rotate, 1077 rotation: rotate,
1083 scale: scale, 1078 scale: scale,
@@ -1087,6 +1082,15 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, {
1087 } 1082 }
1088 }, 1083 },
1089 1084
1085/**
1086* Helper function required for matrix decomposition
1087* A Javascript implementation of pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition
1088* @param {Vector4} aPoint A 3D point
1089* @param {float} ascl
1090* @param {float} bscl
1091* @author Joe Lambert
1092* @returns {Vector4}
1093*/
1090 combine: { 1094 combine: {
1091 value: function(a, b, ascl, bscl) 1095 value: function(a, b, ascl, bscl)
1092 { 1096 {