diff options
author | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-04-04 15:53:29 -0700 |
commit | e721a7c1009f298a1bd8fea583da14535e039880 (patch) | |
tree | 9415f5ba25ad643df678e561719d2708fd3ead5a /js/helper-classes/RDGE/src/core/script/math | |
parent | 8482e23cd9b8c4700b5130f2588e5eb24d376536 (diff) | |
parent | 7249d6377c8897b2f9d8115be99717be971a0981 (diff) | |
download | ninja-e721a7c1009f298a1bd8fea583da14535e039880.tar.gz |
Merge pull request #156 from mayhewinator/WorkingBranch
Namespace and code cleanup for RDGE and related files
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/math')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/mat4.js | 1085 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/quat.js | 237 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec2.js | 229 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec3.js | 423 | ||||
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/math/vec4.js | 315 |
5 files changed, 1141 insertions, 1148 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 fab57732..239c646a 100755 --- a/js/helper-classes/RDGE/src/core/script/math/mat4.js +++ b/js/helper-classes/RDGE/src/core/script/math/mat4.js | |||
@@ -4,17 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | |||
8 | float3 = function() { | ||
9 | data = [3]; | ||
10 | } | ||
11 | |||
12 | float4 = function() { | ||
13 | data = [4]; | ||
14 | } | ||
15 | |||
16 | /** | 7 | /** |
17 | * mat4 = {} | ||
18 | * This library contains functions for operating on 4x4 matrices. Any JS array | 8 | * This library contains functions for operating on 4x4 matrices. Any JS array |
19 | * containing at least 16 numeric components can represent a 4x4 matrix. | 9 | * containing at least 16 numeric components can represent a 4x4 matrix. |
20 | * | 10 | * |
@@ -31,313 +21,314 @@ float4 = function() { | |||
31 | * y0, y1, y2, y3, | 21 | * y0, y1, y2, y3, |
32 | * z0, z1, z2, z3, | 22 | * z0, z1, z2, z3, |
33 | * w0, w1, w2, w3 ]; | 23 | * w0, w1, w2, w3 ]; |
34 | * The translation components of a tranformation matrix would be stored in | 24 | * The translation components of a transformation matrix would be stored in |
35 | * w0, w1, w2, or at indices 12, 13, and 14 of the array, as is consistent | 25 | * w0, w1, w2, or at indices 12, 13, and 14 of the array, as is consistent |
36 | * with opengl. | 26 | * with OpenGL. |
37 | */ | 27 | */ |
38 | mat4 = {} | 28 | // RDGE namespaces |
29 | var RDGE = RDGE || {}; | ||
30 | RDGE.mat4 = {}; | ||
39 | 31 | ||
40 | /** | 32 | /** |
41 | * mat4.string | 33 | * RDGE.mat4.string |
42 | */ | 34 | */ |
43 | mat4.string = function(m) { | 35 | RDGE.mat4.string = function (m) { |
44 | var out = "{ "; | 36 | var out = "{ "; |
45 | out += m[0] + ", " + m[1] + ", " + m[2] + ", " + m[3] + ", "; | 37 | out += m[0] + ", " + m[1] + ", " + m[2] + ", " + m[3] + ", "; |
46 | out += m[4] + ", " + m[5] + ", " + m[6] + ", " + m[7] + ", "; | 38 | out += m[4] + ", " + m[5] + ", " + m[6] + ", " + m[7] + ", "; |
47 | out += m[8] + ", " + m[9] + ", " + m[10] + ", " + m[11] + ", "; | 39 | out += m[8] + ", " + m[9] + ", " + m[10] + ", " + m[11] + ", "; |
48 | out += m[12] + ", " + m[13] + ", " + m[14] + ", " + m[15] + " }"; | 40 | out += m[12] + ", " + m[13] + ", " + m[14] + ", " + m[15] + " }"; |
49 | return out; | 41 | return out; |
50 | } | 42 | }; |
51 | 43 | ||
52 | mat4.toCSSString = function(m, conversionConstant) | 44 | RDGE.mat4.toCSSString = function (m, conversionConstant) { |
53 | { | ||
54 | var cc = 10.0; | 45 | var cc = 10.0; |
55 | 46 | ||
56 | if (conversionConstant) | 47 | if (conversionConstant) |
57 | cc = conversionConstant; | 48 | cc = conversionConstant; |
58 | 49 | ||
59 | var out = "matrix3d("; | 50 | var out = "matrix3d("; |
60 | out += m[0].toFixed(10) + ", " + m[1].toFixed(10) + ", " + m[2].toFixed(10) + ", " + m[3].toFixed(10) + ", "; | 51 | out += m[0].toFixed(10) + ", " + m[1].toFixed(10) + ", " + m[2].toFixed(10) + ", " + m[3].toFixed(10) + ", "; |
61 | out += m[4].toFixed(10) + ", " + m[5].toFixed(10) + ", " + m[6].toFixed(10) + ", " + m[7].toFixed(10) + ", "; | 52 | out += m[4].toFixed(10) + ", " + m[5].toFixed(10) + ", " + m[6].toFixed(10) + ", " + m[7].toFixed(10) + ", "; |
62 | out += m[8].toFixed(10) + ", " + m[9].toFixed(10) + ", " + m[10].toFixed(10) + ", " + m[11].toFixed(10) + ", "; | 53 | out += m[8].toFixed(10) + ", " + m[9].toFixed(10) + ", " + m[10].toFixed(10) + ", " + m[11].toFixed(10) + ", "; |
63 | out += m[12].toFixed(10)*cc + ", " + (600 - m[13].toFixed(10)*cc) + ", " + m[14].toFixed(10)*cc + ", " + m[15].toFixed(10) + ")"; | 54 | out += m[12].toFixed(10) * cc + ", " + (600 - m[13].toFixed(10) * cc) + ", " + m[14].toFixed(10) * cc + ", " + m[15].toFixed(10) + ")"; |
64 | return out; | 55 | return out; |
65 | } | 56 | }; |
66 | 57 | ||
67 | /** | 58 | /** |
68 | * mat4.verify | 59 | * RDGE.mat4.verify |
69 | * This function is provided for debugging purposes only. It is not recommended | 60 | * This function is provided for debugging purposes only. It is not recommended |
70 | * to be used in performance critical areas of the code. | 61 | * to be used in performance critical areas of the code. |
71 | */ | 62 | */ |
72 | mat4.verify = function(m) { | 63 | RDGE.mat4.verify = function (m) { |
73 | if (m == undefined || m.length == undefined || m.length < 16) { | 64 | if (m == undefined || m.length == undefined || m.length < 16) { |
74 | return false; | 65 | return false; |
75 | } | 66 | } |
76 | var i = 16; | 67 | var i = 16; |
77 | while (i--) { | 68 | while (i--) { |
78 | if (typeof (m[i]) != "number") { | 69 | if (typeof (m[i]) != "number") { |
79 | return false; | 70 | return false; |
80 | } | 71 | } |
81 | } | 72 | } |
82 | return true; | 73 | return true; |
83 | } | 74 | }; |
84 | 75 | ||
85 | /** | 76 | /** |
86 | * mat4.copy | 77 | * RDGE.mat4.copy |
87 | */ | 78 | */ |
88 | mat4.copy = function(m) { | 79 | RDGE.mat4.copy = function (m) { |
89 | return [ m[0], m[1], m[2], m[3], | 80 | return [m[0], m[1], m[2], m[3], |
90 | m[4], m[5], m[6], m[7], | 81 | m[4], m[5], m[6], m[7], |
91 | m[8], m[9], m[10], m[11], | 82 | m[8], m[9], m[10], m[11], |
92 | m[12], m[13], m[14], m[15] ]; | 83 | m[12], m[13], m[14], m[15]]; |
93 | } | 84 | }; |
94 | 85 | ||
95 | /** | 86 | /** |
96 | * mat4.inplace_copy | 87 | * RDGE.mat4.inplace_copy |
97 | */ | 88 | */ |
98 | mat4.inplace_copy = function(dst, src) { | 89 | RDGE.mat4.inplace_copy = function (dst, src) { |
99 | dst[0] = src[0]; | 90 | dst[0] = src[0]; |
100 | dst[1] = src[1]; | 91 | dst[1] = src[1]; |
101 | dst[2] = src[2]; | 92 | dst[2] = src[2]; |
102 | dst[3] = src[3]; | 93 | dst[3] = src[3]; |
103 | dst[4] = src[4]; | 94 | dst[4] = src[4]; |
104 | dst[5] = src[5]; | 95 | dst[5] = src[5]; |
105 | dst[6] = src[6]; | 96 | dst[6] = src[6]; |
106 | dst[7] = src[7]; | 97 | dst[7] = src[7]; |
107 | dst[8] = src[8]; | 98 | dst[8] = src[8]; |
108 | dst[9] = src[9]; | 99 | dst[9] = src[9]; |
109 | dst[10] = src[10]; | 100 | dst[10] = src[10]; |
110 | dst[11] = src[11]; | 101 | dst[11] = src[11]; |
111 | dst[12] = src[12]; | 102 | dst[12] = src[12]; |
112 | dst[13] = src[13]; | 103 | dst[13] = src[13]; |
113 | dst[14] = src[14]; | 104 | dst[14] = src[14]; |
114 | dst[15] = src[15]; | 105 | dst[15] = src[15]; |
115 | } | 106 | }; |
116 | 107 | ||
117 | /** | 108 | /** |
118 | * mat4.identity | 109 | * RDGE.mat4.identity |
119 | */ | 110 | */ |
120 | mat4.identity = function() { | 111 | RDGE.mat4.identity = function () { |
121 | return [ 1.0, 0.0, 0.0, 0.0, | 112 | return [1.0, 0.0, 0.0, 0.0, |
122 | 0.0, 1.0, 0.0, 0.0, | 113 | 0.0, 1.0, 0.0, 0.0, |
123 | 0.0, 0.0, 1.0, 0.0, | 114 | 0.0, 0.0, 1.0, 0.0, |
124 | 0.0, 0.0, 0.0, 1.0 ]; | 115 | 0.0, 0.0, 0.0, 1.0]; |
125 | } | 116 | }; |
126 | 117 | ||
127 | /** | 118 | /** |
128 | * mat4.zero | 119 | * RDGE.mat4.zero |
129 | */ | 120 | */ |
130 | mat4.zero = function() { | 121 | RDGE.mat4.zero = function () { |
131 | return [ 0.0, 0.0, 0.0, 0.0, | 122 | return [0.0, 0.0, 0.0, 0.0, |
132 | 0.0, 0.0, 0.0, 0.0, | 123 | 0.0, 0.0, 0.0, 0.0, |
133 | 0.0, 0.0, 0.0, 0.0, | 124 | 0.0, 0.0, 0.0, 0.0, |
134 | 0.0, 0.0, 0.0, 0.0 ]; | 125 | 0.0, 0.0, 0.0, 0.0]; |
135 | } | 126 | }; |
136 | 127 | ||
137 | /** | 128 | /** |
138 | * mat4.basis | 129 | * RDGE.mat4.basis |
139 | * description - construct a matrix with the given basis vectors. | 130 | * description - construct a matrix with the given basis vectors. |
140 | */ | 131 | */ |
141 | mat4.basis = function( rowx, rowy, rowz, roww ) { | 132 | RDGE.mat4.basis = function (rowx, rowy, rowz, roww) { |
142 | if( roww == nul |