diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math/mat4.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/mat4.js | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/math/mat4.js b/js/helper-classes/RDGE/src/core/script/math/mat4.js index 32c7111c..a0f47bcf 100755 --- a/js/helper-classes/RDGE/src/core/script/math/mat4.js +++ b/js/helper-classes/RDGE/src/core/script/math/mat4.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -29,8 +30,8 @@ POSSIBILITY OF SUCH DAMAGE. | |||
29 | </copyright> */ | 30 | </copyright> */ |
30 | 31 | ||
31 | /** | 32 | /** |
32 | * This library contains functions for operating on 4x4 matrices. Any JS array | 33 | * This library contains functions for operating on 4x4 matrices. Any JS array |
33 | * containing at least 16 numeric components can represent a 4x4 matrix. | 34 | * containing at least 16 numeric components can represent a 4x4 matrix. |
34 | * | 35 | * |
35 | * For example, all of these are valid matrix construction methods: | 36 | * For example, all of these are valid matrix construction methods: |
36 | * ... | 37 | * ... |
@@ -39,15 +40,15 @@ POSSIBILITY OF SUCH DAMAGE. | |||
39 | * var c = mat4.lookAt( [0, 0, 0], [1, 0, 0], [ 0, 1, 0 ] ); | 40 | * var c = mat4.lookAt( [0, 0, 0], [1, 0, 0], [ 0, 1, 0 ] ); |
40 | * var d = mat4.basis( [1, 0, 0], [0, 1, 0], [ 0, 0, 1 ] ); | 41 | * var d = mat4.basis( [1, 0, 0], [0, 1, 0], [ 0, 0, 1 ] ); |
41 | * | 42 | * |
42 | * This library is implemented assuming components are arranged | 43 | * This library is implemented assuming components are arranged |
43 | * contiguously in memory as such: | 44 | * contiguously in memory as such: |
44 | * M = [ x0, x1, x2, x3, | 45 | * M = [ x0, x1, x2, x3, |
45 | * y0, y1, y2, y3, | 46 | * y0, y1, y2, y3, |
46 | * z0, z1, z2, z3, | 47 | * z0, z1, z2, z3, |
47 | * w0, w1, w2, w3 ]; | 48 | * w0, w1, w2, w3 ]; |
48 | * The translation components of a transformation matrix would be stored in | 49 | * The translation components of a transformation matrix would be stored in |
49 | * w0, w1, w2, or at indices 12, 13, and 14 of the array, as is consistent | 50 | * w0, w1, w2, or at indices 12, 13, and 14 of the array, as is consistent |
50 | * with OpenGL. | 51 | * with OpenGL. |
51 | */ | 52 | */ |
52 | // RDGE namespaces | 53 | // RDGE namespaces |
53 | var RDGE = RDGE || {}; | 54 | var RDGE = RDGE || {}; |
@@ -81,7 +82,7 @@ RDGE.mat4.toCSSString = function (m, conversionConstant) { | |||
81 | 82 | ||
82 | /** | 83 | /** |
83 | * RDGE.mat4.verify | 84 | * RDGE.mat4.verify |
84 | * This function is provided for debugging purposes only. It is not recommended | 85 | * This function is provided for debugging purposes only. It is not recommended |
85 | * to be used in performance critical areas of the code. | 86 | * to be used in performance critical areas of the code. |
86 | */ | 87 | */ |
87 | RDGE.mat4.verify = function (m) { | 88 | RDGE.mat4.verify = function (m) { |
@@ -231,10 +232,10 @@ RDGE.mat4.angleAxis = function (angle, axis) { | |||
231 | RDGE.mat4.lookAt = function (eye, at, up) { | 232 | RDGE.mat4.lookAt = function (eye, at, up) { |
232 | /* | 233 | /* |
233 | var w_axis = new RDGE.vec3(posVec.x, posVec.y, posVec.z); | 234 | var w_axis = new RDGE.vec3(posVec.x, posVec.y, posVec.z); |
234 | 235 | ||
235 | var z_axis = subVec3(targetVec, w_axis); | 236 | var z_axis = subVec3(targetVec, w_axis); |
236 | z_axis.normalize(); | 237 | z_axis.normalize(); |
237 | 238 | ||
238 | var x_axis = crossVec3(upVec, z_axis); | 239 | var x_axis = crossVec3(upVec, z_axis); |
239 | x_axis.normalize(); | 240 | x_axis.normalize(); |
240 | 241 | ||
@@ -522,7 +523,7 @@ RDGE.mat4._adjoint = function (m) { | |||
522 | */ | 523 | */ |
523 | RDGE.mat4.inverse = function (m) { | 524 | RDGE.mat4.inverse = function (m) { |
524 | // Calculate the 4x4 determinant | 525 | // Calculate the 4x4 determinant |
525 | // If the determinant is zero, | 526 | // If the determinant is zero, |
526 | // then the inverse matrix is not unique. | 527 | // then the inverse matrix is not unique. |
527 | var det = RDGE.mat4._det4x4(m); | 528 | var det = RDGE.mat4._det4x4(m); |
528 | 529 | ||
@@ -580,7 +581,7 @@ RDGE.mat4.transformPoint = function (m, v) { | |||
580 | m[1] * x + m[5] * y + m[9] * z + m[13] * w, | 581 | m[1] * x + m[5] * y + m[9] * z + m[13] * w, |
581 | m[2] * x + m[6] * y + m[10] * z + m[14] * w, | 582 | m[2] * x + m[6] * y + m[10] * z + m[14] * w, |
582 | m[3] * x + m[7] * y + m[11] * z + m[15] * w]; | 583 | m[3] * x + m[7] * y + m[11] * z + m[15] * w]; |
583 | // 12 adds, 16 multiplies, 16 lookups. | 584 | // 12 adds, 16 multiplies, 16 lookups. |
584 | }; | 585 | }; |
585 | 586 | ||
586 | /** | 587 | /** |
@@ -589,7 +590,7 @@ RDGE.mat4.transformPoint = function (m, v) { | |||
589 | RDGE.mat4.transformVector = function (m, v) { | 590 | RDGE.mat4.transformVector = function (m, v) { |
590 | m = RDGE.mat4.inverse(m); | 591 | m = RDGE.mat4.inverse(m); |
591 | var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 0.0; | 592 | var x = v[0], y = v[1], z = v[2], w = v.length >= 4 ? v[3] : 0.0; |
592 | // 12 adds, 16 multiplies, 16 lookups. | 593 | // 12 adds, 16 multiplies, 16 lookups. |
593 | // transpose multiply | 594 | // transpose multiply |
594 | return [m[0] * x + m[1] * y + m[2] * z + m[3] * w, | 595 | return [m[0] * x + m[1] * y + m[2] * z + m[3] * w, |
595 | m[4] * x + m[5] * y + m[6] * z + m[7] * w, | 596 | m[4] * x + m[5] * y + m[6] * z + m[7] * w, |