diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/3D | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/helper-classes/3D')
-rw-r--r-- | js/helper-classes/3D/GLMatrix/gl-matrix.js | 1842 | ||||
-rw-r--r-- | js/helper-classes/3D/GLMatrix/notice.txt | 4 | ||||
-rw-r--r-- | js/helper-classes/3D/LinePlaneIntersectRec.js | 60 | ||||
-rw-r--r-- | js/helper-classes/3D/ParseUtils.js | 84 | ||||
-rw-r--r-- | js/helper-classes/3D/Rectangle.js | 209 | ||||
-rw-r--r-- | js/helper-classes/3D/StageLine.js | 461 | ||||
-rw-r--r-- | js/helper-classes/3D/draw-utils.js | 1208 | ||||
-rw-r--r-- | js/helper-classes/3D/element-planes.js | 134 | ||||
-rw-r--r-- | js/helper-classes/3D/glUtils.js | 319 | ||||
-rw-r--r-- | js/helper-classes/3D/hit-record.js | 291 | ||||
-rw-r--r-- | js/helper-classes/3D/math-utils.js | 1104 | ||||
-rw-r--r-- | js/helper-classes/3D/snap-2d-record.js | 130 | ||||
-rw-r--r-- | js/helper-classes/3D/snap-manager.js | 2247 | ||||
-rw-r--r-- | js/helper-classes/3D/vec-utils.js | 199 | ||||
-rw-r--r-- | js/helper-classes/3D/view-utils.js | 1342 |
15 files changed, 9634 insertions, 0 deletions
diff --git a/js/helper-classes/3D/GLMatrix/gl-matrix.js b/js/helper-classes/3D/GLMatrix/gl-matrix.js new file mode 100644 index 00000000..811ed5cd --- /dev/null +++ b/js/helper-classes/3D/GLMatrix/gl-matrix.js | |||
@@ -0,0 +1,1842 @@ | |||
1 | /* | ||
2 | * gl-matrix.js - High performance matrix and vector operations for WebGL | ||
3 | * Version 1.0.0 | ||
4 | */ | ||
5 | |||
6 | /* | ||
7 | * Copyright (c) 2011 Brandon Jones | ||
8 | * | ||
9 | * This software is provided 'as-is', without any express or implied | ||
10 | * warranty. In no event will the authors be held liable for any damages | ||
11 | * arising from the use of this software. | ||
12 | * | ||
13 | * Permission is granted to anyone to use this software for any purpose, | ||
14 | * including commercial applications, and to alter it and redistribute it | ||
15 | * freely, subject to the following restrictions: | ||
16 | * | ||
17 | * 1. The origin of this software must not be misrepresented; you must not | ||
18 | * claim that you wrote the original software. If you use this software | ||
19 | * in a product, an acknowledgment in the product documentation would be | ||
20 | * appreciated but is not required. | ||
21 | * | ||
22 | * 2. Altered source versions must be plainly marked as such, and must not | ||
23 | * be misrepresented as being the original software. | ||
24 | * | ||
25 | * 3. This notice may not be removed or altered from any source | ||
26 | * distribution. | ||
27 | */ | ||
28 | |||
29 | "use strict"; | ||
30 | |||
31 | // Type declarations | ||
32 | var MatrixArray = (typeof Float32Array !== 'undefined') ? Float32Array : Array, // Fallback for systems that don't support TypedArrays | ||
33 | glMatrixArrayType = MatrixArray, // For Backwards compatibility | ||
34 | vec3 = {}, | ||
35 | mat3 = {}, | ||
36 | glmat4 = {}, | ||
37 | quat4 = {}; | ||
38 | |||
39 | |||
40 | /* | ||
41 | * vec3 - 3 Dimensional Vector | ||
42 | */ | ||
43 | |||
44 | /* | ||
45 | * vec3.create | ||
46 | * Creates a new instance of a vec3 using the default array type | ||
47 | * Any javascript array containing at least 3 numeric elements can serve as a vec3 | ||
48 | * | ||
49 | * Params: | ||
50 | * vec - Optional, vec3 containing values to initialize with | ||
51 | * | ||
52 | * Returns: | ||
53 | * New vec3 | ||
54 | */ | ||
55 | vec3.create = function (vec) { | ||
56 | var dest = new MatrixArray(3); | ||
57 | |||
58 | if (vec) { | ||
59 | dest[0] = vec[0]; | ||
60 | dest[1] = vec[1]; | ||
61 | dest[2] = vec[2]; | ||
62 | } | ||
63 | |||
64 | return dest; | ||
65 | }; | ||
66 | |||
67 | /* | ||
68 | * vec3.set | ||
69 | * Copies the values of one vec3 to another | ||
70 | * | ||
71 | * Params: | ||
72 | * vec - vec3 containing values to copy | ||
73 | * dest - vec3 receiving copied values | ||
74 | * | ||
75 | * Returns: | ||
76 | * dest | ||
77 | */ | ||
78 | vec3.set = function (vec, dest) { | ||
79 | dest[0] = vec[0]; | ||
80 | dest[1] = vec[1]; | ||
81 | dest[2] = vec[2]; | ||
82 | |||
83 | return dest; | ||
84 | }; | ||
85 | |||
86 | /* | ||
87 | * vec3.add | ||
88 | * Performs a vector addition | ||
89 | * | ||
90 | * Params: | ||
91 | * vec - vec3, first operand | ||
92 | * vec2 - vec3, second operand | ||
93 | * dest - Optional, vec3 receiving operation result. If not specified result is written to vec | ||
94 | * | ||
95 | * Returns: | ||
96 | * dest if specified, vec otherwise | ||
97 | */ | ||
98 | vec3.add = function (vec, vec2, dest) { | ||
99 | if (!dest || vec === dest) { | ||
100 | vec[0] += vec2[0]; | ||
101 | vec[1] += vec2[1]; | ||
102 | vec[2] += vec2[2]; | ||
103 | return vec; | ||
104 | } | ||
105 | |||
106 | dest[0] = vec[0] + vec2[0]; | ||
107 | dest[1] = vec[1] + vec2[1]; | ||
108 | dest[2] = vec[2] + vec2[2]; | ||
109 | return dest; | ||
110 | }; | ||
111 | |||
112 | /* | ||
113 | * vec3.subtract | ||
114 | * Performs a vector subtraction | ||
115 | * | ||
116 | * Params: | ||
117 | * vec - vec3, first operand | ||
118 | * vec2 - vec3, second operand | ||
119 | * dest - Optional, vec3 receiving operation result. If not specified result is written to vec | ||
120 | * | ||
121 | * Returns: | ||
122 | * dest if specified, vec otherwise | ||
123 | */ | ||
124 | vec3.subtract = function (vec, vec2, dest) { | ||
125 | if (!dest || vec === dest) { | ||
126 | vec[0] -= vec2[0]; | ||
127 | vec[1] -= vec2[1]; | ||
128 | vec[2] -= vec2[2]; | ||
129 | return vec; | ||
130 | } | ||
131 | |||
132 | dest[0] = vec[0] - vec2[0]; | ||
133 | dest[1] = vec[1] - vec2[1]; | ||
134 | dest[2] = vec[2] - vec2[2]; | ||
135 | return dest; | ||
136 | }; | ||
137 | |||
138 | /* | ||
139 | * vec3.negate | ||
140 | * Negates the components of a vec3 | ||
141 | * | ||
142 | * Params: | ||
143 | * vec - vec3 to negate | ||
144 | * dest - Optional, vec3 receiving operation result. If not specified result is written to vec | ||
145 | * | ||
146 | * Returns: | ||
147 | * dest if specified, vec otherwise | ||
148 | */ | ||
149 | vec3.negate = function (vec, dest) { | ||
150 | if (!dest) { dest = vec; } | ||
151 | |||
152 | dest[0] = -vec[0]; | ||
153 | dest[1] = -vec[1]; | ||
154 | dest[2] = -vec[2]; | ||
155 | return dest; | ||
156 | }; | ||
157 | |||
158 | /* | ||
159 | * vec3.scale | ||
160 | * Multiplies the components of a vec3 by a scalar value | ||
161 | * | ||
162 | * Params: | ||
163 | * vec - vec3 to scale | ||
164 | * val - Numeric value to scale by | ||
165 | * dest - Optional, vec3 receiving operation result. If not specified result is written to vec | ||
166 | * | ||
167 | * Returns: | ||
168 | * dest if specified, vec otherwise | ||
169 | */ | ||
170 | vec3.scale = function (vec, val, dest) { | ||
171 | if (!dest || vec === dest) { | ||
172 | vec[0] *= val; | ||
173 | vec[1] *= val; | ||
174 | vec[2] *= val; | ||
175 | return vec; | ||
176 | } | ||
177 | |||
178 | dest[0] = vec[0] * val; | ||
179 | dest[1] = vec[1] * val; | ||
180 | dest[2] = vec[2] * val; | ||
181 | return dest; | ||
182 | }; | ||
183 | |||
184 | /* | ||
185 | * vec3.normalize | ||
186 | * Generates a unit vector of the same direction as the provided vec3 | ||
187 | * If vector length is 0, returns [0, 0, 0] | ||
188 | * | ||
189 | * Params: | ||
190 | * vec - vec3 to normalize | ||
191 | * dest - Optional, vec3 receiving operation result. If not specified result is written to vec | ||
192 | * | ||
193 | * Returns: | ||
194 | * dest if specified, vec otherwise | ||
195 | */ | ||
196 | vec3.normalize = function (vec, dest) { | ||
197 | if (!dest) { dest = vec; } | ||
198 | |||
199 | var x = vec[0], y = vec[1], z = vec[2], | ||
200 | len = Math.sqrt(x * x + y * y + z * z); | ||
201 | |||
202 | if (!len) { | ||
203 | dest[0] = 0; | ||
204 | dest[1] = 0; | ||
205 | dest[2] = 0; | ||
206 | return dest; | ||
207 | } else if (len === 1) { | ||
208 | dest[0] = x; | ||
209 | dest[1] = y; | ||
210 | dest[2] = z; | ||
211 | return dest; | ||