gl-matrix-rails 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module GLMatrix
2
2
  module Version
3
- MAJOR, MINOR, TINY = 0, 1, 1
3
+ MAJOR, MINOR, TINY = 0, 1, 2
4
4
  STRING = [MAJOR, MINOR, TINY].join '.'
5
5
  end
6
6
 
@@ -1,24 +1,24 @@
1
1
  /**
2
- * @fileoverview gl-matrix - High performance matrix and vector operations
3
- * @author Brandon Jones
4
- * @author Colin MacKenzie IV
5
- * @version 2.1.0
6
- */
2
+ * @fileoverview gl-matrix - High performance matrix and vector operations
3
+ * @author Brandon Jones
4
+ * @author Colin MacKenzie IV
5
+ * @version 2.1.0
6
+ */
7
7
 
8
8
  /* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
9
9
 
10
10
  Redistribution and use in source and binary forms, with or without modification,
11
11
  are permitted provided that the following conditions are met:
12
12
 
13
- * Redistributions of source code must retain the above copyright notice, this
14
- list of conditions and the following disclaimer.
15
- * Redistributions in binary form must reproduce the above copyright notice,
16
- this list of conditions and the following disclaimer in the documentation
17
- and/or other materials provided with the distribution.
13
+ * Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+ * Redistributions in binary form must reproduce the above copyright notice,
16
+ this list of conditions and the following disclaimer in the documentation
17
+ and/or other materials provided with the distribution.
18
18
 
19
19
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20
20
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
22
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23
23
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
24
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -41,7 +41,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
41
41
  } else {
42
42
  // gl-matrix lives in a browser, define its namespaces in global
43
43
  shim.exports = window;
44
- }
44
+ }
45
45
  }
46
46
  else {
47
47
  // gl-matrix lives in commonjs, define its namespaces in exports
@@ -54,15 +54,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
54
54
  Redistribution and use in source and binary forms, with or without modification,
55
55
  are permitted provided that the following conditions are met:
56
56
 
57
- * Redistributions of source code must retain the above copyright notice, this
58
- list of conditions and the following disclaimer.
59
- * Redistributions in binary form must reproduce the above copyright notice,
60
- this list of conditions and the following disclaimer in the documentation
61
- and/or other materials provided with the distribution.
57
+ * Redistributions of source code must retain the above copyright notice, this
58
+ list of conditions and the following disclaimer.
59
+ * Redistributions in binary form must reproduce the above copyright notice,
60
+ this list of conditions and the following disclaimer in the documentation
61
+ and/or other materials provided with the distribution.
62
62
 
63
63
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
64
64
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
65
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
65
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
66
66
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
67
67
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68
68
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -81,16 +81,16 @@ if(!GLMAT_ARRAY_TYPE) {
81
81
  }
82
82
 
83
83
  /**
84
- * @class Common utilities
85
- * @name glMatrix
86
- */
84
+ * @class Common utilities
85
+ * @name glMatrix
86
+ */
87
87
  var glMatrix = {};
88
88
 
89
89
  /**
90
- * Sets the type of array used when creating new vectors and matricies
91
- *
92
- * @param {Type} type Array type, such as Float32Array or Array
93
- */
90
+ * Sets the type of array used when creating new vectors and matricies
91
+ *
92
+ * @param {Type} type Array type, such as Float32Array or Array
93
+ */
94
94
  glMatrix.setMatrixArrayType = function(type) {
95
95
  GLMAT_ARRAY_TYPE = type;
96
96
  }
@@ -104,15 +104,15 @@ if(typeof(exports) !== 'undefined') {
104
104
  Redistribution and use in source and binary forms, with or without modification,
105
105
  are permitted provided that the following conditions are met:
106
106
 
107
- * Redistributions of source code must retain the above copyright notice, this
108
- list of conditions and the following disclaimer.
109
- * Redistributions in binary form must reproduce the above copyright notice,
110
- this list of conditions and the following disclaimer in the documentation
111
- and/or other materials provided with the distribution.
107
+ * Redistributions of source code must retain the above copyright notice, this
108
+ list of conditions and the following disclaimer.
109
+ * Redistributions in binary form must reproduce the above copyright notice,
110
+ this list of conditions and the following disclaimer in the documentation
111
+ and/or other materials provided with the distribution.
112
112
 
113
113
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
114
114
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
115
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
115
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
116
116
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
117
117
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
118
118
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -122,17 +122,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122
122
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
123
123
 
124
124
  /**
125
- * @class 2 Dimensional Vector
126
- * @name vec2
127
- */
125
+ * @class 2 Dimensional Vector
126
+ * @name vec2
127
+ */
128
128
 
129
129
  var vec2 = {};
130
130
 
131
131
  /**
132
- * Creates a new, empty vec2
133
- *
134
- * @returns {vec2} a new 2D vector
135
- */
132
+ * Creates a new, empty vec2
133
+ *
134
+ * @returns {vec2} a new 2D vector
135
+ */
136
136
  vec2.create = function() {
137
137
  var out = new GLMAT_ARRAY_TYPE(2);
138
138
  out[0] = 0;
@@ -141,11 +141,11 @@ vec2.create = function() {
141
141
  };
142
142
 
143
143
  /**
144
- * Creates a new vec2 initialized with values from an existing vector
145
- *
146
- * @param {vec2} a vector to clone
147
- * @returns {vec2} a new 2D vector
148
- */
144
+ * Creates a new vec2 initialized with values from an existing vector
145
+ *
146
+ * @param {vec2} a vector to clone
147
+ * @returns {vec2} a new 2D vector
148
+ */
149
149
  vec2.clone = function(a) {
150
150
  var out = new GLMAT_ARRAY_TYPE(2);
151
151
  out[0] = a[0];
@@ -154,12 +154,12 @@ vec2.clone = function(a) {
154
154
  };
155
155
 
156
156
  /**
157
- * Creates a new vec2 initialized with the given values
158
- *
159
- * @param {Number} x X component
160
- * @param {Number} y Y component
161
- * @returns {vec2} a new 2D vector
162
- */
157
+ * Creates a new vec2 initialized with the given values
158
+ *
159
+ * @param {Number} x X component
160
+ * @param {Number} y Y component
161
+ * @returns {vec2} a new 2D vector
162
+ */
163
163
  vec2.fromValues = function(x, y) {
164
164
  var out = new GLMAT_ARRAY_TYPE(2);
165
165
  out[0] = x;
@@ -168,12 +168,12 @@ vec2.fromValues = function(x, y) {
168
168
  };
169
169
 
170
170
  /**
171
- * Copy the values from one vec2 to another
172
- *
173
- * @param {vec2} out the receiving vector
174
- * @param {vec2} a the source vector
175
- * @returns {vec2} out
176
- */
171
+ * Copy the values from one vec2 to another
172
+ *
173
+ * @param {vec2} out the receiving vector
174
+ * @param {vec2} a the source vector
175
+ * @returns {vec2} out
176
+ */
177
177
  vec2.copy = function(out, a) {
178
178
  out[0] = a[0];
179
179
  out[1] = a[1];
@@ -181,13 +181,13 @@ vec2.copy = function(out, a) {
181
181
  };
182
182
 
183
183
  /**
184
- * Set the components of a vec2 to the given values
185
- *
186
- * @param {vec2} out the receiving vector
187
- * @param {Number} x X component
188
- * @param {Number} y Y component
189
- * @returns {vec2} out
190
- */
184
+ * Set the components of a vec2 to the given values
185
+ *
186
+ * @param {vec2} out the receiving vector
187
+ * @param {Number} x X component
188
+ * @param {Number} y Y component
189
+ * @returns {vec2} out
190
+ */
191
191
  vec2.set = function(out, x, y) {
192
192
  out[0] = x;
193
193
  out[1] = y;
@@ -195,13 +195,13 @@ vec2.set = function(out, x, y) {
195
195
  };
196
196
 
197
197
  /**
198
- * Adds two vec2's
199
- *
200
- * @param {vec2} out the receiving vector
201
- * @param {vec2} a the first operand
202
- * @param {vec2} b the second operand
203
- * @returns {vec2} out
204
- */
198
+ * Adds two vec2's
199
+ *
200
+ * @param {vec2} out the receiving vector
201
+ * @param {vec2} a the first operand
202
+ * @param {vec2} b the second operand
203
+ * @returns {vec2} out
204
+ */
205
205
  vec2.add = function(out, a, b) {
206
206
  out[0] = a[0] + b[0];
207
207
  out[1] = a[1] + b[1];
@@ -209,13 +209,13 @@ vec2.add = function(out, a, b) {
209
209
  };
210
210
 
211
211
  /**
212
- * Subtracts two vec2's
213
- *
214
- * @param {vec2} out the receiving vector
215
- * @param {vec2} a the first operand
216
- * @param {vec2} b the second operand
217
- * @returns {vec2} out
218
- */
212
+ * Subtracts vector b from vector a
213
+ *
214
+ * @param {vec2} out the receiving vector
215
+ * @param {vec2} a the first operand
216
+ * @param {vec2} b the second operand
217
+ * @returns {vec2} out
218
+ */
219
219
  vec2.subtract = function(out, a, b) {
220
220
  out[0] = a[0] - b[0];
221
221
  out[1] = a[1] - b[1];
@@ -223,19 +223,19 @@ vec2.subtract = function(out, a, b) {
223
223
  };
224
224
 
225
225
  /**
226
- * Alias for {@link vec2.subtract}
227
- * @function
228
- */
226
+ * Alias for {@link vec2.subtract}
227
+ * @function
228
+ */
229
229
  vec2.sub = vec2.subtract;
230
230
 
231
231
  /**
232
- * Multiplies two vec2's
233
- *
234
- * @param {vec2} out the receiving vector
235
- * @param {vec2} a the first operand
236
- * @param {vec2} b the second operand
237
- * @returns {vec2} out
238
- */
232
+ * Multiplies two vec2's
233
+ *
234
+ * @param {vec2} out the receiving vector
235
+ * @param {vec2} a the first operand
236
+ * @param {vec2} b the second operand
237
+ * @returns {vec2} out
238
+ */
239
239
  vec2.multiply = function(out, a, b) {
240
240
  out[0] = a[0] * b[0];
241
241
  out[1] = a[1] * b[1];
@@ -243,19 +243,19 @@ vec2.multiply = function(out, a, b) {
243
243
  };
244
244
 
245
245
  /**
246
- * Alias for {@link vec2.multiply}
247
- * @function
248
- */
246
+ * Alias for {@link vec2.multiply}
247
+ * @function
248
+ */
249
249
  vec2.mul = vec2.multiply;
250
250
 
251
251
  /**
252
- * Divides two vec2's
253
- *
254
- * @param {vec2} out the receiving vector
255
- * @param {vec2} a the first operand
256
- * @param {vec2} b the second operand
257
- * @returns {vec2} out
258
- */
252
+ * Divides two vec2's
253
+ *
254
+ * @param {vec2} out the receiving vector
255
+ * @param {vec2} a the first operand
256
+ * @param {vec2} b the second operand
257
+ * @returns {vec2} out
258
+ */
259
259
  vec2.divide = function(out, a, b) {
260
260
  out[0] = a[0] / b[0];
261
261
  out[1] = a[1] / b[1];
@@ -263,19 +263,19 @@ vec2.divide = function(out, a, b) {
263
263
  };
264
264
 
265
265
  /**
266
- * Alias for {@link vec2.divide}
267
- * @function
268
- */
266
+ * Alias for {@link vec2.divide}
267
+ * @function
268
+ */
269
269
  vec2.div = vec2.divide;
270
270
 
271
271
  /**
272
- * Returns the minimum of two vec2's
273
- *
274
- * @param {vec2} out the receiving vector
275
- * @param {vec2} a the first operand
276
- * @param {vec2} b the second operand
277
- * @returns {vec2} out
278
- */
272
+ * Returns the minimum of two vec2's
273
+ *
274
+ * @param {vec2} out the receiving vector
275
+ * @param {vec2} a the first operand
276
+ * @param {vec2} b the second operand
277
+ * @returns {vec2} out
278
+ */
279
279
  vec2.min = function(out, a, b) {
280
280
  out[0] = Math.min(a[0], b[0]);
281
281
  out[1] = Math.min(a[1], b[1]);
@@ -283,13 +283,13 @@ vec2.min = function(out, a, b) {
283
283
  };
284
284
 
285
285
  /**
286
- * Returns the maximum of two vec2's
287
- *
288
- * @param {vec2} out the receiving vector
289
- * @param {vec2} a the first operand
290
- * @param {vec2} b the second operand
291
- * @returns {vec2} out
292
- */
286
+ * Returns the maximum of two vec2's
287
+ *
288
+ * @param {vec2} out the receiving vector
289
+ * @param {vec2} a the first operand
290
+ * @param {vec2} b the second operand
291
+ * @returns {vec2} out
292
+ */
293
293
  vec2.max = function(out, a, b) {
294
294
  out[0] = Math.max(a[0], b[0]);
295
295
  out[1] = Math.max(a[1], b[1]);
@@ -297,13 +297,13 @@ vec2.max = function(out, a, b) {
297
297
  };
298
298
 
299
299
  /**
300
- * Scales a vec2 by a scalar number
301
- *
302
- * @param {vec2} out the receiving vector
303
- * @param {vec2} a the vector to scale
304
- * @param {Number} b amount to scale the vector by
305
- * @returns {vec2} out
306
- */
300
+ * Scales a vec2 by a scalar number
301
+ *
302
+ * @param {vec2} out the receiving vector
303
+ * @param {vec2} a the vector to scale
304
+ * @param {Number} b amount to scale the vector by
305
+ * @returns {vec2} out
306
+ */
307
307
  vec2.scale = function(out, a, b) {
308
308
  out[0] = a[0] * b;
309
309
  out[1] = a[1] * b;
@@ -311,12 +311,27 @@ vec2.scale = function(out, a, b) {
311
311
  };
312
312
 
313
313
  /**
314
- * Calculates the euclidian distance between two vec2's
315
- *
316
- * @param {vec2} a the first operand
317
- * @param {vec2} b the second operand
318
- * @returns {Number} distance between a and b
319
- */
314
+ * Adds two vec2's after scaling the second operand by a scalar value
315
+ *
316
+ * @param {vec2} out the receiving vector
317
+ * @param {vec2} a the first operand
318
+ * @param {vec2} b the second operand
319
+ * @param {Number} scale the amount to scale b by before adding
320
+ * @returns {vec2} out
321
+ */
322
+ vec2.scaleAndAdd = function(out, a, b, scale) {
323
+ out[0] = a[0] + (b[0] * scale);
324
+ out[1] = a[1] + (b[1] * scale);
325
+ return out;
326
+ };
327
+
328
+ /**
329
+ * Calculates the euclidian distance between two vec2's
330
+ *
331
+ * @param {vec2} a the first operand
332
+ * @param {vec2} b the second operand
333
+ * @returns {Number} distance between a and b
334
+ */
320
335
  vec2.distance = function(a, b) {
321
336
  var x = b[0] - a[0],
322
337
  y = b[1] - a[1];
@@ -324,18 +339,18 @@ vec2.distance = function(a, b) {
324
339
  };
325
340
 
326
341
  /**
327
- * Alias for {@link vec2.distance}
328
- * @function
329
- */
342
+ * Alias for {@link vec2.distance}
343
+ * @function
344
+ */
330
345
  vec2.dist = vec2.distance;
331
346
 
332
347
  /**
333
- * Calculates the squared euclidian distance between two vec2's
334
- *
335
- * @param {vec2} a the first operand
336
- * @param {vec2} b the second operand
337
- * @returns {Number} squared distance between a and b
338
- */
348
+ * Calculates the squared euclidian distance between two vec2's
349
+ *
350
+ * @param {vec2} a the first operand
351
+ * @param {vec2} b the second operand
352
+ * @returns {Number} squared distance between a and b
353
+ */
339
354
  vec2.squaredDistance = function(a, b) {
340
355
  var x = b[0] - a[0],
341
356
  y = b[1] - a[1];
@@ -343,17 +358,17 @@ vec2.squaredDistance = function(a, b) {
343
358
  };
344
359
 
345
360
  /**
346
- * Alias for {@link vec2.squaredDistance}
347
- * @function
348
- */
361
+ * Alias for {@link vec2.squaredDistance}
362
+ * @function
363
+ */
349
364
  vec2.sqrDist = vec2.squaredDistance;
350
365
 
351
366
  /**
352
- * Calculates the length of a vec2
353
- *
354
- * @param {vec2} a vector to calculate length of
355
- * @returns {Number} length of a
356
- */
367
+ * Calculates the length of a vec2
368
+ *
369
+ * @param {vec2} a vector to calculate length of
370
+ * @returns {Number} length of a
371
+ */
357
372
  vec2.length = function (a) {
358
373
  var x = a[0],
359
374
  y = a[1];
@@ -361,17 +376,17 @@ vec2.length = function (a) {
361
376
  };
362
377
 
363
378
  /**
364
- * Alias for {@link vec2.length}
365
- * @function
366
- */
379
+ * Alias for {@link vec2.length}
380
+ * @function
381
+ */
367
382
  vec2.len = vec2.length;
368
383
 
369
384
  /**
370
- * Calculates the squared length of a vec2
371
- *
372
- * @param {vec2} a vector to calculate squared length of
373
- * @returns {Number} squared length of a
374
- */
385
+ * Calculates the squared length of a vec2
386
+ *
387
+ * @param {vec2} a vector to calculate squared length of
388
+ * @returns {Number} squared length of a
389
+ */
375
390
  vec2.squaredLength = function (a) {
376
391
  var x = a[0],
377
392
  y = a[1];
@@ -379,18 +394,18 @@ vec2.squaredLength = function (a) {
379
394
  };
380
395
 
381
396
  /**
382
- * Alias for {@link vec2.squaredLength}
383
- * @function
384
- */
397
+ * Alias for {@link vec2.squaredLength}
398
+ * @function
399
+ */
385
400
  vec2.sqrLen = vec2.squaredLength;
386
401
 
387
402
  /**
388
- * Negates the components of a vec2
389
- *
390
- * @param {vec2} out the receiving vector
391
- * @param {vec2} a vector to negate
392
- * @returns {vec2} out
393
- */
403
+ * Negates the components of a vec2
404
+ *
405
+ * @param {vec2} out the receiving vector
406
+ * @param {vec2} a vector to negate
407
+ * @returns {vec2} out
408
+ */
394
409
  vec2.negate = function(out, a) {
395
410
  out[0] = -a[0];
396
411
  out[1] = -a[1];
@@ -398,12 +413,12 @@ vec2.negate = function(out, a) {
398
413
  };
399
414
 
400
415
  /**
401
- * Normalize a vec2
402
- *
403
- * @param {vec2} out the receiving vector
404
- * @param {vec2} a vector to normalize
405
- * @returns {vec2} out
406
- */
416
+ * Normalize a vec2
417
+ *
418
+ * @param {vec2} out the receiving vector
419
+ * @param {vec2} a vector to normalize
420
+ * @returns {vec2} out
421
+ */
407
422
  vec2.normalize = function(out, a) {
408
423
  var x = a[0],
409
424
  y = a[1];
@@ -418,25 +433,25 @@ vec2.normalize = function(out, a) {
418
433
  };
419
434
 
420
435
  /**
421
- * Calculates the dot product of two vec2's
422
- *
423
- * @param {vec2} a the first operand
424
- * @param {vec2} b the second operand
425
- * @returns {Number} dot product of a and b
426
- */
436
+ * Calculates the dot product of two vec2's
437
+ *
438
+ * @param {vec2} a the first operand
439
+ * @param {vec2} b the second operand
440
+ * @returns {Number} dot product of a and b
441
+ */
427
442
  vec2.dot = function (a, b) {
428
443
  return a[0] * b[0] + a[1] * b[1];
429
444
  };
430
445
 
431
446
  /**
432
- * Computes the cross product of two vec2's
433
- * Note that the cross product must by definition produce a 3D vector
434
- *
435
- * @param {vec3} out the receiving vector
436
- * @param {vec2} a the first operand
437
- * @param {vec2} b the second operand
438
- * @returns {vec3} out
439
- */
447
+ * Computes the cross product of two vec2's
448
+ * Note that the cross product must by definition produce a 3D vector
449
+ *
450
+ * @param {vec3} out the receiving vector
451
+ * @param {vec2} a the first operand
452
+ * @param {vec2} b the second operand
453
+ * @returns {vec3} out
454
+ */
440
455
  vec2.cross = function(out, a, b) {
441
456
  var z = a[0] * b[1] - a[1] * b[0];
442
457
  out[0] = out[1] = 0;
@@ -445,14 +460,14 @@ vec2.cross = function(out, a, b) {
445
460
  };
446
461
 
447
462
  /**
448
- * Performs a linear interpolation between two vec2's
449
- *
450
- * @param {vec2} out the receiving vector
451
- * @param {vec2} a the first operand
452
- * @param {vec2} b the second operand
453
- * @param {Number} t interpolation amount between the two inputs
454
- * @returns {vec2} out
455
- */
463
+ * Performs a linear interpolation between two vec2's
464
+ *
465
+ * @param {vec2} out the receiving vector
466
+ * @param {vec2} a the first operand
467
+ * @param {vec2} b the second operand
468
+ * @param {Number} t interpolation amount between the two inputs
469
+ * @returns {vec2} out
470
+ */
456
471
  vec2.lerp = function (out, a, b, t) {
457
472
  var ax = a[0],
458
473
  ay = a[1];
@@ -462,13 +477,13 @@ vec2.lerp = function (out, a, b, t) {
462
477
  };
463
478
 
464
479
  /**
465
- * Transforms the vec2 with a mat2
466
- *
467
- * @param {vec2} out the receiving vector
468
- * @param {vec2} a the vector to transform
469
- * @param {mat2} m matrix to transform with
470
- * @returns {vec2} out
471
- */
480
+ * Transforms the vec2 with a mat2
481
+ *
482
+ * @param {vec2} out the receiving vector
483
+ * @param {vec2} a the vector to transform
484
+ * @param {mat2} m matrix to transform with
485
+ * @returns {vec2} out
486
+ */
472
487
  vec2.transformMat2 = function(out, a, m) {
473
488
  var x = a[0],
474
489
  y = a[1];
@@ -478,13 +493,13 @@ vec2.transformMat2 = function(out, a, m) {
478
493
  };
479
494
 
480
495
  /**
481
- * Transforms the vec2 with a mat2d
482
- *
483
- * @param {vec2} out the receiving vector
484
- * @param {vec2} a the vector to transform
485
- * @param {mat2d} m matrix to transform with
486
- * @returns {vec2} out
487
- */
496
+ * Transforms the vec2 with a mat2d
497
+ *
498
+ * @param {vec2} out the receiving vector
499
+ * @param {vec2} a the vector to transform
500
+ * @param {mat2d} m matrix to transform with
501
+ * @returns {vec2} out
502
+ */
488
503
  vec2.transformMat2d = function(out, a, m) {
489
504
  var x = a[0],
490
505
  y = a[1];
@@ -494,14 +509,14 @@ vec2.transformMat2d = function(out, a, m) {
494
509
  };
495
510
 
496
511
  /**
497
- * Transforms the vec2 with a mat3
498
- * 3rd vector component is implicitly '1'
499
- *
500
- * @param {vec2} out the receiving vector
501
- * @param {vec2} a the vector to transform
502
- * @param {mat3} m matrix to transform with
503
- * @returns {vec2} out
504
- */
512
+ * Transforms the vec2 with a mat3
513
+ * 3rd vector component is implicitly '1'
514
+ *
515
+ * @param {vec2} out the receiving vector
516
+ * @param {vec2} a the vector to transform
517
+ * @param {mat3} m matrix to transform with
518
+ * @returns {vec2} out
519
+ */
505
520
  vec2.transformMat3 = function(out, a, m) {
506
521
  var x = a[0],
507
522
  y = a[1];
@@ -511,17 +526,17 @@ vec2.transformMat3 = function(out, a, m) {
511
526
  };
512
527
 
513
528
  /**
514
- * Transforms the vec2 with a mat4
515
- * 3rd vector component is implicitly '0'
516
- * 4th vector component is implicitly '1'
517
- *
518
- * @param {vec2} out the receiving vector
519
- * @param {vec2} a the vector to transform
520
- * @param {mat4} m matrix to transform with
521
- * @returns {vec2} out
522
- */
529
+ * Transforms the vec2 with a mat4
530
+ * 3rd vector component is implicitly '0'
531
+ * 4th vector component is implicitly '1'
532
+ *
533
+ * @param {vec2} out the receiving vector
534
+ * @param {vec2} a the vector to transform
535
+ * @param {mat4} m matrix to transform with
536
+ * @returns {vec2} out
537
+ */
523
538
  vec2.transformMat4 = function(out, a, m) {
524
- var x = a[0],
539
+ var x = a[0],
525
540
  y = a[1];
526
541
  out[0] = m[0] * x + m[4] * y + m[12];
527
542
  out[1] = m[1] * x + m[5] * y + m[13];
@@ -529,17 +544,17 @@ vec2.transformMat4 = function(out, a, m) {
529
544
  };
530
545
 
531
546
  /**
532
- * Perform some operation over an array of vec2s.
533
- *
534
- * @param {Array} a the array of vectors to iterate over
535
- * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
536
- * @param {Number} offset Number of elements to skip at the beginning of the array
537
- * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
538
- * @param {Function} fn Function to call for each vector in the array
539
- * @param {Object} [arg] additional argument to pass to fn
540
- * @returns {Array} a
541
- * @function
542
- */
547
+ * Perform some operation over an array of vec2s.
548
+ *
549
+ * @param {Array} a the array of vectors to iterate over
550
+ * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
551
+ * @param {Number} offset Number of elements to skip at the beginning of the array
552
+ * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
553
+ * @param {Function} fn Function to call for each vector in the array
554
+ * @param {Object} [arg] additional argument to pass to fn
555
+ * @returns {Array} a
556
+ * @function
557
+ */
543
558
  vec2.forEach = (function() {
544
559
  var vec = vec2.create();
545
560
 
@@ -570,11 +585,11 @@ vec2.forEach = (function() {
570
585
  })();
571
586
 
572
587
  /**
573
- * Returns a string representation of a vector
574
- *
575
- * @param {vec2} vec vector to represent as a string
576
- * @returns {String} string representation of the vector
577
- */
588
+ * Returns a string representation of a vector
589
+ *
590
+ * @param {vec2} vec vector to represent as a string
591
+ * @returns {String} string representation of the vector
592
+ */
578
593
  vec2.str = function (a) {
579
594
  return 'vec2(' + a[0] + ', ' + a[1] + ')';
580
595
  };
@@ -588,15 +603,15 @@ if(typeof(exports) !== 'undefined') {
588
603
  Redistribution and use in source and binary forms, with or without modification,
589
604
  are permitted provided that the following conditions are met:
590
605
 
591
- * Redistributions of source code must retain the above copyright notice, this
592
- list of conditions and the following disclaimer.
593
- * Redistributions in binary form must reproduce the above copyright notice,
594
- this list of conditions and the following disclaimer in the documentation
595
- and/or other materials provided with the distribution.
606
+ * Redistributions of source code must retain the above copyright notice, this
607
+ list of conditions and the following disclaimer.
608
+ * Redistributions in binary form must reproduce the above copyright notice,
609
+ this list of conditions and the following disclaimer in the documentation
610
+ and/or other materials provided with the distribution.
596
611
 
597
612
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
598
613
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
599
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
614
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
600
615
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
601
616
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
602
617
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -606,17 +621,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
606
621
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
607
622
 
608
623
  /**
609
- * @class 3 Dimensional Vector
610
- * @name vec3
611
- */
624
+ * @class 3 Dimensional Vector
625
+ * @name vec3
626
+ */
612
627
 
613
628
  var vec3 = {};
614
629
 
615
630
  /**
616
- * Creates a new, empty vec3
617
- *
618
- * @returns {vec3} a new 3D vector
619
- */
631
+ * Creates a new, empty vec3
632
+ *
633
+ * @returns {vec3} a new 3D vector
634
+ */
620
635
  vec3.create = function() {
621
636
  var out = new GLMAT_ARRAY_TYPE(3);
622
637
  out[0] = 0;
@@ -626,11 +641,11 @@ vec3.create = function() {
626
641
  };
627
642
 
628
643
  /**
629
- * Creates a new vec3 initialized with values from an existing vector
630
- *
631
- * @param {vec3} a vector to clone
632
- * @returns {vec3} a new 3D vector
633
- */
644
+ * Creates a new vec3 initialized with values from an existing vector
645
+ *
646
+ * @param {vec3} a vector to clone
647
+ * @returns {vec3} a new 3D vector
648
+ */
634
649
  vec3.clone = function(a) {
635
650
  var out = new GLMAT_ARRAY_TYPE(3);
636
651
  out[0] = a[0];
@@ -640,13 +655,13 @@ vec3.clone = function(a) {
640
655
  };
641
656
 
642
657
  /**
643
- * Creates a new vec3 initialized with the given values
644
- *
645
- * @param {Number} x X component
646
- * @param {Number} y Y component
647
- * @param {Number} z Z component
648
- * @returns {vec3} a new 3D vector
649
- */
658
+ * Creates a new vec3 initialized with the given values
659
+ *
660
+ * @param {Number} x X component
661
+ * @param {Number} y Y component
662
+ * @param {Number} z Z component
663
+ * @returns {vec3} a new 3D vector
664
+ */
650
665
  vec3.fromValues = function(x, y, z) {
651
666
  var out = new GLMAT_ARRAY_TYPE(3);
652
667
  out[0] = x;
@@ -656,12 +671,12 @@ vec3.fromValues = function(x, y, z) {
656
671
  };
657
672
 
658
673
  /**
659
- * Copy the values from one vec3 to another
660
- *
661
- * @param {vec3} out the receiving vector
662
- * @param {vec3} a the source vector
663
- * @returns {vec3} out
664
- */
674
+ * Copy the values from one vec3 to another
675
+ *
676
+ * @param {vec3} out the receiving vector
677
+ * @param {vec3} a the source vector
678
+ * @returns {vec3} out
679
+ */
665
680
  vec3.copy = function(out, a) {
666
681
  out[0] = a[0];
667
682
  out[1] = a[1];
@@ -670,14 +685,14 @@ vec3.copy = function(out, a) {
670
685
  };
671
686
 
672
687
  /**
673
- * Set the components of a vec3 to the given values
674
- *
675
- * @param {vec3} out the receiving vector
676
- * @param {Number} x X component
677
- * @param {Number} y Y component
678
- * @param {Number} z Z component
679
- * @returns {vec3} out
680
- */
688
+ * Set the components of a vec3 to the given values
689
+ *
690
+ * @param {vec3} out the receiving vector
691
+ * @param {Number} x X component
692
+ * @param {Number} y Y component
693
+ * @param {Number} z Z component
694
+ * @returns {vec3} out
695
+ */
681
696
  vec3.set = function(out, x, y, z) {
682
697
  out[0] = x;
683
698
  out[1] = y;
@@ -686,13 +701,13 @@ vec3.set = function(out, x, y, z) {
686
701
  };
687
702
 
688
703
  /**
689
- * Adds two vec3's
690
- *
691
- * @param {vec3} out the receiving vector
692
- * @param {vec3} a the first operand
693
- * @param {vec3} b the second operand
694
- * @returns {vec3} out
695
- */
704
+ * Adds two vec3's
705
+ *
706
+ * @param {vec3} out the receiving vector
707
+ * @param {vec3} a the first operand
708
+ * @param {vec3} b the second operand
709
+ * @returns {vec3} out
710
+ */
696
711
  vec3.add = function(out, a, b) {
697
712
  out[0] = a[0] + b[0];
698
713
  out[1] = a[1] + b[1];
@@ -701,13 +716,13 @@ vec3.add = function(out, a, b) {
701
716
  };
702
717
 
703
718
  /**
704
- * Subtracts two vec3's
705
- *
706
- * @param {vec3} out the receiving vector
707
- * @param {vec3} a the first operand
708
- * @param {vec3} b the second operand
709
- * @returns {vec3} out
710
- */
719
+ * Subtracts vector b from vector a
720
+ *
721
+ * @param {vec3} out the receiving vector
722
+ * @param {vec3} a the first operand
723
+ * @param {vec3} b the second operand
724
+ * @returns {vec3} out
725
+ */
711
726
  vec3.subtract = function(out, a, b) {
712
727
  out[0] = a[0] - b[0];
713
728
  out[1] = a[1] - b[1];
@@ -716,19 +731,19 @@ vec3.subtract = function(out, a, b) {
716
731
  };
717
732
 
718
733
  /**
719
- * Alias for {@link vec3.subtract}
720
- * @function
721
- */
734
+ * Alias for {@link vec3.subtract}
735
+ * @function
736
+ */
722
737
  vec3.sub = vec3.subtract;
723
738
 
724
739
  /**
725
- * Multiplies two vec3's
726
- *
727
- * @param {vec3} out the receiving vector
728
- * @param {vec3} a the first operand
729
- * @param {vec3} b the second operand
730
- * @returns {vec3} out
731
- */
740
+ * Multiplies two vec3's
741
+ *
742
+ * @param {vec3} out the receiving vector
743
+ * @param {vec3} a the first operand
744
+ * @param {vec3} b the second operand
745
+ * @returns {vec3} out
746
+ */
732
747
  vec3.multiply = function(out, a, b) {
733
748
  out[0] = a[0] * b[0];
734
749
  out[1] = a[1] * b[1];
@@ -737,19 +752,19 @@ vec3.multiply = function(out, a, b) {
737
752
  };
738
753
 
739
754
  /**
740
- * Alias for {@link vec3.multiply}
741
- * @function
742
- */
755
+ * Alias for {@link vec3.multiply}
756
+ * @function
757
+ */
743
758
  vec3.mul = vec3.multiply;
744
759
 
745
760
  /**
746
- * Divides two vec3's
747
- *
748
- * @param {vec3} out the receiving vector
749
- * @param {vec3} a the first operand
750
- * @param {vec3} b the second operand
751
- * @returns {vec3} out
752
- */
761
+ * Divides two vec3's
762
+ *
763
+ * @param {vec3} out the receiving vector
764
+ * @param {vec3} a the first operand
765
+ * @param {vec3} b the second operand
766
+ * @returns {vec3} out
767
+ */
753
768
  vec3.divide = function(out, a, b) {
754
769
  out[0] = a[0] / b[0];
755
770
  out[1] = a[1] / b[1];
@@ -758,19 +773,19 @@ vec3.divide = function(out, a, b) {
758
773
  };
759
774
 
760
775
  /**
761
- * Alias for {@link vec3.divide}
762
- * @function
763
- */
776
+ * Alias for {@link vec3.divide}
777
+ * @function
778
+ */
764
779
  vec3.div = vec3.divide;
765
780
 
766
781
  /**
767
- * Returns the minimum of two vec3's
768
- *
769
- * @param {vec3} out the receiving vector
770
- * @param {vec3} a the first operand
771
- * @param {vec3} b the second operand
772
- * @returns {vec3} out
773
- */
782
+ * Returns the minimum of two vec3's
783
+ *
784
+ * @param {vec3} out the receiving vector
785
+ * @param {vec3} a the first operand
786
+ * @param {vec3} b the second operand
787
+ * @returns {vec3} out
788
+ */
774
789
  vec3.min = function(out, a, b) {
775
790
  out[0] = Math.min(a[0], b[0]);
776
791
  out[1] = Math.min(a[1], b[1]);
@@ -779,13 +794,13 @@ vec3.min = function(out, a, b) {
779
794
  };
780
795
 
781
796
  /**
782
- * Returns the maximum of two vec3's
783
- *
784
- * @param {vec3} out the receiving vector
785
- * @param {vec3} a the first operand
786
- * @param {vec3} b the second operand
787
- * @returns {vec3} out
788
- */
797
+ * Returns the maximum of two vec3's
798
+ *
799
+ * @param {vec3} out the receiving vector
800
+ * @param {vec3} a the first operand
801
+ * @param {vec3} b the second operand
802
+ * @returns {vec3} out
803
+ */
789
804
  vec3.max = function(out, a, b) {
790
805
  out[0] = Math.max(a[0], b[0]);
791
806
  out[1] = Math.max(a[1], b[1]);
@@ -794,13 +809,13 @@ vec3.max = function(out, a, b) {
794
809
  };
795
810
 
796
811
  /**
797
- * Scales a vec3 by a scalar number
798
- *
799
- * @param {vec3} out the receiving vector
800
- * @param {vec3} a the vector to scale
801
- * @param {Number} b amount to scale the vector by
802
- * @returns {vec3} out
803
- */
812
+ * Scales a vec3 by a scalar number
813
+ *
814
+ * @param {vec3} out the receiving vector
815
+ * @param {vec3} a the vector to scale
816
+ * @param {Number} b amount to scale the vector by
817
+ * @returns {vec3} out
818
+ */
804
819
  vec3.scale = function(out, a, b) {
805
820
  out[0] = a[0] * b;
806
821
  out[1] = a[1] * b;
@@ -809,12 +824,28 @@ vec3.scale = function(out, a, b) {
809
824
  };
810
825
 
811
826
  /**
812
- * Calculates the euclidian distance between two vec3's
813
- *
814
- * @param {vec3} a the first operand
815
- * @param {vec3} b the second operand
816
- * @returns {Number} distance between a and b
817
- */
827
+ * Adds two vec3's after scaling the second operand by a scalar value
828
+ *
829
+ * @param {vec3} out the receiving vector
830
+ * @param {vec3} a the first operand
831
+ * @param {vec3} b the second operand
832
+ * @param {Number} scale the amount to scale b by before adding
833
+ * @returns {vec3} out
834
+ */
835
+ vec3.scaleAndAdd = function(out, a, b, scale) {
836
+ out[0] = a[0] + (b[0] * scale);
837
+ out[1] = a[1] + (b[1] * scale);
838
+ out[2] = a[2] + (b[2] * scale);
839
+ return out;
840
+ };
841
+
842
+ /**
843
+ * Calculates the euclidian distance between two vec3's
844
+ *
845
+ * @param {vec3} a the first operand
846
+ * @param {vec3} b the second operand
847
+ * @returns {Number} distance between a and b
848
+ */
818
849
  vec3.distance = function(a, b) {
819
850
  var x = b[0] - a[0],
820
851
  y = b[1] - a[1],
@@ -823,18 +854,18 @@ vec3.distance = function(a, b) {
823
854
  };
824
855
 
825
856
  /**
826
- * Alias for {@link vec3.distance}
827
- * @function
828
- */
857
+ * Alias for {@link vec3.distance}
858
+ * @function
859
+ */
829
860
  vec3.dist = vec3.distance;
830
861
 
831
862
  /**
832
- * Calculates the squared euclidian distance between two vec3's
833
- *
834
- * @param {vec3} a the first operand
835
- * @param {vec3} b the second operand
836
- * @returns {Number} squared distance between a and b
837
- */
863
+ * Calculates the squared euclidian distance between two vec3's
864
+ *
865
+ * @param {vec3} a the first operand
866
+ * @param {vec3} b the second operand
867
+ * @returns {Number} squared distance between a and b
868
+ */
838
869
  vec3.squaredDistance = function(a, b) {
839
870
  var x = b[0] - a[0],
840
871
  y = b[1] - a[1],
@@ -843,17 +874,17 @@ vec3.squaredDistance = function(a, b) {
843
874
  };
844
875
 
845
876
  /**
846
- * Alias for {@link vec3.squaredDistance}
847
- * @function
848
- */
877
+ * Alias for {@link vec3.squaredDistance}
878
+ * @function
879
+ */
849
880
  vec3.sqrDist = vec3.squaredDistance;
850
881
 
851
882
  /**
852
- * Calculates the length of a vec3
853
- *
854
- * @param {vec3} a vector to calculate length of
855
- * @returns {Number} length of a
856
- */
883
+ * Calculates the length of a vec3
884
+ *
885
+ * @param {vec3} a vector to calculate length of
886
+ * @returns {Number} length of a
887
+ */
857
888
  vec3.length = function (a) {
858
889
  var x = a[0],
859
890
  y = a[1],
@@ -862,17 +893,17 @@ vec3.length = function (a) {
862
893
  };
863
894
 
864
895
  /**
865
- * Alias for {@link vec3.length}
866
- * @function
867
- */
896
+ * Alias for {@link vec3.length}
897
+ * @function
898
+ */
868
899
  vec3.len = vec3.length;
869
900
 
870
901
  /**
871
- * Calculates the squared length of a vec3
872
- *
873
- * @param {vec3} a vector to calculate squared length of
874
- * @returns {Number} squared length of a
875
- */
902
+ * Calculates the squared length of a vec3
903
+ *
904
+ * @param {vec3} a vector to calculate squared length of
905
+ * @returns {Number} squared length of a
906
+ */
876
907
  vec3.squaredLength = function (a) {
877
908
  var x = a[0],
878
909
  y = a[1],
@@ -881,18 +912,18 @@ vec3.squaredLength = function (a) {
881
912
  };
882
913
 
883
914
  /**
884
- * Alias for {@link vec3.squaredLength}
885
- * @function
886
- */
915
+ * Alias for {@link vec3.squaredLength}
916
+ * @function
917
+ */
887
918
  vec3.sqrLen = vec3.squaredLength;
888
919
 
889
920
  /**
890
- * Negates the components of a vec3
891
- *
892
- * @param {vec3} out the receiving vector
893
- * @param {vec3} a vector to negate
894
- * @returns {vec3} out
895
- */
921
+ * Negates the components of a vec3
922
+ *
923
+ * @param {vec3} out the receiving vector
924
+ * @param {vec3} a vector to negate
925
+ * @returns {vec3} out
926
+ */
896
927
  vec3.negate = function(out, a) {
897
928
  out[0] = -a[0];
898
929
  out[1] = -a[1];
@@ -901,12 +932,12 @@ vec3.negate = function(out, a) {
901
932
  };
902
933
 
903
934
  /**
904
- * Normalize a vec3
905
- *
906
- * @param {vec3} out the receiving vector
907
- * @param {vec3} a vector to normalize
908
- * @returns {vec3} out
909
- */
935
+ * Normalize a vec3
936
+ *
937
+ * @param {vec3} out the receiving vector
938
+ * @param {vec3} a vector to normalize
939
+ * @returns {vec3} out
940
+ */
910
941
  vec3.normalize = function(out, a) {
911
942
  var x = a[0],
912
943
  y = a[1],
@@ -923,24 +954,24 @@ vec3.normalize = function(out, a) {
923
954
  };
924
955
 
925
956
  /**
926
- * Calculates the dot product of two vec3's
927
- *
928
- * @param {vec3} a the first operand
929
- * @param {vec3} b the second operand
930
- * @returns {Number} dot product of a and b
931
- */
957
+ * Calculates the dot product of two vec3's
958
+ *
959
+ * @param {vec3} a the first operand
960
+ * @param {vec3} b the second operand
961
+ * @returns {Number} dot product of a and b
962
+ */
932
963
  vec3.dot = function (a, b) {
933
964
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
934
965
  };
935
966
 
936
967
  /**
937
- * Computes the cross product of two vec3's
938
- *
939
- * @param {vec3} out the receiving vector
940
- * @param {vec3} a the first operand
941
- * @param {vec3} b the second operand
942
- * @returns {vec3} out
943
- */
968
+ * Computes the cross product of two vec3's
969
+ *
970
+ * @param {vec3} out the receiving vector
971
+ * @param {vec3} a the first operand
972
+ * @param {vec3} b the second operand
973
+ * @returns {vec3} out
974
+ */
944
975
  vec3.cross = function(out, a, b) {
945
976
  var ax = a[0], ay = a[1], az = a[2],
946
977
  bx = b[0], by = b[1], bz = b[2];
@@ -952,14 +983,14 @@ vec3.cross = function(out, a, b) {
952
983
  };
953
984
 
954
985
  /**
955
- * Performs a linear interpolation between two vec3's
956
- *
957
- * @param {vec3} out the receiving vector
958
- * @param {vec3} a the first operand
959
- * @param {vec3} b the second operand
960
- * @param {Number} t interpolation amount between the two inputs
961
- * @returns {vec3} out
962
- */
986
+ * Performs a linear interpolation between two vec3's
987
+ *
988
+ * @param {vec3} out the receiving vector
989
+ * @param {vec3} a the first operand
990
+ * @param {vec3} b the second operand
991
+ * @param {Number} t interpolation amount between the two inputs
992
+ * @returns {vec3} out
993
+ */
963
994
  vec3.lerp = function (out, a, b, t) {
964
995
  var ax = a[0],
965
996
  ay = a[1],
@@ -971,14 +1002,14 @@ vec3.lerp = function (out, a, b, t) {
971
1002
  };
972
1003
 
973
1004
  /**
974
- * Transforms the vec3 with a mat4.
975
- * 4th vector component is implicitly '1'
976
- *
977
- * @param {vec3} out the receiving vector
978
- * @param {vec3} a the vector to transform
979
- * @param {mat4} m matrix to transform with
980
- * @returns {vec3} out
981
- */
1005
+ * Transforms the vec3 with a mat4.
1006
+ * 4th vector component is implicitly '1'
1007
+ *
1008
+ * @param {vec3} out the receiving vector
1009
+ * @param {vec3} a the vector to transform
1010
+ * @param {mat4} m matrix to transform with
1011
+ * @returns {vec3} out
1012
+ */
982
1013
  vec3.transformMat4 = function(out, a, m) {
983
1014
  var x = a[0], y = a[1], z = a[2];
984
1015
  out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];
@@ -988,13 +1019,29 @@ vec3.transformMat4 = function(out, a, m) {
988
1019
  };
989
1020
 
990
1021
  /**
991
- * Transforms the vec3 with a quat
992
- *
993
- * @param {vec3} out the receiving vector
994
- * @param {vec3} a the vector to transform
995
- * @param {quat} q quaternion to transform with
996
- * @returns {vec3} out
997
- */
1022
+ * Transforms the vec3 with a mat3.
1023
+ *
1024
+ * @param {vec3} out the receiving vector
1025
+ * @param {vec3} a the vector to transform
1026
+ * @param {mat4} m the 3x3 matrix to transform with
1027
+ * @returns {vec3} out
1028
+ */
1029
+ vec3.transformMat3 = function(out, a, m) {
1030
+ var x = a[0], y = a[1], z = a[2];
1031
+ out[0] = x * m[0] + y * m[3] + z * m[6];
1032
+ out[1] = x * m[1] + y * m[4] + z * m[7];
1033
+ out[2] = x * m[2] + y * m[5] + z * m[8];
1034
+ return out;
1035
+ };
1036
+
1037
+ /**
1038
+ * Transforms the vec3 with a quat
1039
+ *
1040
+ * @param {vec3} out the receiving vector
1041
+ * @param {vec3} a the vector to transform
1042
+ * @param {quat} q quaternion to transform with
1043
+ * @returns {vec3} out
1044
+ */
998
1045
  vec3.transformQuat = function(out, a, q) {
999
1046
  var x = a[0], y = a[1], z = a[2],
1000
1047
  qx = q[0], qy = q[1], qz = q[2], qw = q[3],
@@ -1013,17 +1060,17 @@ vec3.transformQuat = function(out, a, q) {
1013
1060
  };
1014
1061
 
1015
1062
  /**
1016
- * Perform some operation over an array of vec3s.
1017
- *
1018
- * @param {Array} a the array of vectors to iterate over
1019
- * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
1020
- * @param {Number} offset Number of elements to skip at the beginning of the array
1021
- * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
1022
- * @param {Function} fn Function to call for each vector in the array
1023
- * @param {Object} [arg] additional argument to pass to fn
1024
- * @returns {Array} a
1025
- * @function
1026
- */
1063
+ * Perform some operation over an array of vec3s.
1064
+ *
1065
+ * @param {Array} a the array of vectors to iterate over
1066
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
1067
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1068
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
1069
+ * @param {Function} fn Function to call for each vector in the array
1070
+ * @param {Object} [arg] additional argument to pass to fn
1071
+ * @returns {Array} a
1072
+ * @function
1073
+ */
1027
1074
  vec3.forEach = (function() {
1028
1075
  var vec = vec3.create();
1029
1076
 
@@ -1054,11 +1101,11 @@ vec3.forEach = (function() {
1054
1101
  })();
1055
1102
 
1056
1103
  /**
1057
- * Returns a string representation of a vector
1058
- *
1059
- * @param {vec3} vec vector to represent as a string
1060
- * @returns {String} string representation of the vector
1061
- */
1104
+ * Returns a string representation of a vector
1105
+ *
1106
+ * @param {vec3} vec vector to represent as a string
1107
+ * @returns {String} string representation of the vector
1108
+ */
1062
1109
  vec3.str = function (a) {
1063
1110
  return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';
1064
1111
  };
@@ -1072,15 +1119,15 @@ if(typeof(exports) !== 'undefined') {
1072
1119
  Redistribution and use in source and binary forms, with or without modification,
1073
1120
  are permitted provided that the following conditions are met:
1074
1121
 
1075
- * Redistributions of source code must retain the above copyright notice, this
1076
- list of conditions and the following disclaimer.
1077
- * Redistributions in binary form must reproduce the above copyright notice,
1078
- this list of conditions and the following disclaimer in the documentation
1079
- and/or other materials provided with the distribution.
1122
+ * Redistributions of source code must retain the above copyright notice, this
1123
+ list of conditions and the following disclaimer.
1124
+ * Redistributions in binary form must reproduce the above copyright notice,
1125
+ this list of conditions and the following disclaimer in the documentation
1126
+ and/or other materials provided with the distribution.
1080
1127
 
1081
1128
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1082
1129
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1083
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1130
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1084
1131
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
1085
1132
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1086
1133
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -1090,17 +1137,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1090
1137
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
1091
1138
 
1092
1139
  /**
1093
- * @class 4 Dimensional Vector
1094
- * @name vec4
1095
- */
1140
+ * @class 4 Dimensional Vector
1141
+ * @name vec4
1142
+ */
1096
1143
 
1097
1144
  var vec4 = {};
1098
1145
 
1099
1146
  /**
1100
- * Creates a new, empty vec4
1101
- *
1102
- * @returns {vec4} a new 4D vector
1103
- */
1147
+ * Creates a new, empty vec4
1148
+ *
1149
+ * @returns {vec4} a new 4D vector
1150
+ */
1104
1151
  vec4.create = function() {
1105
1152
  var out = new GLMAT_ARRAY_TYPE(4);
1106
1153
  out[0] = 0;
@@ -1111,11 +1158,11 @@ vec4.create = function() {
1111
1158
  };
1112
1159
 
1113
1160
  /**
1114
- * Creates a new vec4 initialized with values from an existing vector
1115
- *
1116
- * @param {vec4} a vector to clone
1117
- * @returns {vec4} a new 4D vector
1118
- */
1161
+ * Creates a new vec4 initialized with values from an existing vector
1162
+ *
1163
+ * @param {vec4} a vector to clone
1164
+ * @returns {vec4} a new 4D vector
1165
+ */
1119
1166
  vec4.clone = function(a) {
1120
1167
  var out = new GLMAT_ARRAY_TYPE(4);
1121
1168
  out[0] = a[0];
@@ -1126,14 +1173,14 @@ vec4.clone = function(a) {
1126
1173
  };
1127
1174
 
1128
1175
  /**
1129
- * Creates a new vec4 initialized with the given values
1130
- *
1131
- * @param {Number} x X component
1132
- * @param {Number} y Y component
1133
- * @param {Number} z Z component
1134
- * @param {Number} w W component
1135
- * @returns {vec4} a new 4D vector
1136
- */
1176
+ * Creates a new vec4 initialized with the given values
1177
+ *
1178
+ * @param {Number} x X component
1179
+ * @param {Number} y Y component
1180
+ * @param {Number} z Z component
1181
+ * @param {Number} w W component
1182
+ * @returns {vec4} a new 4D vector
1183
+ */
1137
1184
  vec4.fromValues = function(x, y, z, w) {
1138
1185
  var out = new GLMAT_ARRAY_TYPE(4);
1139
1186
  out[0] = x;
@@ -1144,12 +1191,12 @@ vec4.fromValues = function(x, y, z, w) {
1144
1191
  };
1145
1192
 
1146
1193
  /**
1147
- * Copy the values from one vec4 to another
1148
- *
1149
- * @param {vec4} out the receiving vector
1150
- * @param {vec4} a the source vector
1151
- * @returns {vec4} out
1152
- */
1194
+ * Copy the values from one vec4 to another
1195
+ *
1196
+ * @param {vec4} out the receiving vector
1197
+ * @param {vec4} a the source vector
1198
+ * @returns {vec4} out
1199
+ */
1153
1200
  vec4.copy = function(out, a) {
1154
1201
  out[0] = a[0];
1155
1202
  out[1] = a[1];
@@ -1159,15 +1206,15 @@ vec4.copy = function(out, a) {
1159
1206
  };
1160
1207
 
1161
1208
  /**
1162
- * Set the components of a vec4 to the given values
1163
- *
1164
- * @param {vec4} out the receiving vector
1165
- * @param {Number} x X component
1166
- * @param {Number} y Y component
1167
- * @param {Number} z Z component
1168
- * @param {Number} w W component
1169
- * @returns {vec4} out
1170
- */
1209
+ * Set the components of a vec4 to the given values
1210
+ *
1211
+ * @param {vec4} out the receiving vector
1212
+ * @param {Number} x X component
1213
+ * @param {Number} y Y component
1214
+ * @param {Number} z Z component
1215
+ * @param {Number} w W component
1216
+ * @returns {vec4} out
1217
+ */
1171
1218
  vec4.set = function(out, x, y, z, w) {
1172
1219
  out[0] = x;
1173
1220
  out[1] = y;
@@ -1177,13 +1224,13 @@ vec4.set = function(out, x, y, z, w) {
1177
1224
  };
1178
1225
 
1179
1226
  /**
1180
- * Adds two vec4's
1181
- *
1182
- * @param {vec4} out the receiving vector
1183
- * @param {vec4} a the first operand
1184
- * @param {vec4} b the second operand
1185
- * @returns {vec4} out
1186
- */
1227
+ * Adds two vec4's
1228
+ *
1229
+ * @param {vec4} out the receiving vector
1230
+ * @param {vec4} a the first operand
1231
+ * @param {vec4} b the second operand
1232
+ * @returns {vec4} out
1233
+ */
1187
1234
  vec4.add = function(out, a, b) {
1188
1235
  out[0] = a[0] + b[0];
1189
1236
  out[1] = a[1] + b[1];
@@ -1193,13 +1240,13 @@ vec4.add = function(out, a, b) {
1193
1240
  };
1194
1241
 
1195
1242
  /**
1196
- * Subtracts two vec4's
1197
- *
1198
- * @param {vec4} out the receiving vector
1199
- * @param {vec4} a the first operand
1200
- * @param {vec4} b the second operand
1201
- * @returns {vec4} out
1202
- */
1243
+ * Subtracts vector b from vector a
1244
+ *
1245
+ * @param {vec4} out the receiving vector
1246
+ * @param {vec4} a the first operand
1247
+ * @param {vec4} b the second operand
1248
+ * @returns {vec4} out
1249
+ */
1203
1250
  vec4.subtract = function(out, a, b) {
1204
1251
  out[0] = a[0] - b[0];
1205
1252
  out[1] = a[1] - b[1];
@@ -1209,19 +1256,19 @@ vec4.subtract = function(out, a, b) {
1209
1256
  };
1210
1257
 
1211
1258
  /**
1212
- * Alias for {@link vec4.subtract}
1213
- * @function
1214
- */
1259
+ * Alias for {@link vec4.subtract}
1260
+ * @function
1261
+ */
1215
1262
  vec4.sub = vec4.subtract;
1216
1263
 
1217
1264
  /**
1218
- * Multiplies two vec4's
1219
- *
1220
- * @param {vec4} out the receiving vector
1221
- * @param {vec4} a the first operand
1222
- * @param {vec4} b the second operand
1223
- * @returns {vec4} out
1224
- */
1265
+ * Multiplies two vec4's
1266
+ *
1267
+ * @param {vec4} out the receiving vector
1268
+ * @param {vec4} a the first operand
1269
+ * @param {vec4} b the second operand
1270
+ * @returns {vec4} out
1271
+ */
1225
1272
  vec4.multiply = function(out, a, b) {
1226
1273
  out[0] = a[0] * b[0];
1227
1274
  out[1] = a[1] * b[1];
@@ -1231,19 +1278,19 @@ vec4.multiply = function(out, a, b) {
1231
1278
  };
1232
1279
 
1233
1280
  /**
1234
- * Alias for {@link vec4.multiply}
1235
- * @function
1236
- */
1281
+ * Alias for {@link vec4.multiply}
1282
+ * @function
1283
+ */
1237
1284
  vec4.mul = vec4.multiply;
1238
1285
 
1239
1286
  /**
1240
- * Divides two vec4's
1241
- *
1242
- * @param {vec4} out the receiving vector
1243
- * @param {vec4} a the first operand
1244
- * @param {vec4} b the second operand
1245
- * @returns {vec4} out
1246
- */
1287
+ * Divides two vec4's
1288
+ *
1289
+ * @param {vec4} out the receiving vector
1290
+ * @param {vec4} a the first operand
1291
+ * @param {vec4} b the second operand
1292
+ * @returns {vec4} out
1293
+ */
1247
1294
  vec4.divide = function(out, a, b) {
1248
1295
  out[0] = a[0] / b[0];
1249
1296
  out[1] = a[1] / b[1];
@@ -1253,19 +1300,19 @@ vec4.divide = function(out, a, b) {
1253
1300
  };
1254
1301
 
1255
1302
  /**
1256
- * Alias for {@link vec4.divide}
1257
- * @function
1258
- */
1303
+ * Alias for {@link vec4.divide}
1304
+ * @function
1305
+ */
1259
1306
  vec4.div = vec4.divide;
1260
1307
 
1261
1308
  /**
1262
- * Returns the minimum of two vec4's
1263
- *
1264
- * @param {vec4} out the receiving vector
1265
- * @param {vec4} a the first operand
1266
- * @param {vec4} b the second operand
1267
- * @returns {vec4} out
1268
- */
1309
+ * Returns the minimum of two vec4's
1310
+ *
1311
+ * @param {vec4} out the receiving vector
1312
+ * @param {vec4} a the first operand
1313
+ * @param {vec4} b the second operand
1314
+ * @returns {vec4} out
1315
+ */
1269
1316
  vec4.min = function(out, a, b) {
1270
1317
  out[0] = Math.min(a[0], b[0]);
1271
1318
  out[1] = Math.min(a[1], b[1]);
@@ -1275,13 +1322,13 @@ vec4.min = function(out, a, b) {
1275
1322
  };
1276
1323
 
1277
1324
  /**
1278
- * Returns the maximum of two vec4's
1279
- *
1280
- * @param {vec4} out the receiving vector
1281
- * @param {vec4} a the first operand
1282
- * @param {vec4} b the second operand
1283
- * @returns {vec4} out
1284
- */
1325
+ * Returns the maximum of two vec4's
1326
+ *
1327
+ * @param {vec4} out the receiving vector
1328
+ * @param {vec4} a the first operand
1329
+ * @param {vec4} b the second operand
1330
+ * @returns {vec4} out
1331
+ */
1285
1332
  vec4.max = function(out, a, b) {
1286
1333
  out[0] = Math.max(a[0], b[0]);
1287
1334
  out[1] = Math.max(a[1], b[1]);
@@ -1291,13 +1338,13 @@ vec4.max = function(out, a, b) {
1291
1338
  };
1292
1339
 
1293
1340
  /**
1294
- * Scales a vec4 by a scalar number
1295
- *
1296
- * @param {vec4} out the receiving vector
1297
- * @param {vec4} a the vector to scale
1298
- * @param {Number} b amount to scale the vector by
1299
- * @returns {vec4} out
1300
- */
1341
+ * Scales a vec4 by a scalar number
1342
+ *
1343
+ * @param {vec4} out the receiving vector
1344
+ * @param {vec4} a the vector to scale
1345
+ * @param {Number} b amount to scale the vector by
1346
+ * @returns {vec4} out
1347
+ */
1301
1348
  vec4.scale = function(out, a, b) {
1302
1349
  out[0] = a[0] * b;
1303
1350
  out[1] = a[1] * b;
@@ -1307,12 +1354,29 @@ vec4.scale = function(out, a, b) {
1307
1354
  };
1308
1355
 
1309
1356
  /**
1310
- * Calculates the euclidian distance between two vec4's
1311
- *
1312
- * @param {vec4} a the first operand
1313
- * @param {vec4} b the second operand
1314
- * @returns {Number} distance between a and b
1315
- */
1357
+ * Adds two vec4's after scaling the second operand by a scalar value
1358
+ *
1359
+ * @param {vec4} out the receiving vector
1360
+ * @param {vec4} a the first operand
1361
+ * @param {vec4} b the second operand
1362
+ * @param {Number} scale the amount to scale b by before adding
1363
+ * @returns {vec4} out
1364
+ */
1365
+ vec4.scaleAndAdd = function(out, a, b, scale) {
1366
+ out[0] = a[0] + (b[0] * scale);
1367
+ out[1] = a[1] + (b[1] * scale);
1368
+ out[2] = a[2] + (b[2] * scale);
1369
+ out[3] = a[3] + (b[3] * scale);
1370
+ return out;
1371
+ };
1372
+
1373
+ /**
1374
+ * Calculates the euclidian distance between two vec4's
1375
+ *
1376
+ * @param {vec4} a the first operand
1377
+ * @param {vec4} b the second operand
1378
+ * @returns {Number} distance between a and b
1379
+ */
1316
1380
  vec4.distance = function(a, b) {
1317
1381
  var x = b[0] - a[0],
1318
1382
  y = b[1] - a[1],
@@ -1322,18 +1386,18 @@ vec4.distance = function(a, b) {
1322
1386
  };
1323
1387
 
1324
1388
  /**
1325
- * Alias for {@link vec4.distance}
1326
- * @function
1327
- */
1389
+ * Alias for {@link vec4.distance}
1390
+ * @function
1391
+ */
1328
1392
  vec4.dist = vec4.distance;
1329
1393
 
1330
1394
  /**
1331
- * Calculates the squared euclidian distance between two vec4's
1332
- *
1333
- * @param {vec4} a the first operand
1334
- * @param {vec4} b the second operand
1335
- * @returns {Number} squared distance between a and b
1336
- */
1395
+ * Calculates the squared euclidian distance between two vec4's
1396
+ *
1397
+ * @param {vec4} a the first operand
1398
+ * @param {vec4} b the second operand
1399
+ * @returns {Number} squared distance between a and b
1400
+ */
1337
1401
  vec4.squaredDistance = function(a, b) {
1338
1402
  var x = b[0] - a[0],
1339
1403
  y = b[1] - a[1],
@@ -1343,17 +1407,17 @@ vec4.squaredDistance = function(a, b) {
1343
1407
  };
1344
1408
 
1345
1409
  /**
1346
- * Alias for {@link vec4.squaredDistance}
1347
- * @function
1348
- */
1410
+ * Alias for {@link vec4.squaredDistance}
1411
+ * @function
1412
+ */
1349
1413
  vec4.sqrDist = vec4.squaredDistance;
1350
1414
 
1351
1415
  /**
1352
- * Calculates the length of a vec4
1353
- *
1354
- * @param {vec4} a vector to calculate length of
1355
- * @returns {Number} length of a
1356
- */
1416
+ * Calculates the length of a vec4
1417
+ *
1418
+ * @param {vec4} a vector to calculate length of
1419
+ * @returns {Number} length of a
1420
+ */
1357
1421
  vec4.length = function (a) {
1358
1422
  var x = a[0],
1359
1423
  y = a[1],
@@ -1363,17 +1427,17 @@ vec4.length = function (a) {
1363
1427
  };
1364
1428
 
1365
1429
  /**
1366
- * Alias for {@link vec4.length}
1367
- * @function
1368
- */
1430
+ * Alias for {@link vec4.length}
1431
+ * @function
1432
+ */
1369
1433
  vec4.len = vec4.length;
1370
1434
 
1371
1435
  /**
1372
- * Calculates the squared length of a vec4
1373
- *
1374
- * @param {vec4} a vector to calculate squared length of
1375
- * @returns {Number} squared length of a
1376
- */
1436
+ * Calculates the squared length of a vec4
1437
+ *
1438
+ * @param {vec4} a vector to calculate squared length of
1439
+ * @returns {Number} squared length of a
1440
+ */
1377
1441
  vec4.squaredLength = function (a) {
1378
1442
  var x = a[0],
1379
1443
  y = a[1],
@@ -1383,18 +1447,18 @@ vec4.squaredLength = function (a) {
1383
1447
  };
1384
1448
 
1385
1449
  /**
1386
- * Alias for {@link vec4.squaredLength}
1387
- * @function
1388
- */
1450
+ * Alias for {@link vec4.squaredLength}
1451
+ * @function
1452
+ */
1389
1453
  vec4.sqrLen = vec4.squaredLength;
1390
1454
 
1391
1455
  /**
1392
- * Negates the components of a vec4
1393
- *
1394
- * @param {vec4} out the receiving vector
1395
- * @param {vec4} a vector to negate
1396
- * @returns {vec4} out
1397
- */
1456
+ * Negates the components of a vec4
1457
+ *
1458
+ * @param {vec4} out the receiving vector
1459
+ * @param {vec4} a vector to negate
1460
+ * @returns {vec4} out
1461
+ */
1398
1462
  vec4.negate = function(out, a) {
1399
1463
  out[0] = -a[0];
1400
1464
  out[1] = -a[1];
@@ -1404,12 +1468,12 @@ vec4.negate = function(out, a) {
1404
1468
  };
1405
1469
 
1406
1470
  /**
1407
- * Normalize a vec4
1408
- *
1409
- * @param {vec4} out the receiving vector
1410
- * @param {vec4} a vector to normalize
1411
- * @returns {vec4} out
1412
- */
1471
+ * Normalize a vec4
1472
+ *
1473
+ * @param {vec4} out the receiving vector
1474
+ * @param {vec4} a vector to normalize
1475
+ * @returns {vec4} out
1476
+ */
1413
1477
  vec4.normalize = function(out, a) {
1414
1478
  var x = a[0],
1415
1479
  y = a[1],
@@ -1427,25 +1491,25 @@ vec4.normalize = function(out, a) {
1427
1491
  };
1428
1492
 
1429
1493
  /**
1430
- * Calculates the dot product of two vec4's
1431
- *
1432
- * @param {vec4} a the first operand
1433
- * @param {vec4} b the second operand
1434
- * @returns {Number} dot product of a and b
1435
- */
1494
+ * Calculates the dot product of two vec4's
1495
+ *
1496
+ * @param {vec4} a the first operand
1497
+ * @param {vec4} b the second operand
1498
+ * @returns {Number} dot product of a and b
1499
+ */
1436
1500
  vec4.dot = function (a, b) {
1437
1501
  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
1438
1502
  };
1439
1503
 
1440
1504
  /**
1441
- * Performs a linear interpolation between two vec4's
1442
- *
1443
- * @param {vec4} out the receiving vector
1444
- * @param {vec4} a the first operand
1445
- * @param {vec4} b the second operand
1446
- * @param {Number} t interpolation amount between the two inputs
1447
- * @returns {vec4} out
1448
- */
1505
+ * Performs a linear interpolation between two vec4's
1506
+ *
1507
+ * @param {vec4} out the receiving vector
1508
+ * @param {vec4} a the first operand
1509
+ * @param {vec4} b the second operand
1510
+ * @param {Number} t interpolation amount between the two inputs
1511
+ * @returns {vec4} out
1512
+ */
1449
1513
  vec4.lerp = function (out, a, b, t) {
1450
1514
  var ax = a[0],
1451
1515
  ay = a[1],
@@ -1459,13 +1523,13 @@ vec4.lerp = function (out, a, b, t) {
1459
1523
  };
1460
1524
 
1461
1525
  /**
1462
- * Transforms the vec4 with a mat4.
1463
- *
1464
- * @param {vec4} out the receiving vector
1465
- * @param {vec4} a the vector to transform
1466
- * @param {mat4} m matrix to transform with
1467
- * @returns {vec4} out
1468
- */
1526
+ * Transforms the vec4 with a mat4.
1527
+ *
1528
+ * @param {vec4} out the receiving vector
1529
+ * @param {vec4} a the vector to transform
1530
+ * @param {mat4} m matrix to transform with
1531
+ * @returns {vec4} out
1532
+ */
1469
1533
  vec4.transformMat4 = function(out, a, m) {
1470
1534
  var x = a[0], y = a[1], z = a[2], w = a[3];
1471
1535
  out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
@@ -1476,13 +1540,13 @@ vec4.transformMat4 = function(out, a, m) {
1476
1540
  };
1477
1541
 
1478
1542
  /**
1479
- * Transforms the vec4 with a quat
1480
- *
1481
- * @param {vec4} out the receiving vector
1482
- * @param {vec4} a the vector to transform
1483
- * @param {quat} q quaternion to transform with
1484
- * @returns {vec4} out
1485
- */
1543
+ * Transforms the vec4 with a quat
1544
+ *
1545
+ * @param {vec4} out the receiving vector
1546
+ * @param {vec4} a the vector to transform
1547
+ * @param {quat} q quaternion to transform with
1548
+ * @returns {vec4} out
1549
+ */
1486
1550
  vec4.transformQuat = function(out, a, q) {
1487
1551
  var x = a[0], y = a[1], z = a[2],
1488
1552
  qx = q[0], qy = q[1], qz = q[2], qw = q[3],
@@ -1501,17 +1565,17 @@ vec4.transformQuat = function(out, a, q) {
1501
1565
  };
1502
1566
 
1503
1567
  /**
1504
- * Perform some operation over an array of vec4s.
1505
- *
1506
- * @param {Array} a the array of vectors to iterate over
1507
- * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
1508
- * @param {Number} offset Number of elements to skip at the beginning of the array
1509
- * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
1510
- * @param {Function} fn Function to call for each vector in the array
1511
- * @param {Object} [arg] additional argument to pass to fn
1512
- * @returns {Array} a
1513
- * @function
1514
- */
1568
+ * Perform some operation over an array of vec4s.
1569
+ *
1570
+ * @param {Array} a the array of vectors to iterate over
1571
+ * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
1572
+ * @param {Number} offset Number of elements to skip at the beginning of the array
1573
+ * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
1574
+ * @param {Function} fn Function to call for each vector in the array
1575
+ * @param {Object} [arg] additional argument to pass to fn
1576
+ * @returns {Array} a
1577
+ * @function
1578
+ */
1515
1579
  vec4.forEach = (function() {
1516
1580
  var vec = vec4.create();
1517
1581
 
@@ -1542,11 +1606,11 @@ vec4.forEach = (function() {
1542
1606
  })();
1543
1607
 
1544
1608
  /**
1545
- * Returns a string representation of a vector
1546
- *
1547
- * @param {vec4} vec vector to represent as a string
1548
- * @returns {String} string representation of the vector
1549
- */
1609
+ * Returns a string representation of a vector
1610
+ *
1611
+ * @param {vec4} vec vector to represent as a string
1612
+ * @returns {String} string representation of the vector
1613
+ */
1550
1614
  vec4.str = function (a) {
1551
1615
  return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
1552
1616
  };
@@ -1560,15 +1624,15 @@ if(typeof(exports) !== 'undefined') {
1560
1624
  Redistribution and use in source and binary forms, with or without modification,
1561
1625
  are permitted provided that the following conditions are met:
1562
1626
 
1563
- * Redistributions of source code must retain the above copyright notice, this
1564
- list of conditions and the following disclaimer.
1565
- * Redistributions in binary form must reproduce the above copyright notice,
1566
- this list of conditions and the following disclaimer in the documentation
1567
- and/or other materials provided with the distribution.
1627
+ * Redistributions of source code must retain the above copyright notice, this
1628
+ list of conditions and the following disclaimer.
1629
+ * Redistributions in binary form must reproduce the above copyright notice,
1630
+ this list of conditions and the following disclaimer in the documentation
1631
+ and/or other materials provided with the distribution.
1568
1632
 
1569
1633
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1570
1634
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1571
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1635
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1572
1636
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
1573
1637
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1574
1638
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -1578,22 +1642,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1578
1642
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
1579
1643
 
1580
1644
  /**
1581
- * @class 2x2 Matrix
1582
- * @name mat2
1583
- */
1645
+ * @class 2x2 Matrix
1646
+ * @name mat2
1647
+ */
1584
1648
 
1585
1649
  var mat2 = {};
1586
1650
 
1587
- var mat2Identity = new Float32Array([
1588
- 1, 0,
1589
- 0, 1
1590
- ]);
1591
-
1592
1651
  /**
1593
- * Creates a new identity mat2
1594
- *
1595
- * @returns {mat2} a new 2x2 matrix
1596
- */
1652
+ * Creates a new identity mat2
1653
+ *
1654
+ * @returns {mat2} a new 2x2 matrix
1655
+ */
1597
1656
  mat2.create = function() {
1598
1657
  var out = new GLMAT_ARRAY_TYPE(4);
1599
1658
  out[0] = 1;
@@ -1604,11 +1663,11 @@ mat2.create = function() {
1604
1663
  };
1605
1664
 
1606
1665
  /**
1607
- * Creates a new mat2 initialized with values from an existing matrix
1608
- *
1609
- * @param {mat2} a matrix to clone
1610
- * @returns {mat2} a new 2x2 matrix
1611
- */
1666
+ * Creates a new mat2 initialized with values from an existing matrix
1667
+ *
1668
+ * @param {mat2} a matrix to clone
1669
+ * @returns {mat2} a new 2x2 matrix
1670
+ */
1612
1671
  mat2.clone = function(a) {
1613
1672
  var out = new GLMAT_ARRAY_TYPE(4);
1614
1673
  out[0] = a[0];
@@ -1619,12 +1678,12 @@ mat2.clone = function(a) {
1619
1678
  };
1620
1679
 
1621
1680
  /**
1622
- * Copy the values from one mat2 to another
1623
- *
1624
- * @param {mat2} out the receiving matrix
1625
- * @param {mat2} a the source matrix
1626
- * @returns {mat2} out
1627
- */
1681
+ * Copy the values from one mat2 to another
1682
+ *
1683
+ * @param {mat2} out the receiving matrix
1684
+ * @param {mat2} a the source matrix
1685
+ * @returns {mat2} out
1686
+ */
1628
1687
  mat2.copy = function(out, a) {
1629
1688
  out[0] = a[0];
1630
1689
  out[1] = a[1];
@@ -1634,11 +1693,11 @@ mat2.copy = function(out, a) {
1634
1693
  };
1635
1694
 
1636
1695
  /**
1637
- * Set a mat2 to the identity matrix
1638
- *
1639
- * @param {mat2} out the receiving matrix
1640
- * @returns {mat2} out
1641
- */
1696
+ * Set a mat2 to the identity matrix
1697
+ *
1698
+ * @param {mat2} out the receiving matrix
1699
+ * @returns {mat2} out
1700
+ */
1642
1701
  mat2.identity = function(out) {
1643
1702
  out[0] = 1;
1644
1703
  out[1] = 0;
@@ -1648,12 +1707,12 @@ mat2.identity = function(out) {
1648
1707
  };
1649
1708
 
1650
1709
  /**
1651
- * Transpose the values of a mat2
1652
- *
1653
- * @param {mat2} out the receiving matrix
1654
- * @param {mat2} a the source matrix
1655
- * @returns {mat2} out
1656
- */
1710
+ * Transpose the values of a mat2
1711
+ *
1712
+ * @param {mat2} out the receiving matrix
1713
+ * @param {mat2} a the source matrix
1714
+ * @returns {mat2} out
1715
+ */
1657
1716
  mat2.transpose = function(out, a) {
1658
1717
  // If we are transposing ourselves we can skip a few steps but have to cache some values
1659
1718
  if (out === a) {
@@ -1671,12 +1730,12 @@ mat2.transpose = function(out, a) {
1671
1730
  };
1672
1731
 
1673
1732
  /**
1674
- * Inverts a mat2
1675
- *
1676
- * @param {mat2} out the receiving matrix
1677
- * @param {mat2} a the source matrix
1678
- * @returns {mat2} out
1679
- */
1733
+ * Inverts a mat2
1734
+ *
1735
+ * @param {mat2} out the receiving matrix
1736
+ * @param {mat2} a the source matrix
1737
+ * @returns {mat2} out
1738
+ */
1680
1739
  mat2.invert = function(out, a) {
1681
1740
  var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
1682
1741
 
@@ -1688,50 +1747,50 @@ mat2.invert = function(out, a) {
1688
1747
  }
1689
1748
  det = 1.0 / det;
1690
1749
 
1691
- out[0] = a3 * det;
1750
+ out[0] = a3 * det;
1692
1751
  out[1] = -a1 * det;
1693
1752
  out[2] = -a2 * det;
1694
- out[3] = a0 * det;
1753
+ out[3] = a0 * det;
1695
1754
 
1696
1755
  return out;
1697
1756
  };
1698
1757
 
1699
1758
  /**
1700
- * Calculates the adjugate of a mat2
1701
- *
1702
- * @param {mat2} out the receiving matrix
1703
- * @param {mat2} a the source matrix
1704
- * @returns {mat2} out
1705
- */
1759
+ * Calculates the adjugate of a mat2
1760
+ *
1761
+ * @param {mat2} out the receiving matrix
1762
+ * @param {mat2} a the source matrix
1763
+ * @returns {mat2} out
1764
+ */
1706
1765
  mat2.adjoint = function(out, a) {
1707
1766
  // Caching this value is nessecary if out == a
1708
1767
  var a0 = a[0];
1709
- out[0] = a[3];
1768
+ out[0] = a[3];
1710
1769
  out[1] = -a[1];
1711
1770
  out[2] = -a[2];
1712
- out[3] = a0;
1771
+ out[3] = a0;
1713
1772
 
1714
1773
  return out;
1715
1774
  };
1716
1775
 
1717
1776
  /**
1718
- * Calculates the determinant of a mat2
1719
- *
1720
- * @param {mat2} a the source matrix
1721
- * @returns {Number} determinant of a
1722
- */
1777
+ * Calculates the determinant of a mat2
1778
+ *
1779
+ * @param {mat2} a the source matrix
1780
+ * @returns {Number} determinant of a
1781
+ */
1723
1782
  mat2.determinant = function (a) {
1724
1783
  return a[0] * a[3] - a[2] * a[1];
1725
1784
  };
1726
1785
 
1727
1786
  /**
1728
- * Multiplies two mat2's
1729
- *
1730
- * @param {mat2} out the receiving matrix
1731
- * @param {mat2} a the first operand
1732
- * @param {mat2} b the second operand
1733
- * @returns {mat2} out
1734
- */
1787
+ * Multiplies two mat2's
1788
+ *
1789
+ * @param {mat2} out the receiving matrix
1790
+ * @param {mat2} a the first operand
1791
+ * @param {mat2} b the second operand
1792
+ * @returns {mat2} out
1793
+ */
1735
1794
  mat2.multiply = function (out, a, b) {
1736
1795
  var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
1737
1796
  var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
@@ -1743,38 +1802,38 @@ mat2.multiply = function (out, a, b) {
1743
1802
  };
1744
1803
 
1745
1804
  /**
1746
- * Alias for {@link mat2.multiply}
1747
- * @function
1748
- */
1805
+ * Alias for {@link mat2.multiply}
1806
+ * @function
1807
+ */
1749
1808
  mat2.mul = mat2.multiply;
1750
1809
 
1751
1810
  /**
1752
- * Rotates a mat2 by the given angle
1753
- *
1754
- * @param {mat2} out the receiving matrix
1755
- * @param {mat2} a the matrix to rotate
1756
- * @param {Number} rad the angle to rotate the matrix by
1757
- * @returns {mat2} out
1758
- */
1811
+ * Rotates a mat2 by the given angle
1812
+ *
1813
+ * @param {mat2} out the receiving matrix
1814
+ * @param {mat2} a the matrix to rotate
1815
+ * @param {Number} rad the angle to rotate the matrix by
1816
+ * @returns {mat2} out
1817
+ */
1759
1818
  mat2.rotate = function (out, a, rad) {
1760
1819
  var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
1761
1820
  s = Math.sin(rad),
1762
1821
  c = Math.cos(rad);
1763
- out[0] = a0 * c + a1 * s;
1822
+ out[0] = a0 * c + a1 * s;
1764
1823
  out[1] = a0 * -s + a1 * c;
1765
- out[2] = a2 * c + a3 * s;
1824
+ out[2] = a2 * c + a3 * s;
1766
1825
  out[3] = a2 * -s + a3 * c;
1767
1826
  return out;
1768
1827
  };
1769
1828
 
1770
1829
  /**
1771
- * Scales the mat2 by the dimensions in the given vec2
1772
- *
1773
- * @param {mat2} out the receiving matrix
1774
- * @param {mat2} a the matrix to rotate
1775
- * @param {vec2} v the vec2 to scale the matrix by
1776
- * @returns {mat2} out
1777
- **/
1830
+ * Scales the mat2 by the dimensions in the given vec2
1831
+ *
1832
+ * @param {mat2} out the receiving matrix
1833
+ * @param {mat2} a the matrix to rotate
1834
+ * @param {vec2} v the vec2 to scale the matrix by
1835
+ * @returns {mat2} out
1836
+ **/
1778
1837
  mat2.scale = function(out, a, v) {
1779
1838
  var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
1780
1839
  v0 = v[0], v1 = v[1];
@@ -1786,11 +1845,11 @@ mat2.scale = function(out, a, v) {
1786
1845
  };
1787
1846
 
1788
1847
  /**
1789
- * Returns a string representation of a mat2
1790
- *
1791
- * @param {mat2} mat matrix to represent as a string
1792
- * @returns {String} string representation of the matrix
1793
- */
1848
+ * Returns a string representation of a mat2
1849
+ *
1850
+ * @param {mat2} mat matrix to represent as a string
1851
+ * @returns {String} string representation of the matrix
1852
+ */
1794
1853
  mat2.str = function (a) {
1795
1854
  return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
1796
1855
  };
@@ -1804,15 +1863,15 @@ if(typeof(exports) !== 'undefined') {
1804
1863
  Redistribution and use in source and binary forms, with or without modification,
1805
1864
  are permitted provided that the following conditions are met:
1806
1865
 
1807
- * Redistributions of source code must retain the above copyright notice, this
1808
- list of conditions and the following disclaimer.
1809
- * Redistributions in binary form must reproduce the above copyright notice,
1810
- this list of conditions and the following disclaimer in the documentation
1811
- and/or other materials provided with the distribution.
1866
+ * Redistributions of source code must retain the above copyright notice, this
1867
+ list of conditions and the following disclaimer.
1868
+ * Redistributions in binary form must reproduce the above copyright notice,
1869
+ this list of conditions and the following disclaimer in the documentation
1870
+ and/or other materials provided with the distribution.
1812
1871
 
1813
1872
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1814
1873
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1815
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1874
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1816
1875
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
1817
1876
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1818
1877
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -1822,38 +1881,32 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1822
1881
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
1823
1882
 
1824
1883
  /**
1825
- * @class 2x3 Matrix
1826
- * @name mat2d
1827
- *
1828
- * @description
1829
- * A mat2d contains six elements defined as:
1830
- * <pre>
1831
- * [a, b,
1832
- * c, d,
1833
- * tx,ty]
1834
- * </pre>
1835
- * This is a short form for the 3x3 matrix:
1836
- * <pre>
1837
- * [a, b, 0
1838
- * c, d, 0
1839
- * tx,ty,1]
1840
- * </pre>
1841
- * The last column is ignored so the array is shorter and operations are faster.
1842
- */
1884
+ * @class 2x3 Matrix
1885
+ * @name mat2d
1886
+ *
1887
+ * @description
1888
+ * A mat2d contains six elements defined as:
1889
+ * <pre>
1890
+ * [a, b,
1891
+ * c, d,
1892
+ * tx,ty]
1893
+ * </pre>
1894
+ * This is a short form for the 3x3 matrix:
1895
+ * <pre>
1896
+ * [a, b, 0
1897
+ * c, d, 0
1898
+ * tx,ty,1]
1899
+ * </pre>
1900
+ * The last column is ignored so the array is shorter and operations are faster.
1901
+ */
1843
1902
 
1844
1903
  var mat2d = {};
1845
1904
 
1846
- var mat2dIdentity = new Float32Array([
1847
- 1, 0,
1848
- 0, 1,
1849
- 0, 0
1850
- ]);
1851
-
1852
1905
  /**
1853
- * Creates a new identity mat2d
1854
- *
1855
- * @returns {mat2d} a new 2x3 matrix
1856
- */
1906
+ * Creates a new identity mat2d
1907
+ *
1908
+ * @returns {mat2d} a new 2x3 matrix
1909
+ */
1857
1910
  mat2d.create = function() {
1858
1911
  var out = new GLMAT_ARRAY_TYPE(6);
1859
1912
  out[0] = 1;
@@ -1866,11 +1919,11 @@ mat2d.create = function() {
1866
1919
  };
1867
1920
 
1868
1921
  /**
1869
- * Creates a new mat2d initialized with values from an existing matrix
1870
- *
1871
- * @param {mat2d} a matrix to clone
1872
- * @returns {mat2d} a new 2x3 matrix
1873
- */
1922
+ * Creates a new mat2d initialized with values from an existing matrix
1923
+ *
1924
+ * @param {mat2d} a matrix to clone
1925
+ * @returns {mat2d} a new 2x3 matrix
1926
+ */
1874
1927
  mat2d.clone = function(a) {
1875
1928
  var out = new GLMAT_ARRAY_TYPE(6);
1876
1929
  out[0] = a[0];
@@ -1883,12 +1936,12 @@ mat2d.clone = function(a) {
1883
1936
  };
1884
1937
 
1885
1938
  /**
1886
- * Copy the values from one mat2d to another
1887
- *
1888
- * @param {mat2d} out the receiving matrix
1889
- * @param {mat2d} a the source matrix
1890
- * @returns {mat2d} out
1891
- */
1939
+ * Copy the values from one mat2d to another
1940
+ *
1941
+ * @param {mat2d} out the receiving matrix
1942
+ * @param {mat2d} a the source matrix
1943
+ * @returns {mat2d} out
1944
+ */
1892
1945
  mat2d.copy = function(out, a) {
1893
1946
  out[0] = a[0];
1894
1947
  out[1] = a[1];
@@ -1900,11 +1953,11 @@ mat2d.copy = function(out, a) {
1900
1953
  };
1901
1954
 
1902
1955
  /**
1903
- * Set a mat2d to the identity matrix
1904
- *
1905
- * @param {mat2d} out the receiving matrix
1906
- * @returns {mat2d} out
1907
- */
1956
+ * Set a mat2d to the identity matrix
1957
+ *
1958
+ * @param {mat2d} out the receiving matrix
1959
+ * @returns {mat2d} out
1960
+ */
1908
1961
  mat2d.identity = function(out) {
1909
1962
  out[0] = 1;
1910
1963
  out[1] = 0;
@@ -1916,12 +1969,12 @@ mat2d.identity = function(out) {
1916
1969
  };
1917
1970
 
1918
1971
  /**
1919
- * Inverts a mat2d
1920
- *
1921
- * @param {mat2d} out the receiving matrix
1922
- * @param {mat2d} a the source matrix
1923
- * @returns {mat2d} out
1924
- */
1972
+ * Inverts a mat2d
1973
+ *
1974
+ * @param {mat2d} out the receiving matrix
1975
+ * @param {mat2d} a the source matrix
1976
+ * @returns {mat2d} out
1977
+ */
1925
1978
  mat2d.invert = function(out, a) {
1926
1979
  var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
1927
1980
  atx = a[4], aty = a[5];
@@ -1942,23 +1995,23 @@ mat2d.invert = function(out, a) {
1942
1995
  };
1943
1996
 
1944
1997
  /**
1945
- * Calculates the determinant of a mat2d
1946
- *
1947
- * @param {mat2d} a the source matrix
1948
- * @returns {Number} determinant of a
1949
- */
1998
+ * Calculates the determinant of a mat2d
1999
+ *
2000
+ * @param {mat2d} a the source matrix
2001
+ * @returns {Number} determinant of a
2002
+ */
1950
2003
  mat2d.determinant = function (a) {
1951
2004
  return a[0] * a[3] - a[1] * a[2];
1952
2005
  };
1953
2006
 
1954
2007
  /**
1955
- * Multiplies two mat2d's
1956
- *
1957
- * @param {mat2d} out the receiving matrix
1958
- * @param {mat2d} a the first operand
1959
- * @param {mat2d} b the second operand
1960
- * @returns {mat2d} out
1961
- */
2008
+ * Multiplies two mat2d's
2009
+ *
2010
+ * @param {mat2d} out the receiving matrix
2011
+ * @param {mat2d} a the first operand
2012
+ * @param {mat2d} b the second operand
2013
+ * @returns {mat2d} out
2014
+ */
1962
2015
  mat2d.multiply = function (out, a, b) {
1963
2016
  var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
1964
2017
  atx = a[4], aty = a[5],
@@ -1975,20 +2028,20 @@ mat2d.multiply = function (out, a, b) {
1975
2028
  };
1976
2029
 
1977
2030
  /**
1978
- * Alias for {@link mat2d.multiply}
1979
- * @function
1980
- */
2031
+ * Alias for {@link mat2d.multiply}
2032
+ * @function
2033
+ */
1981
2034
  mat2d.mul = mat2d.multiply;
1982
2035
 
1983
2036
 
1984
2037
  /**
1985
- * Rotates a mat2d by the given angle
1986
- *
1987
- * @param {mat2d} out the receiving matrix
1988
- * @param {mat2d} a the matrix to rotate
1989
- * @param {Number} rad the angle to rotate the matrix by
1990
- * @returns {mat2d} out
1991
- */
2038
+ * Rotates a mat2d by the given angle
2039
+ *
2040
+ * @param {mat2d} out the receiving matrix
2041
+ * @param {mat2d} a the matrix to rotate
2042
+ * @param {Number} rad the angle to rotate the matrix by
2043
+ * @returns {mat2d} out
2044
+ */
1992
2045
  mat2d.rotate = function (out, a, rad) {
1993
2046
  var aa = a[0],
1994
2047
  ab = a[1],
@@ -2009,13 +2062,13 @@ mat2d.rotate = function (out, a, rad) {
2009
2062
  };
2010
2063
 
2011
2064
  /**
2012
- * Scales the mat2d by the dimensions in the given vec2
2013
- *
2014
- * @param {mat2d} out the receiving matrix
2015
- * @param {mat2d} a the matrix to translate
2016
- * @param {mat2d} v the vec2 to scale the matrix by
2017
- * @returns {mat2d} out
2018
- **/
2065
+ * Scales the mat2d by the dimensions in the given vec2
2066
+ *
2067
+ * @param {mat2d} out the receiving matrix
2068
+ * @param {mat2d} a the matrix to translate
2069
+ * @param {vec2} v the vec2 to scale the matrix by
2070
+ * @returns {mat2d} out
2071
+ **/
2019
2072
  mat2d.scale = function(out, a, v) {
2020
2073
  var vx = v[0], vy = v[1];
2021
2074
  out[0] = a[0] * vx;
@@ -2028,13 +2081,13 @@ mat2d.scale = function(out, a, v) {
2028
2081
  };
2029
2082
 
2030
2083
  /**
2031
- * Translates the mat2d by the dimensions in the given vec2
2032
- *
2033
- * @param {mat2d} out the receiving matrix
2034
- * @param {mat2d} a the matrix to translate
2035
- * @param {mat2d} v the vec2 to translate the matrix by
2036
- * @returns {mat2d} out
2037
- **/
2084
+ * Translates the mat2d by the dimensions in the given vec2
2085
+ *
2086
+ * @param {mat2d} out the receiving matrix
2087
+ * @param {mat2d} a the matrix to translate
2088
+ * @param {vec2} v the vec2 to translate the matrix by
2089
+ * @returns {mat2d} out
2090
+ **/
2038
2091
  mat2d.translate = function(out, a, v) {
2039
2092
  out[0] = a[0];
2040
2093
  out[1] = a[1];
@@ -2046,13 +2099,13 @@ mat2d.translate = function(out, a, v) {
2046
2099
  };
2047
2100
 
2048
2101
  /**
2049
- * Returns a string representation of a mat2d
2050
- *
2051
- * @param {mat2d} a matrix to represent as a string
2052
- * @returns {String} string representation of the matrix
2053
- */
2102
+ * Returns a string representation of a mat2d
2103
+ *
2104
+ * @param {mat2d} a matrix to represent as a string
2105
+ * @returns {String} string representation of the matrix
2106
+ */
2054
2107
  mat2d.str = function (a) {
2055
- return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
2108
+ return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
2056
2109
  a[3] + ', ' + a[4] + ', ' + a[5] + ')';
2057
2110
  };
2058
2111
 
@@ -2065,15 +2118,15 @@ if(typeof(exports) !== 'undefined') {
2065
2118
  Redistribution and use in source and binary forms, with or without modification,
2066
2119
  are permitted provided that the following conditions are met:
2067
2120
 
2068
- * Redistributions of source code must retain the above copyright notice, this
2069
- list of conditions and the following disclaimer.
2070
- * Redistributions in binary form must reproduce the above copyright notice,
2071
- this list of conditions and the following disclaimer in the documentation
2072
- and/or other materials provided with the distribution.
2121
+ * Redistributions of source code must retain the above copyright notice, this
2122
+ list of conditions and the following disclaimer.
2123
+ * Redistributions in binary form must reproduce the above copyright notice,
2124
+ this list of conditions and the following disclaimer in the documentation
2125
+ and/or other materials provided with the distribution.
2073
2126
 
2074
2127
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2075
2128
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2076
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2129
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2077
2130
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
2078
2131
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2079
2132
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -2083,23 +2136,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2083
2136
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
2084
2137
 
2085
2138
  /**
2086
- * @class 3x3 Matrix
2087
- * @name mat3
2088
- */
2139
+ * @class 3x3 Matrix
2140
+ * @name mat3
2141
+ */
2089
2142
 
2090
2143
  var mat3 = {};
2091
2144
 
2092
- var mat3Identity = new Float32Array([
2093
- 1, 0, 0,
2094
- 0, 1, 0,
2095
- 0, 0, 1
2096
- ]);
2097
-
2098
2145
  /**
2099
- * Creates a new identity mat3
2100
- *
2101
- * @returns {mat3} a new 3x3 matrix
2102
- */
2146
+ * Creates a new identity mat3
2147
+ *
2148
+ * @returns {mat3} a new 3x3 matrix
2149
+ */
2103
2150
  mat3.create = function() {
2104
2151
  var out = new GLMAT_ARRAY_TYPE(9);
2105
2152
  out[0] = 1;
@@ -2115,11 +2162,31 @@ mat3.create = function() {
2115
2162
  };
2116
2163
 
2117
2164
  /**
2118
- * Creates a new mat3 initialized with values from an existing matrix
2119
- *
2120
- * @param {mat3} a matrix to clone
2121
- * @returns {mat3} a new 3x3 matrix
2122
- */
2165
+ * Copies the upper-left 3x3 values into the given mat3.
2166
+ *
2167
+ * @param {mat3} out the receiving 3x3 matrix
2168
+ * @param {mat4} a the source 4x4 matrix
2169
+ * @returns {mat3} out
2170
+ */
2171
+ mat3.fromMat4 = function(out, a) {
2172
+ out[0] = a[0];
2173
+ out[1] = a[1];
2174
+ out[2] = a[2];
2175
+ out[3] = a[4];
2176
+ out[4] = a[5];
2177
+ out[5] = a[6];
2178
+ out[6] = a[8];
2179
+ out[7] = a[9];
2180
+ out[8] = a[10];
2181
+ return out;
2182
+ };
2183
+
2184
+ /**
2185
+ * Creates a new mat3 initialized with values from an existing matrix
2186
+ *
2187
+ * @param {mat3} a matrix to clone
2188
+ * @returns {mat3} a new 3x3 matrix
2189
+ */
2123
2190
  mat3.clone = function(a) {
2124
2191
  var out = new GLMAT_ARRAY_TYPE(9);
2125
2192
  out[0] = a[0];
@@ -2135,12 +2202,12 @@ mat3.clone = function(a) {
2135
2202
  };
2136
2203
 
2137
2204
  /**
2138
- * Copy the values from one mat3 to another
2139
- *
2140
- * @param {mat3} out the receiving matrix
2141
- * @param {mat3} a the source matrix
2142
- * @returns {mat3} out
2143
- */
2205
+ * Copy the values from one mat3 to another
2206
+ *
2207
+ * @param {mat3} out the receiving matrix
2208
+ * @param {mat3} a the source matrix
2209
+ * @returns {mat3} out
2210
+ */
2144
2211
  mat3.copy = function(out, a) {
2145
2212
  out[0] = a[0];
2146
2213
  out[1] = a[1];
@@ -2155,11 +2222,11 @@ mat3.copy = function(out, a) {
2155
2222
  };
2156
2223
 
2157
2224
  /**
2158
- * Set a mat3 to the identity matrix
2159
- *
2160
- * @param {mat3} out the receiving matrix
2161
- * @returns {mat3} out
2162
- */
2225
+ * Set a mat3 to the identity matrix
2226
+ *
2227
+ * @param {mat3} out the receiving matrix
2228
+ * @returns {mat3} out
2229
+ */
2163
2230
  mat3.identity = function(out) {
2164
2231
  out[0] = 1;
2165
2232
  out[1] = 0;
@@ -2174,12 +2241,12 @@ mat3.identity = function(out) {
2174
2241
  };
2175
2242
 
2176
2243
  /**
2177
- * Transpose the values of a mat3
2178
- *
2179
- * @param {mat3} out the receiving matrix
2180
- * @param {mat3} a the source matrix
2181
- * @returns {mat3} out
2182
- */
2244
+ * Transpose the values of a mat3
2245
+ *
2246
+ * @param {mat3} out the receiving matrix
2247
+ * @param {mat3} a the source matrix
2248
+ * @returns {mat3} out
2249
+ */
2183
2250
  mat3.transpose = function(out, a) {
2184
2251
  // If we are transposing ourselves we can skip a few steps but have to cache some values
2185
2252
  if (out === a) {
@@ -2206,12 +2273,12 @@ mat3.transpose = function(out, a) {
2206
2273
  };
2207
2274
 
2208
2275
  /**
2209
- * Inverts a mat3
2210
- *
2211
- * @param {mat3} out the receiving matrix
2212
- * @param {mat3} a the source matrix
2213
- * @returns {mat3} out
2214
- */
2276
+ * Inverts a mat3
2277
+ *
2278
+ * @param {mat3} out the receiving matrix
2279
+ * @param {mat3} a the source matrix
2280
+ * @returns {mat3} out
2281
+ */
2215
2282
  mat3.invert = function(out, a) {
2216
2283
  var a00 = a[0], a01 = a[1], a02 = a[2],
2217
2284
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2224,8 +2291,8 @@ mat3.invert = function(out, a) {
2224
2291
  // Calculate the determinant
2225
2292
  det = a00 * b01 + a01 * b11 + a02 * b21;
2226
2293
 
2227
- if (!det) {
2228
- return null;
2294
+ if (!det) {
2295
+ return null;
2229
2296
  }
2230
2297
  det = 1.0 / det;
2231
2298
 
@@ -2242,12 +2309,12 @@ mat3.invert = function(out, a) {
2242
2309
  };
2243
2310
 
2244
2311
  /**
2245
- * Calculates the adjugate of a mat3
2246
- *
2247
- * @param {mat3} out the receiving matrix
2248
- * @param {mat3} a the source matrix
2249
- * @returns {mat3} out
2250
- */
2312
+ * Calculates the adjugate of a mat3
2313
+ *
2314
+ * @param {mat3} out the receiving matrix
2315
+ * @param {mat3} a the source matrix
2316
+ * @returns {mat3} out
2317
+ */
2251
2318
  mat3.adjoint = function(out, a) {
2252
2319
  var a00 = a[0], a01 = a[1], a02 = a[2],
2253
2320
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2266,11 +2333,11 @@ mat3.adjoint = function(out, a) {
2266
2333
  };
2267
2334
 
2268
2335
  /**
2269
- * Calculates the determinant of a mat3
2270
- *
2271
- * @param {mat3} a the source matrix
2272
- * @returns {Number} determinant of a
2273
- */
2336
+ * Calculates the determinant of a mat3
2337
+ *
2338
+ * @param {mat3} a the source matrix
2339
+ * @returns {Number} determinant of a
2340
+ */
2274
2341
  mat3.determinant = function (a) {
2275
2342
  var a00 = a[0], a01 = a[1], a02 = a[2],
2276
2343
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2280,13 +2347,13 @@ mat3.determinant = function (a) {
2280
2347
  };
2281
2348
 
2282
2349
  /**
2283
- * Multiplies two mat3's
2284
- *
2285
- * @param {mat3} out the receiving matrix
2286
- * @param {mat3} a the first operand
2287
- * @param {mat3} b the second operand
2288
- * @returns {mat3} out
2289
- */
2350
+ * Multiplies two mat3's
2351
+ *
2352
+ * @param {mat3} out the receiving matrix
2353
+ * @param {mat3} a the first operand
2354
+ * @param {mat3} b the second operand
2355
+ * @returns {mat3} out
2356
+ */
2290
2357
  mat3.multiply = function (out, a, b) {
2291
2358
  var a00 = a[0], a01 = a[1], a02 = a[2],
2292
2359
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2311,19 +2378,19 @@ mat3.multiply = function (out, a, b) {
2311
2378
  };
2312
2379
 
2313
2380
  /**
2314
- * Alias for {@link mat3.multiply}
2315
- * @function
2316
- */
2381
+ * Alias for {@link mat3.multiply}
2382
+ * @function
2383
+ */
2317
2384
  mat3.mul = mat3.multiply;
2318
2385
 
2319
2386
  /**
2320
- * Translate a mat3 by the given vector
2321
- *
2322
- * @param {mat3} out the receiving matrix
2323
- * @param {mat3} a the matrix to translate
2324
- * @param {vec2} v vector to translate by
2325
- * @returns {mat3} out
2326
- */
2387
+ * Translate a mat3 by the given vector
2388
+ *
2389
+ * @param {mat3} out the receiving matrix
2390
+ * @param {mat3} a the matrix to translate
2391
+ * @param {vec2} v vector to translate by
2392
+ * @returns {mat3} out
2393
+ */
2327
2394
  mat3.translate = function(out, a, v) {
2328
2395
  var a00 = a[0], a01 = a[1], a02 = a[2],
2329
2396
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2345,13 +2412,13 @@ mat3.translate = function(out, a, v) {
2345
2412
  };
2346
2413
 
2347
2414
  /**
2348
- * Rotates a mat3 by the given angle
2349
- *
2350
- * @param {mat3} out the receiving matrix
2351
- * @param {mat3} a the matrix to rotate
2352
- * @param {Number} rad the angle to rotate the matrix by
2353
- * @returns {mat3} out
2354
- */
2415
+ * Rotates a mat3 by the given angle
2416
+ *
2417
+ * @param {mat3} out the receiving matrix
2418
+ * @param {mat3} a the matrix to rotate
2419
+ * @param {Number} rad the angle to rotate the matrix by
2420
+ * @returns {mat3} out
2421
+ */
2355
2422
  mat3.rotate = function (out, a, rad) {
2356
2423
  var a00 = a[0], a01 = a[1], a02 = a[2],
2357
2424
  a10 = a[3], a11 = a[4], a12 = a[5],
@@ -2375,15 +2442,15 @@ mat3.rotate = function (out, a, rad) {
2375
2442
  };
2376
2443
 
2377
2444
  /**
2378
- * Scales the mat3 by the dimensions in the given vec2
2379
- *
2380
- * @param {mat3} out the receiving matrix
2381
- * @param {mat3} a the matrix to rotate
2382
- * @param {vec2} v the vec2 to scale the matrix by
2383
- * @returns {mat3} out
2384
- **/
2445
+ * Scales the mat3 by the dimensions in the given vec2
2446
+ *
2447
+ * @param {mat3} out the receiving matrix
2448
+ * @param {mat3} a the matrix to rotate
2449
+ * @param {vec2} v the vec2 to scale the matrix by
2450
+ * @returns {mat3} out
2451
+ **/
2385
2452
  mat3.scale = function(out, a, v) {
2386
- var x = v[0], y = v[2];
2453
+ var x = v[0], y = v[1];
2387
2454
 
2388
2455
  out[0] = x * a[0];
2389
2456
  out[1] = x * a[1];
@@ -2400,13 +2467,12 @@ mat3.scale = function(out, a, v) {
2400
2467
  };
2401
2468
 
2402
2469
  /**
2403
- * Copies the values from a mat2d into a mat3
2404
- *
2405
- * @param {mat3} out the receiving matrix
2406
- * @param {mat3} a the matrix to rotate
2407
- * @param {vec2} v the vec2 to scale the matrix by
2408
- * @returns {mat3} out
2409
- **/
2470
+ * Copies the values from a mat2d into a mat3
2471
+ *
2472
+ * @param {mat3} out the receiving matrix
2473
+ * @param {mat2d} a the matrix to copy
2474
+ * @returns {mat3} out
2475
+ **/
2410
2476
  mat3.fromMat2d = function(out, a) {
2411
2477
  out[0] = a[0];
2412
2478
  out[1] = a[1];
@@ -2462,14 +2528,14 @@ mat3.fromQuat = function (out, q) {
2462
2528
  };
2463
2529
 
2464
2530
  /**
2465
- * Returns a string representation of a mat3
2466
- *
2467
- * @param {mat3} mat matrix to represent as a string
2468
- * @returns {String} string representation of the matrix
2469
- */
2531
+ * Returns a string representation of a mat3
2532
+ *
2533
+ * @param {mat3} mat matrix to represent as a string
2534
+ * @returns {String} string representation of the matrix
2535
+ */
2470
2536
  mat3.str = function (a) {
2471
- return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
2472
- a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
2537
+ return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
2538
+ a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
2473
2539
  a[6] + ', ' + a[7] + ', ' + a[8] + ')';
2474
2540
  };
2475
2541
 
@@ -2482,15 +2548,15 @@ if(typeof(exports) !== 'undefined') {
2482
2548
  Redistribution and use in source and binary forms, with or without modification,
2483
2549
  are permitted provided that the following conditions are met:
2484
2550
 
2485
- * Redistributions of source code must retain the above copyright notice, this
2486
- list of conditions and the following disclaimer.
2487
- * Redistributions in binary form must reproduce the above copyright notice,
2488
- this list of conditions and the following disclaimer in the documentation
2489
- and/or other materials provided with the distribution.
2551
+ * Redistributions of source code must retain the above copyright notice, this
2552
+ list of conditions and the following disclaimer.
2553
+ * Redistributions in binary form must reproduce the above copyright notice,
2554
+ this list of conditions and the following disclaimer in the documentation
2555
+ and/or other materials provided with the distribution.
2490
2556
 
2491
2557
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
2492
2558
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2493
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2559
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2494
2560
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
2495
2561
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2496
2562
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -2500,24 +2566,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2500
2566
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
2501
2567
 
2502
2568
  /**
2503
- * @class 4x4 Matrix
2504
- * @name mat4
2505
- */
2569
+ * @class 4x4 Matrix
2570
+ * @name mat4
2571
+ */
2506
2572
 
2507
2573
  var mat4 = {};
2508
2574
 
2509
- var mat4Identity = new Float32Array([
2510
- 1, 0, 0, 0,
2511
- 0, 1, 0, 0,
2512
- 0, 0, 1, 0,
2513
- 0, 0, 0, 1
2514
- ]);
2515
-
2516
2575
  /**
2517
- * Creates a new identity mat4
2518
- *
2519
- * @returns {mat4} a new 4x4 matrix
2520
- */
2576
+ * Creates a new identity mat4
2577
+ *
2578
+ * @returns {mat4} a new 4x4 matrix
2579
+ */
2521
2580
  mat4.create = function() {
2522
2581
  var out = new GLMAT_ARRAY_TYPE(16);
2523
2582
  out[0] = 1;
@@ -2540,11 +2599,11 @@ mat4.create = function() {
2540
2599
  };
2541
2600
 
2542
2601
  /**
2543
- * Creates a new mat4 initialized with values from an existing matrix
2544
- *
2545
- * @param {mat4} a matrix to clone
2546
- * @returns {mat4} a new 4x4 matrix
2547
- */
2602
+ * Creates a new mat4 initialized with values from an existing matrix
2603
+ *
2604
+ * @param {mat4} a matrix to clone
2605
+ * @returns {mat4} a new 4x4 matrix
2606
+ */
2548
2607
  mat4.clone = function(a) {
2549
2608
  var out = new GLMAT_ARRAY_TYPE(16);
2550
2609
  out[0] = a[0];
@@ -2567,12 +2626,12 @@ mat4.clone = function(a) {
2567
2626
  };
2568
2627
 
2569
2628
  /**
2570
- * Copy the values from one mat4 to another
2571
- *
2572
- * @param {mat4} out the receiving matrix
2573
- * @param {mat4} a the source matrix
2574
- * @returns {mat4} out
2575
- */
2629
+ * Copy the values from one mat4 to another
2630
+ *
2631
+ * @param {mat4} out the receiving matrix
2632
+ * @param {mat4} a the source matrix
2633
+ * @returns {mat4} out
2634
+ */
2576
2635
  mat4.copy = function(out, a) {
2577
2636
  out[0] = a[0];
2578
2637
  out[1] = a[1];
@@ -2594,11 +2653,11 @@ mat4.copy = function(out, a) {
2594
2653
  };
2595
2654
 
2596
2655
  /**
2597
- * Set a mat4 to the identity matrix
2598
- *
2599
- * @param {mat4} out the receiving matrix
2600
- * @returns {mat4} out
2601
- */
2656
+ * Set a mat4 to the identity matrix
2657
+ *
2658
+ * @param {mat4} out the receiving matrix
2659
+ * @returns {mat4} out
2660
+ */
2602
2661
  mat4.identity = function(out) {
2603
2662
  out[0] = 1;
2604
2663
  out[1] = 0;
@@ -2620,12 +2679,12 @@ mat4.identity = function(out) {
2620
2679
  };
2621
2680
 
2622
2681
  /**
2623
- * Transpose the values of a mat4
2624
- *
2625
- * @param {mat4} out the receiving matrix
2626
- * @param {mat4} a the source matrix
2627
- * @returns {mat4} out
2628
- */
2682
+ * Transpose the values of a mat4
2683
+ *
2684
+ * @param {mat4} out the receiving matrix
2685
+ * @param {mat4} a the source matrix
2686
+ * @returns {mat4} out
2687
+ */
2629
2688
  mat4.transpose = function(out, a) {
2630
2689
  // If we are transposing ourselves we can skip a few steps but have to cache some values
2631
2690
  if (out === a) {
@@ -2668,12 +2727,12 @@ mat4.transpose = function(out, a) {
2668
2727
  };
2669
2728
 
2670
2729
  /**
2671
- * Inverts a mat4
2672
- *
2673
- * @param {mat4} out the receiving matrix
2674
- * @param {mat4} a the source matrix
2675
- * @returns {mat4} out
2676
- */
2730
+ * Inverts a mat4
2731
+ *
2732
+ * @param {mat4} out the receiving matrix
2733
+ * @param {mat4} a the source matrix
2734
+ * @returns {mat4} out
2735
+ */
2677
2736
  mat4.invert = function(out, a) {
2678
2737
  var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
2679
2738
  a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
@@ -2696,8 +2755,8 @@ mat4.invert = function(out, a) {
2696
2755
  // Calculate the determinant
2697
2756
  det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
2698
2757
 
2699
- if (!det) {
2700
- return null;
2758
+ if (!det) {
2759
+ return null;
2701
2760
  }
2702
2761
  det = 1.0 / det;
2703
2762
 
@@ -2722,43 +2781,43 @@ mat4.invert = function(out, a) {
2722
2781
  };
2723
2782
 
2724
2783
  /**
2725
- * Calculates the adjugate of a mat4
2726
- *
2727
- * @param {mat4} out the receiving matrix
2728
- * @param {mat4} a the source matrix
2729
- * @returns {mat4} out
2730
- */
2784
+ * Calculates the adjugate of a mat4
2785
+ *
2786
+ * @param {mat4} out the receiving matrix
2787
+ * @param {mat4} a the source matrix
2788
+ * @returns {mat4} out
2789
+ */
2731
2790
  mat4.adjoint = function(out, a) {
2732
2791
  var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
2733
2792
  a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
2734
2793
  a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
2735
2794
  a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
2736
2795
 
2737
- out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
2738
- out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
2739
- out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
2740
- out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
2741
- out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
2742
- out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
2743
- out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
2744
- out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
2745
- out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
2746
- out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
2747
- out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
2796
+ out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
2797
+ out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
2798
+ out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
2799
+ out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
2800
+ out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
2801
+ out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
2802
+ out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
2803
+ out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
2804
+ out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
2805
+ out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
2806
+ out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
2748
2807
  out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
2749
2808
  out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
2750
- out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
2809
+ out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
2751
2810
  out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
2752
- out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
2811
+ out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
2753
2812
  return out;
2754
2813
  };
2755
2814
 
2756
2815
  /**
2757
- * Calculates the determinant of a mat4
2758
- *
2759
- * @param {mat4} a the source matrix
2760
- * @returns {Number} determinant of a
2761
- */
2816
+ * Calculates the determinant of a mat4
2817
+ *
2818
+ * @param {mat4} a the source matrix
2819
+ * @returns {Number} determinant of a
2820
+ */
2762
2821
  mat4.determinant = function (a) {
2763
2822
  var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
2764
2823
  a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
@@ -2783,13 +2842,13 @@ mat4.determinant = function (a) {
2783
2842
  };
2784
2843
 
2785
2844
  /**
2786
- * Multiplies two mat4's
2787
- *
2788
- * @param {mat4} out the receiving matrix
2789
- * @param {mat4} a the first operand
2790
- * @param {mat4} b the second operand
2791
- * @returns {mat4} out
2792
- */
2845
+ * Multiplies two mat4's
2846
+ *
2847
+ * @param {mat4} out the receiving matrix
2848
+ * @param {mat4} a the first operand
2849
+ * @param {mat4} b the second operand
2850
+ * @returns {mat4} out
2851
+ */
2793
2852
  mat4.multiply = function (out, a, b) {
2794
2853
  var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
2795
2854
  a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
@@ -2797,7 +2856,7 @@ mat4.multiply = function (out, a, b) {
2797
2856
  a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
2798
2857
 
2799
2858
  // Cache only the current line of the second matrix
2800
- var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
2859
+ var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
2801
2860
  out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
2802
2861
  out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
2803
2862
  out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
@@ -2824,19 +2883,19 @@ mat4.multiply = function (out, a, b) {
2824
2883
  };
2825
2884
 
2826
2885
  /**
2827
- * Alias for {@link mat4.multiply}
2828
- * @function
2829
- */
2886
+ * Alias for {@link mat4.multiply}
2887
+ * @function
2888
+ */
2830
2889
  mat4.mul = mat4.multiply;
2831
2890
 
2832
2891
  /**
2833
- * Translate a mat4 by the given vector
2834
- *
2835
- * @param {mat4} out the receiving matrix
2836
- * @param {mat4} a the matrix to translate
2837
- * @param {vec3} v vector to translate by
2838
- * @returns {mat4} out
2839
- */
2892
+ * Translate a mat4 by the given vector
2893
+ *
2894
+ * @param {mat4} out the receiving matrix
2895
+ * @param {mat4} a the matrix to translate
2896
+ * @param {vec3} v vector to translate by
2897
+ * @returns {mat4} out
2898
+ */
2840
2899
  mat4.translate = function (out, a, v) {
2841
2900
  var x = v[0], y = v[1], z = v[2],
2842
2901
  a00, a01, a02, a03,
@@ -2867,13 +2926,13 @@ mat4.translate = function (out, a, v) {
2867
2926
  };
2868
2927
 
2869
2928
  /**
2870
- * Scales the mat4 by the dimensions in the given vec3
2871
- *
2872
- * @param {mat4} out the receiving matrix
2873
- * @param {mat4} a the matrix to scale
2874
- * @param {vec3} v the vec3 to scale the matrix by
2875
- * @returns {mat4} out
2876
- **/
2929
+ * Scales the mat4 by the dimensions in the given vec3
2930
+ *
2931
+ * @param {mat4} out the receiving matrix
2932
+ * @param {mat4} a the matrix to scale
2933
+ * @param {vec3} v the vec3 to scale the matrix by
2934
+ * @returns {mat4} out
2935
+ **/
2877
2936
  mat4.scale = function(out, a, v) {
2878
2937
  var x = v[0], y = v[1], z = v[2];
2879
2938
 
@@ -2897,14 +2956,14 @@ mat4.scale = function(out, a, v) {
2897
2956
  };
2898
2957
 
2899
2958
  /**
2900
- * Rotates a mat4 by the given angle
2901
- *
2902
- * @param {mat4} out the receiving matrix
2903
- * @param {mat4} a the matrix to rotate
2904
- * @param {Number} rad the angle to rotate the matrix by
2905
- * @param {vec3} axis the axis to rotate around
2906
- * @returns {mat4} out
2907
- */
2959
+ * Rotates a mat4 by the given angle
2960
+ *
2961
+ * @param {mat4} out the receiving matrix
2962
+ * @param {mat4} a the matrix to rotate
2963
+ * @param {Number} rad the angle to rotate the matrix by
2964
+ * @param {vec3} axis the axis to rotate around
2965
+ * @returns {mat4} out
2966
+ */
2908
2967
  mat4.rotate = function (out, a, rad, axis) {
2909
2968
  var x = axis[0], y = axis[1], z = axis[2],
2910
2969
  len = Math.sqrt(x * x + y * y + z * z),
@@ -2960,13 +3019,13 @@ mat4.rotate = function (out, a, rad, axis) {
2960
3019
  };
2961
3020
 
2962
3021
  /**
2963
- * Rotates a matrix by the given angle around the X axis
2964
- *
2965
- * @param {mat4} out the receiving matrix
2966
- * @param {mat4} a the matrix to rotate
2967
- * @param {Number} rad the angle to rotate the matrix by
2968
- * @returns {mat4} out
2969
- */
3022
+ * Rotates a matrix by the given angle around the X axis
3023
+ *
3024
+ * @param {mat4} out the receiving matrix
3025
+ * @param {mat4} a the matrix to rotate
3026
+ * @param {Number} rad the angle to rotate the matrix by
3027
+ * @returns {mat4} out
3028
+ */
2970
3029
  mat4.rotateX = function (out, a, rad) {
2971
3030
  var s = Math.sin(rad),
2972
3031
  c = Math.cos(rad),
@@ -2980,10 +3039,10 @@ mat4.rotateX = function (out, a, rad) {
2980
3039
  a23 = a[11];
2981
3040
 
2982
3041
  if (a !== out) { // If the source and destination differ, copy the unchanged rows
2983
- out[0] = a[0];
2984
- out[1] = a[1];
2985
- out[2] = a[2];
2986
- out[3] = a[3];
3042
+ out[0] = a[0];
3043
+ out[1] = a[1];
3044
+ out[2] = a[2];
3045
+ out[3] = a[3];
2987
3046
  out[12] = a[12];
2988
3047
  out[13] = a[13];
2989
3048
  out[14] = a[14];
@@ -3003,13 +3062,13 @@ mat4.rotateX = function (out, a, rad) {
3003
3062
  };
3004
3063
 
3005
3064
  /**
3006
- * Rotates a matrix by the given angle around the Y axis
3007
- *
3008
- * @param {mat4} out the receiving matrix
3009
- * @param {mat4} a the matrix to rotate
3010
- * @param {Number} rad the angle to rotate the matrix by
3011
- * @returns {mat4} out
3012
- */
3065
+ * Rotates a matrix by the given angle around the Y axis
3066
+ *
3067
+ * @param {mat4} out the receiving matrix
3068
+ * @param {mat4} a the matrix to rotate
3069
+ * @param {Number} rad the angle to rotate the matrix by
3070
+ * @returns {mat4} out
3071
+ */
3013
3072
  mat4.rotateY = function (out, a, rad) {
3014
3073
  var s = Math.sin(rad),
3015
3074
  c = Math.cos(rad),
@@ -3023,10 +3082,10 @@ mat4.rotateY = function (out, a, rad) {
3023
3082
  a23 = a[11];
3024
3083
 
3025
3084
  if (a !== out) { // If the source and destination differ, copy the unchanged rows
3026
- out[4] = a[4];
3027
- out[5] = a[5];
3028
- out[6] = a[6];
3029
- out[7] = a[7];
3085
+ out[4] = a[4];
3086
+ out[5] = a[5];
3087
+ out[6] = a[6];
3088
+ out[7] = a[7];
3030
3089
  out[12] = a[12];
3031
3090
  out[13] = a[13];
3032
3091
  out[14] = a[14];
@@ -3046,13 +3105,13 @@ mat4.rotateY = function (out, a, rad) {
3046
3105
  };
3047
3106
 
3048
3107
  /**
3049
- * Rotates a matrix by the given angle around the Z axis
3050
- *
3051
- * @param {mat4} out the receiving matrix
3052
- * @param {mat4} a the matrix to rotate
3053
- * @param {Number} rad the angle to rotate the matrix by
3054
- * @returns {mat4} out
3055
- */
3108
+ * Rotates a matrix by the given angle around the Z axis
3109
+ *
3110
+ * @param {mat4} out the receiving matrix
3111
+ * @param {mat4} a the matrix to rotate
3112
+ * @param {Number} rad the angle to rotate the matrix by
3113
+ * @returns {mat4} out
3114
+ */
3056
3115
  mat4.rotateZ = function (out, a, rad) {
3057
3116
  var s = Math.sin(rad),
3058
3117
  c = Math.cos(rad),
@@ -3066,8 +3125,8 @@ mat4.rotateZ = function (out, a, rad) {
3066
3125
  a13 = a[7];
3067
3126
 
3068
3127
  if (a !== out) { // If the source and destination differ, copy the unchanged last row
3069
- out[8] = a[8];
3070
- out[9] = a[9];
3128
+ out[8] = a[8];
3129
+ out[9] = a[9];
3071
3130
  out[10] = a[10];
3072
3131
  out[11] = a[11];
3073
3132
  out[12] = a[12];
@@ -3089,20 +3148,20 @@ mat4.rotateZ = function (out, a, rad) {
3089
3148
  };
3090
3149
 
3091
3150
  /**
3092
- * Creates a matrix from a quaternion rotation and vector translation
3093
- * This is equivalent to (but much faster than):
3094
- *
3095
- * mat4.identity(dest);
3096
- * mat4.translate(dest, vec);
3097
- * var quatMat = mat4.create();
3098
- * quat4.toMat4(quat, quatMat);
3099
- * mat4.multiply(dest, quatMat);
3100
- *
3101
- * @param {mat4} out mat4 receiving operation result
3102
- * @param {quat4} q Rotation quaternion
3103
- * @param {vec3} v Translation vector
3104
- * @returns {mat4} out
3105
- */
3151
+ * Creates a matrix from a quaternion rotation and vector translation
3152
+ * This is equivalent to (but much faster than):
3153
+ *
3154
+ * mat4.identity(dest);
3155
+ * mat4.translate(dest, vec);
3156
+ * var quatMat = mat4.create();
3157
+ * quat4.toMat4(quat, quatMat);
3158
+ * mat4.multiply(dest, quatMat);
3159
+ *
3160
+ * @param {mat4} out mat4 receiving operation result
3161
+ * @param {quat4} q Rotation quaternion
3162
+ * @param {vec3} v Translation vector
3163
+ * @returns {mat4} out
3164
+ */
3106
3165
  mat4.fromRotationTranslation = function (out, q, v) {
3107
3166
  // Quaternion math
3108
3167
  var x = q[0], y = q[1], z = q[2], w = q[3],
@@ -3188,17 +3247,17 @@ mat4.fromQuat = function (out, q) {
3188
3247
  };
3189
3248
 
3190
3249
  /**
3191
- * Generates a frustum matrix with the given bounds
3192
- *
3193
- * @param {mat4} out mat4 frustum matrix will be written into
3194
- * @param {Number} left Left bound of the frustum
3195
- * @param {Number} right Right bound of the frustum
3196
- * @param {Number} bottom Bottom bound of the frustum
3197
- * @param {Number} top Top bound of the frustum
3198
- * @param {Number} near Near bound of the frustum
3199
- * @param {Number} far Far bound of the frustum
3200
- * @returns {mat4} out
3201
- */
3250
+ * Generates a frustum matrix with the given bounds
3251
+ *
3252
+ * @param {mat4} out mat4 frustum matrix will be written into
3253
+ * @param {Number} left Left bound of the frustum
3254
+ * @param {Number} right Right bound of the frustum
3255
+ * @param {Number} bottom Bottom bound of the frustum
3256
+ * @param {Number} top Top bound of the frustum
3257
+ * @param {Number} near Near bound of the frustum
3258
+ * @param {Number} far Far bound of the frustum
3259
+ * @returns {mat4} out
3260
+ */
3202
3261
  mat4.frustum = function (out, left, right, bottom, top, near, far) {
3203
3262
  var rl = 1 / (right - left),
3204
3263
  tb = 1 / (top - bottom),
@@ -3223,15 +3282,15 @@ mat4.frustum = function (out, left, right, bottom, top, near, far) {
3223
3282
  };
3224
3283
 
3225
3284
  /**
3226
- * Generates a perspective projection matrix with the given bounds
3227
- *
3228
- * @param {mat4} out mat4 frustum matrix will be written into
3229
- * @param {number} fovy Vertical field of view in radians
3230
- * @param {number} aspect Aspect ratio. typically viewport width/height
3231
- * @param {number} near Near bound of the frustum
3232
- * @param {number} far Far bound of the frustum
3233
- * @returns {mat4} out
3234
- */
3285
+ * Generates a perspective projection matrix with the given bounds
3286
+ *
3287
+ * @param {mat4} out mat4 frustum matrix will be written into
3288
+ * @param {number} fovy Vertical field of view in radians
3289
+ * @param {number} aspect Aspect ratio. typically viewport width/height
3290
+ * @param {number} near Near bound of the frustum
3291
+ * @param {number} far Far bound of the frustum
3292
+ * @returns {mat4} out
3293
+ */
3235
3294
  mat4.perspective = function (out, fovy, aspect, near, far) {
3236
3295
  var f = 1.0 / Math.tan(fovy / 2),
3237
3296
  nf = 1 / (near - far);
@@ -3255,17 +3314,17 @@ mat4.perspective = function (out, fovy, aspect, near, far) {
3255
3314
  };
3256
3315
 
3257
3316
  /**
3258
- * Generates a orthogonal projection matrix with the given bounds
3259
- *
3260
- * @param {mat4} out mat4 frustum matrix will be written into
3261
- * @param {number} left Left bound of the frustum
3262
- * @param {number} right Right bound of the frustum
3263
- * @param {number} bottom Bottom bound of the frustum
3264
- * @param {number} top Top bound of the frustum
3265
- * @param {number} near Near bound of the frustum
3266
- * @param {number} far Far bound of the frustum
3267
- * @returns {mat4} out
3268
- */
3317
+ * Generates a orthogonal projection matrix with the given bounds
3318
+ *
3319
+ * @param {mat4} out mat4 frustum matrix will be written into
3320
+ * @param {number} left Left bound of the frustum
3321
+ * @param {number} right Right bound of the frustum
3322
+ * @param {number} bottom Bottom bound of the frustum
3323
+ * @param {number} top Top bound of the frustum
3324
+ * @param {number} near Near bound of the frustum
3325
+ * @param {number} far Far bound of the frustum
3326
+ * @returns {mat4} out
3327
+ */
3269
3328
  mat4.ortho = function (out, left, right, bottom, top, near, far) {
3270
3329
  var lr = 1 / (left - right),
3271
3330
  bt = 1 / (bottom - top),
@@ -3290,14 +3349,14 @@ mat4.ortho = function (out, left, right, bottom, top, near, far) {
3290
3349
  };
3291
3350
 
3292
3351
  /**
3293
- * Generates a look-at matrix with the given eye position, focal point, and up axis
3294
- *
3295
- * @param {mat4} out mat4 frustum matrix will be written into
3296
- * @param {vec3} eye Position of the viewer
3297
- * @param {vec3} center Point the viewer is looking at
3298
- * @param {vec3} up vec3 pointing up
3299
- * @returns {mat4} out
3300
- */
3352
+ * Generates a look-at matrix with the given eye position, focal point, and up axis
3353
+ *
3354
+ * @param {mat4} out mat4 frustum matrix will be written into
3355
+ * @param {vec3} eye Position of the viewer
3356
+ * @param {vec3} center Point the viewer is looking at
3357
+ * @param {vec3} up vec3 pointing up
3358
+ * @returns {mat4} out
3359
+ */
3301
3360
  mat4.lookAt = function (out, eye, center, up) {
3302
3361
  var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
3303
3362
  eyex = eye[0],
@@ -3377,15 +3436,15 @@ mat4.lookAt = function (out, eye, center, up) {
3377
3436
  };
3378
3437
 
3379
3438
  /**
3380
- * Returns a string representation of a mat4
3381
- *
3382
- * @param {mat4} mat matrix to represent as a string
3383
- * @returns {String} string representation of the matrix
3384
- */
3439
+ * Returns a string representation of a mat4
3440
+ *
3441
+ * @param {mat4} mat matrix to represent as a string
3442
+ * @returns {String} string representation of the matrix
3443
+ */
3385
3444
  mat4.str = function (a) {
3386
3445
  return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +
3387
3446
  a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +
3388
- a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
3447
+ a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
3389
3448
  a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';
3390
3449
  };
3391
3450
 
@@ -3398,15 +3457,15 @@ if(typeof(exports) !== 'undefined') {
3398
3457
  Redistribution and use in source and binary forms, with or without modification,
3399
3458
  are permitted provided that the following conditions are met:
3400
3459
 
3401
- * Redistributions of source code must retain the above copyright notice, this
3402
- list of conditions and the following disclaimer.
3403
- * Redistributions in binary form must reproduce the above copyright notice,
3404
- this list of conditions and the following disclaimer in the documentation
3405
- and/or other materials provided with the distribution.
3460
+ * Redistributions of source code must retain the above copyright notice, this
3461
+ list of conditions and the following disclaimer.
3462
+ * Redistributions in binary form must reproduce the above copyright notice,
3463
+ this list of conditions and the following disclaimer in the documentation
3464
+ and/or other materials provided with the distribution.
3406
3465
 
3407
3466
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
3408
3467
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
3409
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3468
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3410
3469
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
3411
3470
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3412
3471
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
@@ -3416,19 +3475,17 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3416
3475
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
3417
3476
 
3418
3477
  /**
3419
- * @class Quaternion
3420
- * @name quat
3421
- */
3478
+ * @class Quaternion
3479
+ * @name quat
3480
+ */
3422
3481
 
3423
3482
  var quat = {};
3424
3483
 
3425
- var quatIdentity = new Float32Array([0, 0, 0, 1]);
3426
-
3427
3484
  /**
3428
- * Creates a new identity quat
3429
- *
3430
- * @returns {quat} a new quaternion
3431
- */
3485
+ * Creates a new identity quat
3486
+ *
3487
+ * @returns {quat} a new quaternion
3488
+ */
3432
3489
  quat.create = function() {
3433
3490
  var out = new GLMAT_ARRAY_TYPE(4);
3434
3491
  out[0] = 0;
@@ -3439,55 +3496,125 @@ quat.create = function() {
3439
3496
  };
3440
3497
 
3441
3498
  /**
3442
- * Creates a new quat initialized with values from an existing quaternion
3443
- *
3444
- * @param {quat} a quaternion to clone
3445
- * @returns {quat} a new quaternion
3446
- * @function
3447
- */
3499
+ * Sets a quaternion to represent the shortest rotation from one
3500
+ * vector to another.
3501
+ *
3502
+ * Both vectors are assumed to be unit length.
3503
+ *
3504
+ * @param {quat} out the receiving quaternion.
3505
+ * @param {vec3} a the initial vector
3506
+ * @param {vec3} b the destination vector
3507
+ * @returns {quat} out
3508
+ */
3509
+ quat.rotationTo = (function() {
3510
+ var tmpvec3 = vec3.create();
3511
+ var xUnitVec3 = vec3.fromValues(1,0,0);
3512
+ var yUnitVec3 = vec3.fromValues(0,1,0);
3513
+
3514
+ return function(out, a, b) {
3515
+ var dot = vec3.dot(a, b);
3516
+ if (dot < -0.999999) {
3517
+ vec3.cross(tmpvec3, xUnitVec3, a);
3518
+ if (vec3.length(tmpvec3) < 0.000001)
3519
+ vec3.cross(tmpvec3, yUnitVec3, a);
3520
+ vec3.normalize(tmpvec3, tmpvec3);
3521
+ quat.setAxisAngle(out, tmpvec3, Math.PI);
3522
+ } else if (dot > 0.999999) {
3523
+ out[0] = 0;
3524
+ out[1] = 0;
3525
+ out[2] = 0;
3526
+ out[3] = 1;
3527
+ } else {
3528
+ vec3.cross(tmpvec3, a, b);
3529
+ out[0] = tmpvec3[0];
3530
+ out[1] = tmpvec3[1];
3531
+ out[2] = tmpvec3[2];
3532
+ out[3] = 1 + dot;
3533
+ return quat.normalize(out, out);
3534
+ }
3535
+ };
3536
+ })();
3537
+
3538
+ /**
3539
+ * Sets the specified quaternion with values corresponding to the given
3540
+ * axes. Each axis is a vec3 and is expected to be unit length and
3541
+ * perpendicular to all other specified axes.
3542
+ *
3543
+ * @param {vec3} view the vector representing the viewing direction
3544
+ * @param {vec3} right the vector representing the local "right" direction
3545
+ * @param {vec3} up the vector representing the local "up" direction
3546
+ * @returns {quat} out
3547
+ */
3548
+ quat.setAxes = (function() {
3549
+ var matr = mat3.create();
3550
+
3551
+ return function(out, view, right, up) {
3552
+ matr[0] = right[0];
3553
+ matr[3] = right[1];
3554
+ matr[6] = right[2];
3555
+
3556
+ matr[1] = up[0];
3557
+ matr[4] = up[1];
3558
+ matr[7] = up[2];
3559
+
3560
+ matr[2] = -view[0];
3561
+ matr[5] = -view[1];
3562
+ matr[8] = -view[2];
3563
+
3564
+ return quat.normalize(out, quat.fromMat3(out, matr));
3565
+ };
3566
+ })();
3567
+
3568
+ /**
3569
+ * Creates a new quat initialized with values from an existing quaternion
3570
+ *
3571
+ * @param {quat} a quaternion to clone
3572
+ * @returns {quat} a new quaternion
3573
+ * @function
3574
+ */
3448
3575
  quat.clone = vec4.clone;
3449
3576
 
3450
3577
  /**
3451
- * Creates a new quat initialized with the given values
3452
- *
3453
- * @param {Number} x X component
3454
- * @param {Number} y Y component
3455
- * @param {Number} z Z component
3456
- * @param {Number} w W component
3457
- * @returns {quat} a new quaternion
3458
- * @function
3459
- */
3578
+ * Creates a new quat initialized with the given values
3579
+ *
3580
+ * @param {Number} x X component
3581
+ * @param {Number} y Y component
3582
+ * @param {Number} z Z component
3583
+ * @param {Number} w W component
3584
+ * @returns {quat} a new quaternion
3585
+ * @function
3586
+ */
3460
3587
  quat.fromValues = vec4.fromValues;
3461
3588
 
3462
3589
  /**
3463
- * Copy the values from one quat to another
3464
- *
3465
- * @param {quat} out the receiving quaternion
3466
- * @param {quat} a the source quaternion
3467
- * @returns {quat} out
3468
- * @function
3469
- */
3590
+ * Copy the values from one quat to another
3591
+ *
3592
+ * @param {quat} out the receiving quaternion
3593
+ * @param {quat} a the source quaternion
3594
+ * @returns {quat} out
3595
+ * @function
3596
+ */
3470
3597
  quat.copy = vec4.copy;
3471
3598
 
3472
3599
  /**
3473
- * Set the components of a quat to the given values
3474
- *
3475
- * @param {quat} out the receiving quaternion
3476
- * @param {Number} x X component
3477
- * @param {Number} y Y component
3478
- * @param {Number} z Z component
3479
- * @param {Number} w W component
3480
- * @returns {quat} out
3481
- * @function
3482
- */
3600
+ * Set the components of a quat to the given values
3601
+ *
3602
+ * @param {quat} out the receiving quaternion
3603
+ * @param {Number} x X component
3604
+ * @param {Number} y Y component
3605
+ * @param {Number} z Z component
3606
+ * @param {Number} w W component
3607
+ * @returns {quat} out
3608
+ * @function
3609
+ */
3483
3610
  quat.set = vec4.set;
3484
3611
 
3485
3612
  /**
3486
- * Set a quat to the identity quaternion
3487
- *
3488
- * @param {quat} out the receiving quaternion
3489
- * @returns {quat} out
3490
- */
3613
+ * Set a quat to the identity quaternion
3614
+ *
3615
+ * @param {quat} out the receiving quaternion
3616
+ * @returns {quat} out
3617
+ */
3491
3618
  quat.identity = function(out) {
3492
3619
  out[0] = 0;
3493
3620
  out[1] = 0;
@@ -3497,14 +3624,14 @@ quat.identity = function(out) {
3497
3624
  };
3498
3625
 
3499
3626
  /**
3500
- * Sets a quat from the given angle and rotation axis,
3501
- * then returns it.
3502
- *
3503
- * @param {quat} out the receiving quaternion
3504
- * @param {vec3} axis the axis around which to rotate
3505
- * @param {Number} rad the angle in radians
3506
- * @returns {quat} out
3507
- **/
3627
+ * Sets a quat from the given angle and rotation axis,
3628
+ * then returns it.
3629
+ *
3630
+ * @param {quat} out the receiving quaternion
3631
+ * @param {vec3} axis the axis around which to rotate
3632
+ * @param {Number} rad the angle in radians
3633
+ * @returns {quat} out
3634
+ **/
3508
3635
  quat.setAxisAngle = function(out, axis, rad) {
3509
3636
  rad = rad * 0.5;
3510
3637
  var s = Math.sin(rad);
@@ -3516,24 +3643,24 @@ quat.setAxisAngle = function(out, axis, rad) {
3516
3643
  };
3517
3644
 
3518
3645
  /**
3519
- * Adds two quat's
3520
- *
3521
- * @param {quat} out the receiving quaternion
3522
- * @param {quat} a the first operand
3523
- * @param {quat} b the second operand
3524
- * @returns {quat} out
3525
- * @function
3526
- */
3646
+ * Adds two quat's
3647
+ *
3648
+ * @param {quat} out the receiving quaternion
3649
+ * @param {quat} a the first operand
3650
+ * @param {quat} b the second operand
3651
+ * @returns {quat} out
3652
+ * @function
3653
+ */
3527
3654
  quat.add = vec4.add;
3528
3655
 
3529
3656
  /**
3530
- * Multiplies two quat's
3531
- *
3532
- * @param {quat} out the receiving quaternion
3533
- * @param {quat} a the first operand
3534
- * @param {quat} b the second operand
3535
- * @returns {quat} out
3536
- */
3657
+ * Multiplies two quat's
3658
+ *
3659
+ * @param {quat} out the receiving quaternion
3660
+ * @param {quat} a the first operand
3661
+ * @param {quat} b the second operand
3662
+ * @returns {quat} out
3663
+ */
3537
3664
  quat.multiply = function(out, a, b) {
3538
3665
  var ax = a[0], ay = a[1], az = a[2], aw = a[3],
3539
3666
  bx = b[0], by = b[1], bz = b[2], bw = b[3];
@@ -3546,32 +3673,32 @@ quat.multiply = function(out, a, b) {
3546
3673
  };
3547
3674
 
3548
3675
  /**
3549
- * Alias for {@link quat.multiply}
3550
- * @function
3551
- */
3676
+ * Alias for {@link quat.multiply}
3677
+ * @function
3678
+ */
3552
3679
  quat.mul = quat.multiply;
3553
3680
 
3554
3681
  /**
3555
- * Scales a quat by a scalar number
3556
- *
3557
- * @param {quat} out the receiving vector
3558
- * @param {quat} a the vector to scale
3559
- * @param {Number} b amount to scale the vector by
3560
- * @returns {quat} out
3561
- * @function
3562
- */
3682
+ * Scales a quat by a scalar number
3683
+ *
3684
+ * @param {quat} out the receiving vector
3685
+ * @param {quat} a the vector to scale
3686
+ * @param {Number} b amount to scale the vector by
3687
+ * @returns {quat} out
3688
+ * @function
3689
+ */
3563
3690
  quat.scale = vec4.scale;
3564
3691
 
3565
3692
  /**
3566
- * Rotates a quaternion by the given angle around the X axis
3567
- *
3568
- * @param {quat} out quat receiving operation result
3569
- * @param {quat} a quat to rotate
3570
- * @param {number} rad angle (in radians) to rotate
3571
- * @returns {quat} out
3572
- */
3693
+ * Rotates a quaternion by the given angle about the X axis
3694
+ *
3695
+ * @param {quat} out quat receiving operation result
3696
+ * @param {quat} a quat to rotate
3697
+ * @param {number} rad angle (in radians) to rotate
3698
+ * @returns {quat} out
3699
+ */
3573
3700
  quat.rotateX = function (out, a, rad) {
3574
- rad *= 0.5;
3701
+ rad *= 0.5;
3575
3702
 
3576
3703
  var ax = a[0], ay = a[1], az = a[2], aw = a[3],
3577
3704
  bx = Math.sin(rad), bw = Math.cos(rad);
@@ -3584,15 +3711,15 @@ quat.rotateX = function (out, a, rad) {
3584
3711
  };
3585
3712
 
3586
3713
  /**
3587
- * Rotates a quaternion by the given angle around the Y axis
3588
- *
3589
- * @param {quat} out quat receiving operation result
3590
- * @param {quat} a quat to rotate
3591
- * @param {number} rad angle (in radians) to rotate
3592
- * @returns {quat} out
3593
- */
3714
+ * Rotates a quaternion by the given angle about the Y axis
3715
+ *
3716
+ * @param {quat} out quat receiving operation result
3717
+ * @param {quat} a quat to rotate
3718
+ * @param {number} rad angle (in radians) to rotate
3719
+ * @returns {quat} out
3720
+ */
3594
3721
  quat.rotateY = function (out, a, rad) {
3595
- rad *= 0.5;
3722
+ rad *= 0.5;
3596
3723
 
3597
3724
  var ax = a[0], ay = a[1], az = a[2], aw = a[3],
3598
3725
  by = Math.sin(rad), bw = Math.cos(rad);
@@ -3605,15 +3732,15 @@ quat.rotateY = function (out, a, rad) {
3605
3732
  };
3606
3733
 
3607
3734
  /**
3608
- * Rotates a quaternion by the given angle around the Z axis
3609
- *
3610
- * @param {quat} out quat receiving operation result
3611
- * @param {quat} a quat to rotate
3612
- * @param {number} rad angle (in radians) to rotate
3613
- * @returns {quat} out
3614
- */
3735
+ * Rotates a quaternion by the given angle about the Z axis
3736
+ *
3737
+ * @param {quat} out quat receiving operation result
3738
+ * @param {quat} a quat to rotate
3739
+ * @param {number} rad angle (in radians) to rotate
3740
+ * @returns {quat} out
3741
+ */
3615
3742
  quat.rotateZ = function (out, a, rad) {
3616
- rad *= 0.5;
3743
+ rad *= 0.5;
3617
3744
 
3618
3745
  var ax = a[0], ay = a[1], az = a[2], aw = a[3],
3619
3746
  bz = Math.sin(rad), bw = Math.cos(rad);
@@ -3626,14 +3753,14 @@ quat.rotateZ = function (out, a, rad) {
3626
3753
  };
3627
3754
 
3628
3755
  /**
3629
- * Calculates the W component of a quat from the X, Y, and Z components.
3630
- * Assumes that quaternion is 1 unit in length.
3631
- * Any existing W component will be ignored.
3632
- *
3633
- * @param {quat} out the receiving quaternion
3634
- * @param {quat} a quat to calculate W component of
3635
- * @returns {quat} out
3636
- */
3756
+ * Calculates the W component of a quat from the X, Y, and Z components.
3757
+ * Assumes that quaternion is 1 unit in length.
3758
+ * Any existing W component will be ignored.
3759
+ *
3760
+ * @param {quat} out the receiving quaternion
3761
+ * @param {quat} a quat to calculate W component of
3762
+ * @returns {quat} out
3763
+ */
3637
3764
  quat.calculateW = function (out, a) {
3638
3765
  var x = a[0], y = a[1], z = a[2];
3639
3766
 
@@ -3645,85 +3772,84 @@ quat.calculateW = function (out, a) {
3645
3772
  };
3646
3773
 
3647
3774
  /**
3648
- * Calculates the dot product of two quat's
3649
- *
3650
- * @param {quat} a the first operand
3651
- * @param {quat} b the second operand
3652
- * @returns {Number} dot product of a and b
3653
- * @function
3654
- */
3775
+ * Calculates the dot product of two quat's
3776
+ *
3777
+ * @param {quat} a the first operand
3778
+ * @param {quat} b the second operand
3779
+ * @returns {Number} dot product of a and b
3780
+ * @function
3781
+ */
3655
3782
  quat.dot = vec4.dot;
3656
3783
 
3657
3784
  /**
3658
- * Performs a linear interpolation between two quat's
3659
- *
3660
- * @param {quat} out the receiving quaternion
3661
- * @param {quat} a the first operand
3662
- * @param {quat} b the second operand
3663
- * @param {Number} t interpolation amount between the two inputs
3664
- * @returns {quat} out
3665
- * @function
3666
- */
3785
+ * Performs a linear interpolation between two quat's
3786
+ *
3787
+ * @param {quat} out the receiving quaternion
3788
+ * @param {quat} a the first operand
3789
+ * @param {quat} b the second operand
3790
+ * @param {Number} t interpolation amount between the two inputs
3791
+ * @returns {quat} out
3792
+ * @function
3793
+ */
3667
3794
  quat.lerp = vec4.lerp;
3668
3795
 
3669
3796
  /**
3670
- * Performs a spherical linear interpolation between two quat
3671
- *
3672
- * @param {quat} out the receiving quaternion
3673
- * @param {quat} a the first operand
3674
- * @param {quat} b the second operand
3675
- * @param {Number} t interpolation amount between the two inputs
3676
- * @returns {quat} out
3677
- */
3797
+ * Performs a spherical linear interpolation between two quat
3798
+ *
3799
+ * @param {quat} out the receiving quaternion
3800
+ * @param {quat} a the first operand
3801
+ * @param {quat} b the second operand
3802
+ * @param {Number} t interpolation amount between the two inputs
3803
+ * @returns {quat} out
3804
+ */
3678
3805
  quat.slerp = function (out, a, b, t) {
3806
+ // benchmarks:
3807
+ // http://jsperf.com/quaternion-slerp-implementations
3808
+
3679
3809
  var ax = a[0], ay = a[1], az = a[2], aw = a[3],
3680
3810
  bx = b[0], by = b[1], bz = b[2], bw = b[3];
3681
3811
 
3682
- var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw,
3683
- halfTheta,
3684
- sinHalfTheta,
3685
- ratioA,
3686
- ratioB;
3687
-
3688
- if (Math.abs(cosHalfTheta) >= 1.0) {
3689
- if (out !== a) {
3690
- out[0] = ax;
3691
- out[1] = ay;
3692
- out[2] = az;
3693
- out[3] = aw;
3694
- }
3695
- return out;
3812
+ var omega, cosom, sinom, scale0, scale1;
3813
+
3814
+ // calc cosine
3815
+ cosom = ax * bx + ay * by + az * bz + aw * bw;
3816
+ // adjust signs (if necessary)
3817
+ if ( cosom < 0.0 ) {
3818
+ cosom = -cosom;
3819
+ bx = - bx;
3820
+ by = - by;
3821
+ bz = - bz;
3822
+ bw = - bw;
3696
3823
  }
3697
-
3698
- halfTheta = Math.acos(cosHalfTheta);
3699
- sinHalfTheta = Math.sqrt(1.0 - cosHalfTheta * cosHalfTheta);
3700
-
3701
- if (Math.abs(sinHalfTheta) < 0.001) {
3702
- out[0] = (ax * 0.5 + bx * 0.5);
3703
- out[1] = (ay * 0.5 + by * 0.5);
3704
- out[2] = (az * 0.5 + bz * 0.5);
3705
- out[3] = (aw * 0.5 + bw * 0.5);
3706
- return out;
3824
+ // calculate coefficients
3825
+ if ( (1.0 - cosom) > 0.000001 ) {
3826
+ // standard case (slerp)
3827
+ omega = Math.acos(cosom);
3828
+ sinom = Math.sin(omega);
3829
+ scale0 = Math.sin((1.0 - t) * omega) / sinom;
3830
+ scale1 = Math.sin(t * omega) / sinom;
3831
+ } else {
3832
+ // "from" and "to" quaternions are very close
3833
+ // ... so we can do a linear interpolation
3834
+ scale0 = 1.0 - t;
3835
+ scale1 = t;
3707
3836
  }
3708
-
3709
- ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta;
3710
- ratioB = Math.sin(t * halfTheta) / sinHalfTheta;
3711
-
3712
- out[0] = (ax * ratioA + bx * ratioB);
3713
- out[1] = (ay * ratioA + by * ratioB);
3714
- out[2] = (az * ratioA + bz * ratioB);
3715
- out[3] = (aw * ratioA + bw * ratioB);
3716
-
3837
+ // calculate final values
3838
+ out[0] = scale0 * ax + scale1 * bx;
3839
+ out[1] = scale0 * ay + scale1 * by;
3840
+ out[2] = scale0 * az + scale1 * bz;
3841
+ out[3] = scale0 * aw + scale1 * bw;
3842
+
3717
3843
  return out;
3718
3844
  };
3719
3845
 
3720
3846
  /**
3721
- * Calculates the inverse of a quat
3722
- *
3723
- * @param {quat} out the receiving quaternion
3724
- * @param {quat} a quat to calculate inverse of
3725
- * @returns {quat} out
3726
- */
3847
+ * Calculates the inverse of a quat
3848
+ *
3849
+ * @param {quat} out the receiving quaternion
3850
+ * @param {quat} a quat to calculate inverse of
3851
+ * @returns {quat} out
3852
+ */
3727
3853
  quat.invert = function(out, a) {
3728
3854
  var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
3729
3855
  dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,
@@ -3739,13 +3865,13 @@ quat.invert = function(out, a) {
3739
3865
  };
3740
3866
 
3741
3867
  /**
3742
- * Calculates the conjugate of a quat
3743
- * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
3744
- *
3745
- * @param {quat} out the receiving quaternion
3746
- * @param {quat} a quat to calculate conjugate of
3747
- * @returns {quat} out
3748
- */
3868
+ * Calculates the conjugate of a quat
3869
+ * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
3870
+ *
3871
+ * @param {quat} out the receiving quaternion
3872
+ * @param {quat} a quat to calculate conjugate of
3873
+ * @returns {quat} out
3874
+ */
3749
3875
  quat.conjugate = function (out, a) {
3750
3876
  out[0] = -a[0];
3751
3877
  out[1] = -a[1];
@@ -3755,55 +3881,63 @@ quat.conjugate = function (out, a) {
3755
3881
  };
3756
3882
 
3757
3883
  /**
3758
- * Calculates the length of a quat
3759
- *
3760
- * @param {quat} a vector to calculate length of
3761
- * @returns {Number} length of a
3762
- * @function
3763
- */
3884
+ * Calculates the length of a quat
3885
+ *
3886
+ * @param {quat} a vector to calculate length of
3887
+ * @returns {Number} length of a
3888
+ * @function
3889
+ */
3764
3890
  quat.length = vec4.length;
3765
3891
 
3766
3892
  /**
3767
- * Alias for {@link quat.length}
3768
- * @function
3769
- */
3893
+ * Alias for {@link quat.length}
3894
+ * @function
3895
+ */
3770
3896
  quat.len = quat.length;
3771
3897
 
3772
3898
  /**
3773
- * Calculates the squared length of a quat
3774
- *
3775
- * @param {quat} a vector to calculate squared length of
3776
- * @returns {Number} squared length of a
3777
- * @function
3778
- */
3899
+ * Calculates the squared length of a quat
3900
+ *
3901
+ * @param {quat} a vector to calculate squared length of
3902
+ * @returns {Number} squared length of a
3903
+ * @function
3904
+ */
3779
3905
  quat.squaredLength = vec4.squaredLength;
3780
3906
 
3781
3907
  /**
3782
- * Alias for {@link quat.squaredLength}
3783
- * @function
3784
- */
3908
+ * Alias for {@link quat.squaredLength}
3909
+ * @function
3910
+ */
3785
3911
  quat.sqrLen = quat.squaredLength;
3786
3912
 
3787
3913
  /**
3788
- * Normalize a quat
3789
- *
3790
- * @param {quat} out the receiving quaternion
3791
- * @param {quat} a quaternion to normalize
3792
- * @returns {quat} out
3793
- * @function
3794
- */
3914
+ * Normalize a quat
3915
+ *
3916
+ * @param {quat} out the receiving quaternion
3917
+ * @param {quat} a quaternion to normalize
3918
+ * @returns {quat} out
3919
+ * @function
3920
+ */
3795
3921
  quat.normalize = vec4.normalize;
3796
3922
 
3797
3923
  /**
3798
- * Creates a quaternion from the given 3x3 rotation matrix.
3799
- *
3800
- * @param {quat} out the receiving quaternion
3801
- * @param {mat3} m rotation matrix
3802
- * @returns {quat} out
3803
- * @function
3804
- */
3924
+ * Creates a quaternion from the given 3x3 rotation matrix.
3925
+ *
3926
+ * NOTE: The resultant quaternion is not normalized, so you should be sure
3927
+ * to renormalize the quaternion yourself where necessary.
3928
+ *
3929
+ * @param {quat} out the receiving quaternion
3930
+ * @param {mat3} m rotation matrix
3931
+ * @returns {quat} out
3932
+ * @function
3933
+ */
3805
3934
  quat.fromMat3 = (function() {
3806
- var s_iNext = [1,2,0];
3935
+ // benchmarks:
3936
+ // http://jsperf.com/typed-array-access-speed
3937
+ // http://jsperf.com/conversion-of-3x3-matrix-to-quaternion
3938
+
3939
+ var s_iNext = (typeof(Int8Array) !== 'undefined' ? new Int8Array([1,2,0]) : [1,2,0]);
3940
+
3807
3941
  return function(out, m) {
3808
3942
  // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
3809
3943
  // article "Quaternion Calculus and Fast Animation".
@@ -3812,12 +3946,12 @@ quat.fromMat3 = (function() {
3812
3946
 
3813
3947
  if ( fTrace > 0.0 ) {
3814
3948
  // |w| > 1/2, may as well choose w > 1/2
3815
- fRoot = Math.sqrt(fTrace + 1.0); // 2w
3949
+ fRoot = Math.sqrt(fTrace + 1.0); // 2w
3816
3950
  out[3] = 0.5 * fRoot;
3817
- fRoot = 0.5/fRoot; // 1/(4w)
3818
- out[0] = (m[7]-m[5])*fRoot;
3819
- out[1] = (m[2]-m[6])*fRoot;
3820
- out[2] = (m[3]-m[1])*fRoot;
3951
+ fRoot = 0.5/fRoot; // 1/(4w)
3952
+ out[0] = (m[5]-m[7])*fRoot;
3953
+ out[1] = (m[6]-m[2])*fRoot;
3954
+ out[2] = (m[1]-m[3])*fRoot;
3821
3955
  } else {
3822
3956
  // |w| <= 1/2
3823
3957
  var i = 0;
@@ -3841,11 +3975,11 @@ quat.fromMat3 = (function() {
3841
3975
  })();
3842
3976
 
3843
3977
  /**
3844
- * Returns a string representation of a quatenion
3845
- *
3846
- * @param {quat} vec vector to represent as a string
3847
- * @returns {String} string representation of the vector
3848
- */
3978
+ * Returns a string representation of a quatenion
3979
+ *
3980
+ * @param {quat} vec vector to represent as a string
3981
+ * @returns {String} string representation of the vector
3982
+ */
3849
3983
  quat.str = function (a) {
3850
3984
  return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
3851
3985
  };
@@ -3868,4 +4002,4 @@ if(typeof(exports) !== 'undefined') {
3868
4002
 
3869
4003
 
3870
4004
  })(shim.exports);
3871
- })();
4005
+ })();