aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/vec-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/3D/vec-utils.js')
-rwxr-xr-xjs/helper-classes/3D/vec-utils.js169
1 files changed, 85 insertions, 84 deletions
diff --git a/js/helper-classes/3D/vec-utils.js b/js/helper-classes/3D/vec-utils.js
index 79b9f965..10d0f00d 100755
--- a/js/helper-classes/3D/vec-utils.js
+++ b/js/helper-classes/3D/vec-utils.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, 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
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -82,7 +83,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
82 } 83 }
83 }, 84 },
84 85
85 vecAdd: { 86 vecAdd: {
86 value: function( dimen, a, b ) { 87 value: function( dimen, a, b ) {
87 88
88 var rtnVec; 89 var rtnVec;
@@ -100,7 +101,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
100 }, 101 },
101 102
102 103
103 vecSubtract : { 104 vecSubtract : {
104 value: function( dimen, a, b ) { 105 value: function( dimen, a, b ) {
105 var rtnVec; 106 var rtnVec;
106 if ((a.length < dimen) || (b.length < dimen)) 107 if ((a.length < dimen) || (b.length < dimen))
@@ -116,7 +117,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
116 } 117 }
117 }, 118 },
118 119
119 vecDist : { 120 vecDist : {
120 value: function( dimen, a, b ) { 121 value: function( dimen, a, b ) {
121 var sum; 122 var sum;
122 123
@@ -194,7 +195,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
194 }, 195 },
195 196
196 197
197 vecInterpolate: { 198 vecInterpolate: {
198 value: function( dimen, a, b, t ) { 199 value: function( dimen, a, b, t ) {
199 if ((a.length < dimen) || (b.length < dimen)) 200 if ((a.length < dimen) || (b.length < dimen))
200 { 201 {
@@ -209,7 +210,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
209 } 210 }
210 }, 211 },
211 212
212 vecMag: { 213 vecMag: {
213 value: function( dimen, vec ) { 214 value: function( dimen, vec ) {
214 var sum = 0.0; 215 var sum = 0.0;
215 for (var i=0; i<dimen; i++) 216 for (var i=0; i<dimen; i++)
@@ -227,7 +228,7 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
227 } 228 }
228 }, 229 },
229 230
230 vecScale: { 231 vecScale: {
231 value: function(dimen, vec, scale) { 232 value: function(dimen, vec, scale) {
232 for (var i=0; i<dimen; i++) 233 for (var i=0; i<dimen; i++)
233 vec[i] *= scale; 234 vec[i] *= scale;
@@ -236,72 +237,72 @@ var VecUtils = exports.VecUtils = Object.create(Object.prototype,
236 } 237 }
237 }, 238 },
238 239
239 matI : 240 matI :
240 { 241 {
241 value: function(dimen) 242 value: function(dimen)
242 { 243 {
243 var mat = []; 244 var mat = [];
244 for (var i=0; i<dimen*dimen; i++) mat.push(0); 245 for (var i=0; i<dimen*dimen; i++) mat.push(0);
245 246
246 var index = 0; 247 var index = 0;
247 for (var i=0; i<dimen; i++) 248 for (var i=0; i<dimen; i++)
248 { 249 {
249 mat[index] = 1.0; 250 mat[index] = 1.0;
250 index += dimen + 1; 251 index += dimen + 1;
251 } 252 }
252 253
253 return mat; 254 return mat;
254 } 255 }
255 }, 256 },
256 257
257 matTranslation: 258 matTranslation:
258 { 259 {
259 value: function (vec) 260 value: function (vec)
260 { 261 {
261 var mat = Matrix.I(4); 262 var mat = Matrix.I(4);
262 glmat4.translate(mat, vec); 263 glmat4.translate(mat, vec);
263 return mat; 264 return mat;
264 } 265 }
265 }, 266 },
266 267
267 matRotationX: 268 matRotationX:
268 { 269 {
269 value: function( angle ) 270 value: function( angle )
270 { 271 {
271 var mat = Matrix.I(4); 272 var mat = Matrix.I(4);
272 glmat4.rotateX(mat, angle); 273 glmat4.rotateX(mat, angle);
273 return mat; 274 return mat;
274 } 275 }
275 }, 276 },
276 277
277 matRotationY: 278 matRotationY:
278 { 279 {
279 value: function( angle ) 280 value: function( angle )
280 { 281 {
281 var mat = Matrix.I(4); 282 var mat = Matrix.I(4);
282 glmat4.rotateY(mat, angle); 283 glmat4.rotateY(mat, angle);
283 return mat; 284 return mat;
284 } 285 }
285 }, 286 },
286 287
287 matRotationZ: 288 matRotationZ:
288 { 289 {
289 value: function( angle ) 290 value: function( angle )
290 { 291 {
291 var mat = Matrix.I(4); 292 var mat = Matrix.I(4);
292 glmat4.rotateZ(mat, angle); 293 glmat4.rotateZ(mat, angle);
293 return mat; 294 return mat;
294 } 295 }
295 }, 296 },
296 297
297 matRotation: 298 matRotation:
298 { 299 {
299 value: function(angle, axis) 300 value: function(angle, axis)
300 { 301 {
301 var mat = Matrix.I(4); 302 var mat = Matrix.I(4);
302 glmat4.rotate(mat, angle, axis); 303 glmat4.rotate(mat, angle, axis);
303 return mat; 304 return mat;
304 } 305 }
305 } 306 }
306 307
307}); 308});