gl-matrix-rails 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gl-matrix/version.rb +1 -1
- data/vendor/assets/javascripts/gl-matrix.js +1904 -1104
- metadata +7 -7
data/lib/gl-matrix/version.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
/**
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
-
/* Copyright (c)
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
@@ -49,20 +49,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
|
49
49
|
}
|
50
50
|
|
51
51
|
(function(exports) {
|
52
|
-
/* Copyright (c)
|
52
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
53
53
|
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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;
|
@@ -71,60 +71,109 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
71
71
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
72
72
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
73
73
|
|
74
|
-
/**
|
75
|
-
* @class 2 Dimensional Vector
|
76
|
-
* @name vec2
|
77
|
-
*/
|
78
|
-
|
79
|
-
var vec2 = {};
|
80
74
|
|
81
75
|
if(!GLMAT_EPSILON) {
|
82
76
|
var GLMAT_EPSILON = 0.000001;
|
83
77
|
}
|
84
|
-
|
78
|
+
|
79
|
+
if(!GLMAT_ARRAY_TYPE) {
|
80
|
+
var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
|
81
|
+
}
|
82
|
+
|
85
83
|
/**
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
84
|
+
* @class Common utilities
|
85
|
+
* @name glMatrix
|
86
|
+
*/
|
87
|
+
var glMatrix = {};
|
88
|
+
|
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
|
+
*/
|
94
|
+
glMatrix.setMatrixArrayType = function(type) {
|
95
|
+
GLMAT_ARRAY_TYPE = type;
|
96
|
+
}
|
97
|
+
|
98
|
+
if(typeof(exports) !== 'undefined') {
|
99
|
+
exports.glMatrix = glMatrix;
|
100
|
+
}
|
101
|
+
;
|
102
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
103
|
+
|
104
|
+
Redistribution and use in source and binary forms, with or without modification,
|
105
|
+
are permitted provided that the following conditions are met:
|
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.
|
112
|
+
|
113
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
114
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
115
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
116
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
117
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
118
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
119
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
120
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
121
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
122
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @class 2 Dimensional Vector
|
126
|
+
* @name vec2
|
127
|
+
*/
|
128
|
+
|
129
|
+
var vec2 = {};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Creates a new, empty vec2
|
133
|
+
*
|
134
|
+
* @returns {vec2} a new 2D vector
|
135
|
+
*/
|
90
136
|
vec2.create = function() {
|
91
|
-
|
137
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
138
|
+
out[0] = 0;
|
139
|
+
out[1] = 0;
|
140
|
+
return out;
|
92
141
|
};
|
93
142
|
|
94
143
|
/**
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
+
*/
|
100
149
|
vec2.clone = function(a) {
|
101
|
-
var out = new
|
150
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
102
151
|
out[0] = a[0];
|
103
152
|
out[1] = a[1];
|
104
153
|
return out;
|
105
154
|
};
|
106
155
|
|
107
156
|
/**
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
+
*/
|
114
163
|
vec2.fromValues = function(x, y) {
|
115
|
-
var out = new
|
164
|
+
var out = new GLMAT_ARRAY_TYPE(2);
|
116
165
|
out[0] = x;
|
117
166
|
out[1] = y;
|
118
167
|
return out;
|
119
168
|
};
|
120
169
|
|
121
170
|
/**
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
+
*/
|
128
177
|
vec2.copy = function(out, a) {
|
129
178
|
out[0] = a[0];
|
130
179
|
out[1] = a[1];
|
@@ -132,13 +181,13 @@ vec2.copy = function(out, a) {
|
|
132
181
|
};
|
133
182
|
|
134
183
|
/**
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
+
*/
|
142
191
|
vec2.set = function(out, x, y) {
|
143
192
|
out[0] = x;
|
144
193
|
out[1] = y;
|
@@ -146,13 +195,13 @@ vec2.set = function(out, x, y) {
|
|
146
195
|
};
|
147
196
|
|
148
197
|
/**
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
+
*/
|
156
205
|
vec2.add = function(out, a, b) {
|
157
206
|
out[0] = a[0] + b[0];
|
158
207
|
out[1] = a[1] + b[1];
|
@@ -160,55 +209,73 @@ vec2.add = function(out, a, b) {
|
|
160
209
|
};
|
161
210
|
|
162
211
|
/**
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
vec2.
|
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
|
+
*/
|
219
|
+
vec2.subtract = function(out, a, b) {
|
171
220
|
out[0] = a[0] - b[0];
|
172
221
|
out[1] = a[1] - b[1];
|
173
222
|
return out;
|
174
223
|
};
|
175
224
|
|
176
225
|
/**
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
226
|
+
* Alias for {@link vec2.subtract}
|
227
|
+
* @function
|
228
|
+
*/
|
229
|
+
vec2.sub = vec2.subtract;
|
230
|
+
|
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
|
+
*/
|
239
|
+
vec2.multiply = function(out, a, b) {
|
185
240
|
out[0] = a[0] * b[0];
|
186
241
|
out[1] = a[1] * b[1];
|
187
242
|
return out;
|
188
243
|
};
|
189
244
|
|
190
245
|
/**
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
246
|
+
* Alias for {@link vec2.multiply}
|
247
|
+
* @function
|
248
|
+
*/
|
249
|
+
vec2.mul = vec2.multiply;
|
250
|
+
|
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
|
+
*/
|
259
|
+
vec2.divide = function(out, a, b) {
|
199
260
|
out[0] = a[0] / b[0];
|
200
261
|
out[1] = a[1] / b[1];
|
201
262
|
return out;
|
202
263
|
};
|
203
264
|
|
204
265
|
/**
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
266
|
+
* Alias for {@link vec2.divide}
|
267
|
+
* @function
|
268
|
+
*/
|
269
|
+
vec2.div = vec2.divide;
|
270
|
+
|
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
|
+
*/
|
212
279
|
vec2.min = function(out, a, b) {
|
213
280
|
out[0] = Math.min(a[0], b[0]);
|
214
281
|
out[1] = Math.min(a[1], b[1]);
|
@@ -216,13 +283,13 @@ vec2.min = function(out, a, b) {
|
|
216
283
|
};
|
217
284
|
|
218
285
|
/**
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
+
*/
|
226
293
|
vec2.max = function(out, a, b) {
|
227
294
|
out[0] = Math.max(a[0], b[0]);
|
228
295
|
out[1] = Math.max(a[1], b[1]);
|
@@ -230,13 +297,13 @@ vec2.max = function(out, a, b) {
|
|
230
297
|
};
|
231
298
|
|
232
299
|
/**
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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
|
+
*/
|
240
307
|
vec2.scale = function(out, a, b) {
|
241
308
|
out[0] = a[0] * b;
|
242
309
|
out[1] = a[1] * b;
|
@@ -244,62 +311,86 @@ vec2.scale = function(out, a, b) {
|
|
244
311
|
};
|
245
312
|
|
246
313
|
/**
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
vec2.
|
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
|
+
*/
|
320
|
+
vec2.distance = function(a, b) {
|
254
321
|
var x = b[0] - a[0],
|
255
322
|
y = b[1] - a[1];
|
256
323
|
return Math.sqrt(x*x + y*y);
|
257
324
|
};
|
258
325
|
|
259
326
|
/**
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
327
|
+
* Alias for {@link vec2.distance}
|
328
|
+
* @function
|
329
|
+
*/
|
330
|
+
vec2.dist = vec2.distance;
|
331
|
+
|
332
|
+
/**
|
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
|
+
*/
|
339
|
+
vec2.squaredDistance = function(a, b) {
|
267
340
|
var x = b[0] - a[0],
|
268
341
|
y = b[1] - a[1];
|
269
342
|
return x*x + y*y;
|
270
343
|
};
|
271
344
|
|
272
345
|
/**
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
346
|
+
* Alias for {@link vec2.squaredDistance}
|
347
|
+
* @function
|
348
|
+
*/
|
349
|
+
vec2.sqrDist = vec2.squaredDistance;
|
350
|
+
|
351
|
+
/**
|
352
|
+
* Calculates the length of a vec2
|
353
|
+
*
|
354
|
+
* @param {vec2} a vector to calculate length of
|
355
|
+
* @returns {Number} length of a
|
356
|
+
*/
|
357
|
+
vec2.length = function (a) {
|
279
358
|
var x = a[0],
|
280
359
|
y = a[1];
|
281
360
|
return Math.sqrt(x*x + y*y);
|
282
361
|
};
|
283
362
|
|
284
363
|
/**
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
364
|
+
* Alias for {@link vec2.length}
|
365
|
+
* @function
|
366
|
+
*/
|
367
|
+
vec2.len = vec2.length;
|
368
|
+
|
369
|
+
/**
|
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
|
+
*/
|
375
|
+
vec2.squaredLength = function (a) {
|
291
376
|
var x = a[0],
|
292
377
|
y = a[1];
|
293
378
|
return x*x + y*y;
|
294
379
|
};
|
295
380
|
|
296
381
|
/**
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
382
|
+
* Alias for {@link vec2.squaredLength}
|
383
|
+
* @function
|
384
|
+
*/
|
385
|
+
vec2.sqrLen = vec2.squaredLength;
|
386
|
+
|
387
|
+
/**
|
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
|
+
*/
|
303
394
|
vec2.negate = function(out, a) {
|
304
395
|
out[0] = -a[0];
|
305
396
|
out[1] = -a[1];
|
@@ -307,12 +398,12 @@ vec2.negate = function(out, a) {
|
|
307
398
|
};
|
308
399
|
|
309
400
|
/**
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
401
|
+
* Normalize a vec2
|
402
|
+
*
|
403
|
+
* @param {vec2} out the receiving vector
|
404
|
+
* @param {vec2} a vector to normalize
|
405
|
+
* @returns {vec2} out
|
406
|
+
*/
|
316
407
|
vec2.normalize = function(out, a) {
|
317
408
|
var x = a[0],
|
318
409
|
y = a[1];
|
@@ -327,25 +418,25 @@ vec2.normalize = function(out, a) {
|
|
327
418
|
};
|
328
419
|
|
329
420
|
/**
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
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
|
+
*/
|
336
427
|
vec2.dot = function (a, b) {
|
337
428
|
return a[0] * b[0] + a[1] * b[1];
|
338
429
|
};
|
339
430
|
|
340
431
|
/**
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
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
|
+
*/
|
349
440
|
vec2.cross = function(out, a, b) {
|
350
441
|
var z = a[0] * b[1] - a[1] * b[0];
|
351
442
|
out[0] = out[1] = 0;
|
@@ -354,14 +445,14 @@ vec2.cross = function(out, a, b) {
|
|
354
445
|
};
|
355
446
|
|
356
447
|
/**
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
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
|
+
*/
|
365
456
|
vec2.lerp = function (out, a, b, t) {
|
366
457
|
var ax = a[0],
|
367
458
|
ay = a[1];
|
@@ -371,34 +462,86 @@ vec2.lerp = function (out, a, b, t) {
|
|
371
462
|
};
|
372
463
|
|
373
464
|
/**
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
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
|
+
*/
|
381
472
|
vec2.transformMat2 = function(out, a, m) {
|
382
473
|
var x = a[0],
|
383
474
|
y = a[1];
|
384
|
-
out[0] =
|
385
|
-
out[1] =
|
475
|
+
out[0] = m[0] * x + m[2] * y;
|
476
|
+
out[1] = m[1] * x + m[3] * y;
|
477
|
+
return out;
|
478
|
+
};
|
479
|
+
|
480
|
+
/**
|
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
|
+
*/
|
488
|
+
vec2.transformMat2d = function(out, a, m) {
|
489
|
+
var x = a[0],
|
490
|
+
y = a[1];
|
491
|
+
out[0] = m[0] * x + m[2] * y + m[4];
|
492
|
+
out[1] = m[1] * x + m[3] * y + m[5];
|
493
|
+
return out;
|
494
|
+
};
|
495
|
+
|
496
|
+
/**
|
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
|
+
*/
|
505
|
+
vec2.transformMat3 = function(out, a, m) {
|
506
|
+
var x = a[0],
|
507
|
+
y = a[1];
|
508
|
+
out[0] = m[0] * x + m[3] * y + m[6];
|
509
|
+
out[1] = m[1] * x + m[4] * y + m[7];
|
510
|
+
return out;
|
511
|
+
};
|
512
|
+
|
513
|
+
/**
|
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
|
+
*/
|
523
|
+
vec2.transformMat4 = function(out, a, m) {
|
524
|
+
var x = a[0],
|
525
|
+
y = a[1];
|
526
|
+
out[0] = m[0] * x + m[4] * y + m[12];
|
527
|
+
out[1] = m[1] * x + m[5] * y + m[13];
|
386
528
|
return out;
|
387
529
|
};
|
388
530
|
|
389
531
|
/**
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
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
|
+
*/
|
400
543
|
vec2.forEach = (function() {
|
401
|
-
var vec =
|
544
|
+
var vec = vec2.create();
|
402
545
|
|
403
546
|
return function(a, stride, offset, count, fn, arg) {
|
404
547
|
var i, l;
|
@@ -427,11 +570,11 @@ vec2.forEach = (function() {
|
|
427
570
|
})();
|
428
571
|
|
429
572
|
/**
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
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
|
+
*/
|
435
578
|
vec2.str = function (a) {
|
436
579
|
return 'vec2(' + a[0] + ', ' + a[1] + ')';
|
437
580
|
};
|
@@ -440,20 +583,20 @@ if(typeof(exports) !== 'undefined') {
|
|
440
583
|
exports.vec2 = vec2;
|
441
584
|
}
|
442
585
|
;
|
443
|
-
/* Copyright (c)
|
586
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
444
587
|
|
445
588
|
Redistribution and use in source and binary forms, with or without modification,
|
446
589
|
are permitted provided that the following conditions are met:
|
447
590
|
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
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.
|
453
596
|
|
454
597
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
455
598
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
456
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
599
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
457
600
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
458
601
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
459
602
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -463,33 +606,33 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
463
606
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
464
607
|
|
465
608
|
/**
|
466
|
-
|
467
|
-
|
468
|
-
|
609
|
+
* @class 3 Dimensional Vector
|
610
|
+
* @name vec3
|
611
|
+
*/
|
469
612
|
|
470
613
|
var vec3 = {};
|
471
614
|
|
472
|
-
if(!GLMAT_EPSILON) {
|
473
|
-
var GLMAT_EPSILON = 0.000001;
|
474
|
-
}
|
475
|
-
|
476
615
|
/**
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
616
|
+
* Creates a new, empty vec3
|
617
|
+
*
|
618
|
+
* @returns {vec3} a new 3D vector
|
619
|
+
*/
|
481
620
|
vec3.create = function() {
|
482
|
-
|
621
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
622
|
+
out[0] = 0;
|
623
|
+
out[1] = 0;
|
624
|
+
out[2] = 0;
|
625
|
+
return out;
|
483
626
|
};
|
484
627
|
|
485
628
|
/**
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
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
|
+
*/
|
491
634
|
vec3.clone = function(a) {
|
492
|
-
var out = new
|
635
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
493
636
|
out[0] = a[0];
|
494
637
|
out[1] = a[1];
|
495
638
|
out[2] = a[2];
|
@@ -497,15 +640,15 @@ vec3.clone = function(a) {
|
|
497
640
|
};
|
498
641
|
|
499
642
|
/**
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
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
|
+
*/
|
507
650
|
vec3.fromValues = function(x, y, z) {
|
508
|
-
var out = new
|
651
|
+
var out = new GLMAT_ARRAY_TYPE(3);
|
509
652
|
out[0] = x;
|
510
653
|
out[1] = y;
|
511
654
|
out[2] = z;
|
@@ -513,12 +656,12 @@ vec3.fromValues = function(x, y, z) {
|
|
513
656
|
};
|
514
657
|
|
515
658
|
/**
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
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
|
+
*/
|
522
665
|
vec3.copy = function(out, a) {
|
523
666
|
out[0] = a[0];
|
524
667
|
out[1] = a[1];
|
@@ -527,14 +670,14 @@ vec3.copy = function(out, a) {
|
|
527
670
|
};
|
528
671
|
|
529
672
|
/**
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
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
|
+
*/
|
538
681
|
vec3.set = function(out, x, y, z) {
|
539
682
|
out[0] = x;
|
540
683
|
out[1] = y;
|
@@ -543,13 +686,13 @@ vec3.set = function(out, x, y, z) {
|
|
543
686
|
};
|
544
687
|
|
545
688
|
/**
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
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
|
+
*/
|
553
696
|
vec3.add = function(out, a, b) {
|
554
697
|
out[0] = a[0] + b[0];
|
555
698
|
out[1] = a[1] + b[1];
|
@@ -558,14 +701,14 @@ vec3.add = function(out, a, b) {
|
|
558
701
|
};
|
559
702
|
|
560
703
|
/**
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
vec3.
|
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
|
+
*/
|
711
|
+
vec3.subtract = function(out, a, b) {
|
569
712
|
out[0] = a[0] - b[0];
|
570
713
|
out[1] = a[1] - b[1];
|
571
714
|
out[2] = a[2] - b[2];
|
@@ -573,14 +716,20 @@ vec3.sub = vec3.subtract = function(out, a, b) {
|
|
573
716
|
};
|
574
717
|
|
575
718
|
/**
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
719
|
+
* Alias for {@link vec3.subtract}
|
720
|
+
* @function
|
721
|
+
*/
|
722
|
+
vec3.sub = vec3.subtract;
|
723
|
+
|
724
|
+
/**
|
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
|
+
*/
|
732
|
+
vec3.multiply = function(out, a, b) {
|
584
733
|
out[0] = a[0] * b[0];
|
585
734
|
out[1] = a[1] * b[1];
|
586
735
|
out[2] = a[2] * b[2];
|
@@ -588,14 +737,20 @@ vec3.mul = vec3.multiply = function(out, a, b) {
|
|
588
737
|
};
|
589
738
|
|
590
739
|
/**
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
740
|
+
* Alias for {@link vec3.multiply}
|
741
|
+
* @function
|
742
|
+
*/
|
743
|
+
vec3.mul = vec3.multiply;
|
744
|
+
|
745
|
+
/**
|
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
|
+
*/
|
753
|
+
vec3.divide = function(out, a, b) {
|
599
754
|
out[0] = a[0] / b[0];
|
600
755
|
out[1] = a[1] / b[1];
|
601
756
|
out[2] = a[2] / b[2];
|
@@ -603,13 +758,19 @@ vec3.div = vec3.divide = function(out, a, b) {
|
|
603
758
|
};
|
604
759
|
|
605
760
|
/**
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
761
|
+
* Alias for {@link vec3.divide}
|
762
|
+
* @function
|
763
|
+
*/
|
764
|
+
vec3.div = vec3.divide;
|
765
|
+
|
766
|
+
/**
|
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
|
+
*/
|
613
774
|
vec3.min = function(out, a, b) {
|
614
775
|
out[0] = Math.min(a[0], b[0]);
|
615
776
|
out[1] = Math.min(a[1], b[1]);
|
@@ -618,13 +779,13 @@ vec3.min = function(out, a, b) {
|
|
618
779
|
};
|
619
780
|
|
620
781
|
/**
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
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
|
+
*/
|
628
789
|
vec3.max = function(out, a, b) {
|
629
790
|
out[0] = Math.max(a[0], b[0]);
|
630
791
|
out[1] = Math.max(a[1], b[1]);
|
@@ -633,13 +794,13 @@ vec3.max = function(out, a, b) {
|
|
633
794
|
};
|
634
795
|
|
635
796
|
/**
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
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
|
+
*/
|
643
804
|
vec3.scale = function(out, a, b) {
|
644
805
|
out[0] = a[0] * b;
|
645
806
|
out[1] = a[1] * b;
|
@@ -648,13 +809,13 @@ vec3.scale = function(out, a, b) {
|
|
648
809
|
};
|
649
810
|
|
650
811
|
/**
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
vec3.
|
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
|
+
*/
|
818
|
+
vec3.distance = function(a, b) {
|
658
819
|
var x = b[0] - a[0],
|
659
820
|
y = b[1] - a[1],
|
660
821
|
z = b[2] - a[2];
|
@@ -662,13 +823,19 @@ vec3.dist = vec3.distance = function(a, b) {
|
|
662
823
|
};
|
663
824
|
|
664
825
|
/**
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
826
|
+
* Alias for {@link vec3.distance}
|
827
|
+
* @function
|
828
|
+
*/
|
829
|
+
vec3.dist = vec3.distance;
|
830
|
+
|
831
|
+
/**
|
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
|
+
*/
|
838
|
+
vec3.squaredDistance = function(a, b) {
|
672
839
|
var x = b[0] - a[0],
|
673
840
|
y = b[1] - a[1],
|
674
841
|
z = b[2] - a[2];
|
@@ -676,12 +843,18 @@ vec3.sqrDist = vec3.squaredDistance = function(a, b) {
|
|
676
843
|
};
|
677
844
|
|
678
845
|
/**
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
846
|
+
* Alias for {@link vec3.squaredDistance}
|
847
|
+
* @function
|
848
|
+
*/
|
849
|
+
vec3.sqrDist = vec3.squaredDistance;
|
850
|
+
|
851
|
+
/**
|
852
|
+
* Calculates the length of a vec3
|
853
|
+
*
|
854
|
+
* @param {vec3} a vector to calculate length of
|
855
|
+
* @returns {Number} length of a
|
856
|
+
*/
|
857
|
+
vec3.length = function (a) {
|
685
858
|
var x = a[0],
|
686
859
|
y = a[1],
|
687
860
|
z = a[2];
|
@@ -689,12 +862,18 @@ vec3.len = vec3.length = function (a) {
|
|
689
862
|
};
|
690
863
|
|
691
864
|
/**
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
865
|
+
* Alias for {@link vec3.length}
|
866
|
+
* @function
|
867
|
+
*/
|
868
|
+
vec3.len = vec3.length;
|
869
|
+
|
870
|
+
/**
|
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
|
+
*/
|
876
|
+
vec3.squaredLength = function (a) {
|
698
877
|
var x = a[0],
|
699
878
|
y = a[1],
|
700
879
|
z = a[2];
|
@@ -702,12 +881,18 @@ vec3.sqrLen = vec3.squaredLength = function (a) {
|
|
702
881
|
};
|
703
882
|
|
704
883
|
/**
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
884
|
+
* Alias for {@link vec3.squaredLength}
|
885
|
+
* @function
|
886
|
+
*/
|
887
|
+
vec3.sqrLen = vec3.squaredLength;
|
888
|
+
|
889
|
+
/**
|
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
|
+
*/
|
711
896
|
vec3.negate = function(out, a) {
|
712
897
|
out[0] = -a[0];
|
713
898
|
out[1] = -a[1];
|
@@ -716,12 +901,12 @@ vec3.negate = function(out, a) {
|
|
716
901
|
};
|
717
902
|
|
718
903
|
/**
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
904
|
+
* Normalize a vec3
|
905
|
+
*
|
906
|
+
* @param {vec3} out the receiving vector
|
907
|
+
* @param {vec3} a vector to normalize
|
908
|
+
* @returns {vec3} out
|
909
|
+
*/
|
725
910
|
vec3.normalize = function(out, a) {
|
726
911
|
var x = a[0],
|
727
912
|
y = a[1],
|
@@ -738,24 +923,24 @@ vec3.normalize = function(out, a) {
|
|
738
923
|
};
|
739
924
|
|
740
925
|
/**
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
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
|
+
*/
|
747
932
|
vec3.dot = function (a, b) {
|
748
933
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
749
934
|
};
|
750
935
|
|
751
936
|
/**
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
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
|
+
*/
|
759
944
|
vec3.cross = function(out, a, b) {
|
760
945
|
var ax = a[0], ay = a[1], az = a[2],
|
761
946
|
bx = b[0], by = b[1], bz = b[2];
|
@@ -767,14 +952,14 @@ vec3.cross = function(out, a, b) {
|
|
767
952
|
};
|
768
953
|
|
769
954
|
/**
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
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
|
+
*/
|
778
963
|
vec3.lerp = function (out, a, b, t) {
|
779
964
|
var ax = a[0],
|
780
965
|
ay = a[1],
|
@@ -786,14 +971,14 @@ vec3.lerp = function (out, a, b, t) {
|
|
786
971
|
};
|
787
972
|
|
788
973
|
/**
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
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
|
+
*/
|
797
982
|
vec3.transformMat4 = function(out, a, m) {
|
798
983
|
var x = a[0], y = a[1], z = a[2];
|
799
984
|
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12];
|
@@ -803,13 +988,13 @@ vec3.transformMat4 = function(out, a, m) {
|
|
803
988
|
};
|
804
989
|
|
805
990
|
/**
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
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
|
+
*/
|
813
998
|
vec3.transformQuat = function(out, a, q) {
|
814
999
|
var x = a[0], y = a[1], z = a[2],
|
815
1000
|
qx = q[0], qy = q[1], qz = q[2], qw = q[3],
|
@@ -828,18 +1013,19 @@ vec3.transformQuat = function(out, a, q) {
|
|
828
1013
|
};
|
829
1014
|
|
830
1015
|
/**
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
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
|
+
*/
|
841
1027
|
vec3.forEach = (function() {
|
842
|
-
var vec =
|
1028
|
+
var vec = vec3.create();
|
843
1029
|
|
844
1030
|
return function(a, stride, offset, count, fn, arg) {
|
845
1031
|
var i, l;
|
@@ -868,11 +1054,11 @@ vec3.forEach = (function() {
|
|
868
1054
|
})();
|
869
1055
|
|
870
1056
|
/**
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
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
|
+
*/
|
876
1062
|
vec3.str = function (a) {
|
877
1063
|
return 'vec3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ')';
|
878
1064
|
};
|
@@ -881,20 +1067,20 @@ if(typeof(exports) !== 'undefined') {
|
|
881
1067
|
exports.vec3 = vec3;
|
882
1068
|
}
|
883
1069
|
;
|
884
|
-
/* Copyright (c)
|
1070
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
885
1071
|
|
886
1072
|
Redistribution and use in source and binary forms, with or without modification,
|
887
1073
|
are permitted provided that the following conditions are met:
|
888
1074
|
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
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.
|
894
1080
|
|
895
1081
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
896
1082
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
897
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1083
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
898
1084
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
899
1085
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
900
1086
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -904,33 +1090,34 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
904
1090
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
905
1091
|
|
906
1092
|
/**
|
907
|
-
|
908
|
-
|
909
|
-
|
1093
|
+
* @class 4 Dimensional Vector
|
1094
|
+
* @name vec4
|
1095
|
+
*/
|
910
1096
|
|
911
1097
|
var vec4 = {};
|
912
1098
|
|
913
|
-
if(!GLMAT_EPSILON) {
|
914
|
-
var GLMAT_EPSILON = 0.000001;
|
915
|
-
}
|
916
|
-
|
917
1099
|
/**
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
1100
|
+
* Creates a new, empty vec4
|
1101
|
+
*
|
1102
|
+
* @returns {vec4} a new 4D vector
|
1103
|
+
*/
|
922
1104
|
vec4.create = function() {
|
923
|
-
|
1105
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1106
|
+
out[0] = 0;
|
1107
|
+
out[1] = 0;
|
1108
|
+
out[2] = 0;
|
1109
|
+
out[3] = 0;
|
1110
|
+
return out;
|
924
1111
|
};
|
925
1112
|
|
926
1113
|
/**
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
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
|
+
*/
|
932
1119
|
vec4.clone = function(a) {
|
933
|
-
var out = new
|
1120
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
934
1121
|
out[0] = a[0];
|
935
1122
|
out[1] = a[1];
|
936
1123
|
out[2] = a[2];
|
@@ -939,16 +1126,16 @@ vec4.clone = function(a) {
|
|
939
1126
|
};
|
940
1127
|
|
941
1128
|
/**
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
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
|
+
*/
|
950
1137
|
vec4.fromValues = function(x, y, z, w) {
|
951
|
-
var out = new
|
1138
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
952
1139
|
out[0] = x;
|
953
1140
|
out[1] = y;
|
954
1141
|
out[2] = z;
|
@@ -957,12 +1144,12 @@ vec4.fromValues = function(x, y, z, w) {
|
|
957
1144
|
};
|
958
1145
|
|
959
1146
|
/**
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
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
|
+
*/
|
966
1153
|
vec4.copy = function(out, a) {
|
967
1154
|
out[0] = a[0];
|
968
1155
|
out[1] = a[1];
|
@@ -972,15 +1159,15 @@ vec4.copy = function(out, a) {
|
|
972
1159
|
};
|
973
1160
|
|
974
1161
|
/**
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
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
|
+
*/
|
984
1171
|
vec4.set = function(out, x, y, z, w) {
|
985
1172
|
out[0] = x;
|
986
1173
|
out[1] = y;
|
@@ -990,13 +1177,13 @@ vec4.set = function(out, x, y, z, w) {
|
|
990
1177
|
};
|
991
1178
|
|
992
1179
|
/**
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
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
|
+
*/
|
1000
1187
|
vec4.add = function(out, a, b) {
|
1001
1188
|
out[0] = a[0] + b[0];
|
1002
1189
|
out[1] = a[1] + b[1];
|
@@ -1006,14 +1193,14 @@ vec4.add = function(out, a, b) {
|
|
1006
1193
|
};
|
1007
1194
|
|
1008
1195
|
/**
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
vec4.
|
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
|
+
*/
|
1203
|
+
vec4.subtract = function(out, a, b) {
|
1017
1204
|
out[0] = a[0] - b[0];
|
1018
1205
|
out[1] = a[1] - b[1];
|
1019
1206
|
out[2] = a[2] - b[2];
|
@@ -1022,14 +1209,20 @@ vec4.sub = vec4.subtract = function(out, a, b) {
|
|
1022
1209
|
};
|
1023
1210
|
|
1024
1211
|
/**
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1212
|
+
* Alias for {@link vec4.subtract}
|
1213
|
+
* @function
|
1214
|
+
*/
|
1215
|
+
vec4.sub = vec4.subtract;
|
1216
|
+
|
1217
|
+
/**
|
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
|
+
*/
|
1225
|
+
vec4.multiply = function(out, a, b) {
|
1033
1226
|
out[0] = a[0] * b[0];
|
1034
1227
|
out[1] = a[1] * b[1];
|
1035
1228
|
out[2] = a[2] * b[2];
|
@@ -1038,14 +1231,20 @@ vec4.mul = vec4.multiply = function(out, a, b) {
|
|
1038
1231
|
};
|
1039
1232
|
|
1040
1233
|
/**
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1234
|
+
* Alias for {@link vec4.multiply}
|
1235
|
+
* @function
|
1236
|
+
*/
|
1237
|
+
vec4.mul = vec4.multiply;
|
1238
|
+
|
1239
|
+
/**
|
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
|
+
*/
|
1247
|
+
vec4.divide = function(out, a, b) {
|
1049
1248
|
out[0] = a[0] / b[0];
|
1050
1249
|
out[1] = a[1] / b[1];
|
1051
1250
|
out[2] = a[2] / b[2];
|
@@ -1054,13 +1253,19 @@ vec4.div = vec4.divide = function(out, a, b) {
|
|
1054
1253
|
};
|
1055
1254
|
|
1056
1255
|
/**
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1256
|
+
* Alias for {@link vec4.divide}
|
1257
|
+
* @function
|
1258
|
+
*/
|
1259
|
+
vec4.div = vec4.divide;
|
1260
|
+
|
1261
|
+
/**
|
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
|
+
*/
|
1064
1269
|
vec4.min = function(out, a, b) {
|
1065
1270
|
out[0] = Math.min(a[0], b[0]);
|
1066
1271
|
out[1] = Math.min(a[1], b[1]);
|
@@ -1070,13 +1275,13 @@ vec4.min = function(out, a, b) {
|
|
1070
1275
|
};
|
1071
1276
|
|
1072
1277
|
/**
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
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
|
+
*/
|
1080
1285
|
vec4.max = function(out, a, b) {
|
1081
1286
|
out[0] = Math.max(a[0], b[0]);
|
1082
1287
|
out[1] = Math.max(a[1], b[1]);
|
@@ -1086,13 +1291,13 @@ vec4.max = function(out, a, b) {
|
|
1086
1291
|
};
|
1087
1292
|
|
1088
1293
|
/**
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
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
|
+
*/
|
1096
1301
|
vec4.scale = function(out, a, b) {
|
1097
1302
|
out[0] = a[0] * b;
|
1098
1303
|
out[1] = a[1] * b;
|
@@ -1102,13 +1307,13 @@ vec4.scale = function(out, a, b) {
|
|
1102
1307
|
};
|
1103
1308
|
|
1104
1309
|
/**
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
vec4.
|
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
|
+
*/
|
1316
|
+
vec4.distance = function(a, b) {
|
1112
1317
|
var x = b[0] - a[0],
|
1113
1318
|
y = b[1] - a[1],
|
1114
1319
|
z = b[2] - a[2],
|
@@ -1117,13 +1322,19 @@ vec4.dist = vec4.distance = function(a, b) {
|
|
1117
1322
|
};
|
1118
1323
|
|
1119
1324
|
/**
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1325
|
+
* Alias for {@link vec4.distance}
|
1326
|
+
* @function
|
1327
|
+
*/
|
1328
|
+
vec4.dist = vec4.distance;
|
1329
|
+
|
1330
|
+
/**
|
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
|
+
*/
|
1337
|
+
vec4.squaredDistance = function(a, b) {
|
1127
1338
|
var x = b[0] - a[0],
|
1128
1339
|
y = b[1] - a[1],
|
1129
1340
|
z = b[2] - a[2],
|
@@ -1132,12 +1343,18 @@ vec4.sqrDist = vec4.squaredDistance = function(a, b) {
|
|
1132
1343
|
};
|
1133
1344
|
|
1134
1345
|
/**
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1346
|
+
* Alias for {@link vec4.squaredDistance}
|
1347
|
+
* @function
|
1348
|
+
*/
|
1349
|
+
vec4.sqrDist = vec4.squaredDistance;
|
1350
|
+
|
1351
|
+
/**
|
1352
|
+
* Calculates the length of a vec4
|
1353
|
+
*
|
1354
|
+
* @param {vec4} a vector to calculate length of
|
1355
|
+
* @returns {Number} length of a
|
1356
|
+
*/
|
1357
|
+
vec4.length = function (a) {
|
1141
1358
|
var x = a[0],
|
1142
1359
|
y = a[1],
|
1143
1360
|
z = a[2],
|
@@ -1146,12 +1363,18 @@ vec4.len = vec4.length = function (a) {
|
|
1146
1363
|
};
|
1147
1364
|
|
1148
1365
|
/**
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1366
|
+
* Alias for {@link vec4.length}
|
1367
|
+
* @function
|
1368
|
+
*/
|
1369
|
+
vec4.len = vec4.length;
|
1370
|
+
|
1371
|
+
/**
|
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
|
+
*/
|
1377
|
+
vec4.squaredLength = function (a) {
|
1155
1378
|
var x = a[0],
|
1156
1379
|
y = a[1],
|
1157
1380
|
z = a[2],
|
@@ -1160,12 +1383,18 @@ vec4.sqrLen = vec4.squaredLength = function (a) {
|
|
1160
1383
|
};
|
1161
1384
|
|
1162
1385
|
/**
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1386
|
+
* Alias for {@link vec4.squaredLength}
|
1387
|
+
* @function
|
1388
|
+
*/
|
1389
|
+
vec4.sqrLen = vec4.squaredLength;
|
1390
|
+
|
1391
|
+
/**
|
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
|
+
*/
|
1169
1398
|
vec4.negate = function(out, a) {
|
1170
1399
|
out[0] = -a[0];
|
1171
1400
|
out[1] = -a[1];
|
@@ -1175,12 +1404,12 @@ vec4.negate = function(out, a) {
|
|
1175
1404
|
};
|
1176
1405
|
|
1177
1406
|
/**
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1407
|
+
* Normalize a vec4
|
1408
|
+
*
|
1409
|
+
* @param {vec4} out the receiving vector
|
1410
|
+
* @param {vec4} a vector to normalize
|
1411
|
+
* @returns {vec4} out
|
1412
|
+
*/
|
1184
1413
|
vec4.normalize = function(out, a) {
|
1185
1414
|
var x = a[0],
|
1186
1415
|
y = a[1],
|
@@ -1198,25 +1427,25 @@ vec4.normalize = function(out, a) {
|
|
1198
1427
|
};
|
1199
1428
|
|
1200
1429
|
/**
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
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
|
+
*/
|
1207
1436
|
vec4.dot = function (a, b) {
|
1208
1437
|
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
1209
1438
|
};
|
1210
1439
|
|
1211
1440
|
/**
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
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
|
+
*/
|
1220
1449
|
vec4.lerp = function (out, a, b, t) {
|
1221
1450
|
var ax = a[0],
|
1222
1451
|
ay = a[1],
|
@@ -1230,13 +1459,13 @@ vec4.lerp = function (out, a, b, t) {
|
|
1230
1459
|
};
|
1231
1460
|
|
1232
1461
|
/**
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
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
|
+
*/
|
1240
1469
|
vec4.transformMat4 = function(out, a, m) {
|
1241
1470
|
var x = a[0], y = a[1], z = a[2], w = a[3];
|
1242
1471
|
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
@@ -1247,13 +1476,13 @@ vec4.transformMat4 = function(out, a, m) {
|
|
1247
1476
|
};
|
1248
1477
|
|
1249
1478
|
/**
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
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
|
+
*/
|
1257
1486
|
vec4.transformQuat = function(out, a, q) {
|
1258
1487
|
var x = a[0], y = a[1], z = a[2],
|
1259
1488
|
qx = q[0], qy = q[1], qz = q[2], qw = q[3],
|
@@ -1272,18 +1501,19 @@ vec4.transformQuat = function(out, a, q) {
|
|
1272
1501
|
};
|
1273
1502
|
|
1274
1503
|
/**
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
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
|
+
*/
|
1285
1515
|
vec4.forEach = (function() {
|
1286
|
-
var vec =
|
1516
|
+
var vec = vec4.create();
|
1287
1517
|
|
1288
1518
|
return function(a, stride, offset, count, fn, arg) {
|
1289
1519
|
var i, l;
|
@@ -1312,11 +1542,11 @@ vec4.forEach = (function() {
|
|
1312
1542
|
})();
|
1313
1543
|
|
1314
1544
|
/**
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
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
|
+
*/
|
1320
1550
|
vec4.str = function (a) {
|
1321
1551
|
return 'vec4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
1322
1552
|
};
|
@@ -1325,20 +1555,20 @@ if(typeof(exports) !== 'undefined') {
|
|
1325
1555
|
exports.vec4 = vec4;
|
1326
1556
|
}
|
1327
1557
|
;
|
1328
|
-
/* Copyright (c)
|
1558
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1329
1559
|
|
1330
1560
|
Redistribution and use in source and binary forms, with or without modification,
|
1331
1561
|
are permitted provided that the following conditions are met:
|
1332
1562
|
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
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.
|
1338
1568
|
|
1339
1569
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1340
1570
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1341
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1571
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1342
1572
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1343
1573
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1344
1574
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -1348,9 +1578,9 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1348
1578
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1349
1579
|
|
1350
1580
|
/**
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1581
|
+
* @class 2x2 Matrix
|
1582
|
+
* @name mat2
|
1583
|
+
*/
|
1354
1584
|
|
1355
1585
|
var mat2 = {};
|
1356
1586
|
|
@@ -1359,27 +1589,28 @@ var mat2Identity = new Float32Array([
|
|
1359
1589
|
0, 1
|
1360
1590
|
]);
|
1361
1591
|
|
1362
|
-
if(!GLMAT_EPSILON) {
|
1363
|
-
var GLMAT_EPSILON = 0.000001;
|
1364
|
-
}
|
1365
|
-
|
1366
1592
|
/**
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1593
|
+
* Creates a new identity mat2
|
1594
|
+
*
|
1595
|
+
* @returns {mat2} a new 2x2 matrix
|
1596
|
+
*/
|
1371
1597
|
mat2.create = function() {
|
1372
|
-
|
1598
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1599
|
+
out[0] = 1;
|
1600
|
+
out[1] = 0;
|
1601
|
+
out[2] = 0;
|
1602
|
+
out[3] = 1;
|
1603
|
+
return out;
|
1373
1604
|
};
|
1374
1605
|
|
1375
1606
|
/**
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
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
|
+
*/
|
1381
1612
|
mat2.clone = function(a) {
|
1382
|
-
var out = new
|
1613
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
1383
1614
|
out[0] = a[0];
|
1384
1615
|
out[1] = a[1];
|
1385
1616
|
out[2] = a[2];
|
@@ -1388,12 +1619,12 @@ mat2.clone = function(a) {
|
|
1388
1619
|
};
|
1389
1620
|
|
1390
1621
|
/**
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
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
|
+
*/
|
1397
1628
|
mat2.copy = function(out, a) {
|
1398
1629
|
out[0] = a[0];
|
1399
1630
|
out[1] = a[1];
|
@@ -1403,11 +1634,11 @@ mat2.copy = function(out, a) {
|
|
1403
1634
|
};
|
1404
1635
|
|
1405
1636
|
/**
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1637
|
+
* Set a mat2 to the identity matrix
|
1638
|
+
*
|
1639
|
+
* @param {mat2} out the receiving matrix
|
1640
|
+
* @returns {mat2} out
|
1641
|
+
*/
|
1411
1642
|
mat2.identity = function(out) {
|
1412
1643
|
out[0] = 1;
|
1413
1644
|
out[1] = 0;
|
@@ -1417,12 +1648,12 @@ mat2.identity = function(out) {
|
|
1417
1648
|
};
|
1418
1649
|
|
1419
1650
|
/**
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
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
|
+
*/
|
1426
1657
|
mat2.transpose = function(out, a) {
|
1427
1658
|
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
1428
1659
|
if (out === a) {
|
@@ -1440,12 +1671,12 @@ mat2.transpose = function(out, a) {
|
|
1440
1671
|
};
|
1441
1672
|
|
1442
1673
|
/**
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1674
|
+
* Inverts a mat2
|
1675
|
+
*
|
1676
|
+
* @param {mat2} out the receiving matrix
|
1677
|
+
* @param {mat2} a the source matrix
|
1678
|
+
* @returns {mat2} out
|
1679
|
+
*/
|
1449
1680
|
mat2.invert = function(out, a) {
|
1450
1681
|
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1451
1682
|
|
@@ -1457,51 +1688,51 @@ mat2.invert = function(out, a) {
|
|
1457
1688
|
}
|
1458
1689
|
det = 1.0 / det;
|
1459
1690
|
|
1460
|
-
out[0] =
|
1691
|
+
out[0] = a3 * det;
|
1461
1692
|
out[1] = -a1 * det;
|
1462
1693
|
out[2] = -a2 * det;
|
1463
|
-
out[3] =
|
1694
|
+
out[3] = a0 * det;
|
1464
1695
|
|
1465
1696
|
return out;
|
1466
1697
|
};
|
1467
1698
|
|
1468
1699
|
/**
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
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
|
+
*/
|
1475
1706
|
mat2.adjoint = function(out, a) {
|
1476
1707
|
// Caching this value is nessecary if out == a
|
1477
1708
|
var a0 = a[0];
|
1478
|
-
out[0] =
|
1709
|
+
out[0] = a[3];
|
1479
1710
|
out[1] = -a[1];
|
1480
1711
|
out[2] = -a[2];
|
1481
|
-
out[3] =
|
1712
|
+
out[3] = a0;
|
1482
1713
|
|
1483
1714
|
return out;
|
1484
1715
|
};
|
1485
1716
|
|
1486
1717
|
/**
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1718
|
+
* Calculates the determinant of a mat2
|
1719
|
+
*
|
1720
|
+
* @param {mat2} a the source matrix
|
1721
|
+
* @returns {Number} determinant of a
|
1722
|
+
*/
|
1492
1723
|
mat2.determinant = function (a) {
|
1493
1724
|
return a[0] * a[3] - a[2] * a[1];
|
1494
1725
|
};
|
1495
1726
|
|
1496
1727
|
/**
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
mat2.
|
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
|
+
*/
|
1735
|
+
mat2.multiply = function (out, a, b) {
|
1505
1736
|
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
|
1506
1737
|
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
1507
1738
|
out[0] = a0 * b0 + a1 * b2;
|
@@ -1512,32 +1743,38 @@ mat2.mul = mat2.multiply = function (out, a, b) {
|
|
1512
1743
|
};
|
1513
1744
|
|
1514
1745
|
/**
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1746
|
+
* Alias for {@link mat2.multiply}
|
1747
|
+
* @function
|
1748
|
+
*/
|
1749
|
+
mat2.mul = mat2.multiply;
|
1750
|
+
|
1751
|
+
/**
|
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
|
+
*/
|
1522
1759
|
mat2.rotate = function (out, a, rad) {
|
1523
1760
|
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1524
1761
|
s = Math.sin(rad),
|
1525
1762
|
c = Math.cos(rad);
|
1526
|
-
out[0] = a0 *
|
1763
|
+
out[0] = a0 * c + a1 * s;
|
1527
1764
|
out[1] = a0 * -s + a1 * c;
|
1528
|
-
out[2] = a2 *
|
1765
|
+
out[2] = a2 * c + a3 * s;
|
1529
1766
|
out[3] = a2 * -s + a3 * c;
|
1530
1767
|
return out;
|
1531
1768
|
};
|
1532
1769
|
|
1533
1770
|
/**
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
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
|
+
**/
|
1541
1778
|
mat2.scale = function(out, a, v) {
|
1542
1779
|
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
1543
1780
|
v0 = v[0], v1 = v[1];
|
@@ -1549,11 +1786,11 @@ mat2.scale = function(out, a, v) {
|
|
1549
1786
|
};
|
1550
1787
|
|
1551
1788
|
/**
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
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
|
+
*/
|
1557
1794
|
mat2.str = function (a) {
|
1558
1795
|
return 'mat2(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
1559
1796
|
};
|
@@ -1562,20 +1799,20 @@ if(typeof(exports) !== 'undefined') {
|
|
1562
1799
|
exports.mat2 = mat2;
|
1563
1800
|
}
|
1564
1801
|
;
|
1565
|
-
/* Copyright (c)
|
1802
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1566
1803
|
|
1567
1804
|
Redistribution and use in source and binary forms, with or without modification,
|
1568
1805
|
are permitted provided that the following conditions are met:
|
1569
1806
|
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
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.
|
1575
1812
|
|
1576
1813
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1577
1814
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1578
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1815
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1579
1816
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1580
1817
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1581
1818
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -1585,9 +1822,270 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1585
1822
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1586
1823
|
|
1587
1824
|
/**
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
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
|
+
*/
|
1843
|
+
|
1844
|
+
var mat2d = {};
|
1845
|
+
|
1846
|
+
var mat2dIdentity = new Float32Array([
|
1847
|
+
1, 0,
|
1848
|
+
0, 1,
|
1849
|
+
0, 0
|
1850
|
+
]);
|
1851
|
+
|
1852
|
+
/**
|
1853
|
+
* Creates a new identity mat2d
|
1854
|
+
*
|
1855
|
+
* @returns {mat2d} a new 2x3 matrix
|
1856
|
+
*/
|
1857
|
+
mat2d.create = function() {
|
1858
|
+
var out = new GLMAT_ARRAY_TYPE(6);
|
1859
|
+
out[0] = 1;
|
1860
|
+
out[1] = 0;
|
1861
|
+
out[2] = 0;
|
1862
|
+
out[3] = 1;
|
1863
|
+
out[4] = 0;
|
1864
|
+
out[5] = 0;
|
1865
|
+
return out;
|
1866
|
+
};
|
1867
|
+
|
1868
|
+
/**
|
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
|
+
*/
|
1874
|
+
mat2d.clone = function(a) {
|
1875
|
+
var out = new GLMAT_ARRAY_TYPE(6);
|
1876
|
+
out[0] = a[0];
|
1877
|
+
out[1] = a[1];
|
1878
|
+
out[2] = a[2];
|
1879
|
+
out[3] = a[3];
|
1880
|
+
out[4] = a[4];
|
1881
|
+
out[5] = a[5];
|
1882
|
+
return out;
|
1883
|
+
};
|
1884
|
+
|
1885
|
+
/**
|
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
|
+
*/
|
1892
|
+
mat2d.copy = function(out, a) {
|
1893
|
+
out[0] = a[0];
|
1894
|
+
out[1] = a[1];
|
1895
|
+
out[2] = a[2];
|
1896
|
+
out[3] = a[3];
|
1897
|
+
out[4] = a[4];
|
1898
|
+
out[5] = a[5];
|
1899
|
+
return out;
|
1900
|
+
};
|
1901
|
+
|
1902
|
+
/**
|
1903
|
+
* Set a mat2d to the identity matrix
|
1904
|
+
*
|
1905
|
+
* @param {mat2d} out the receiving matrix
|
1906
|
+
* @returns {mat2d} out
|
1907
|
+
*/
|
1908
|
+
mat2d.identity = function(out) {
|
1909
|
+
out[0] = 1;
|
1910
|
+
out[1] = 0;
|
1911
|
+
out[2] = 0;
|
1912
|
+
out[3] = 1;
|
1913
|
+
out[4] = 0;
|
1914
|
+
out[5] = 0;
|
1915
|
+
return out;
|
1916
|
+
};
|
1917
|
+
|
1918
|
+
/**
|
1919
|
+
* Inverts a mat2d
|
1920
|
+
*
|
1921
|
+
* @param {mat2d} out the receiving matrix
|
1922
|
+
* @param {mat2d} a the source matrix
|
1923
|
+
* @returns {mat2d} out
|
1924
|
+
*/
|
1925
|
+
mat2d.invert = function(out, a) {
|
1926
|
+
var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
|
1927
|
+
atx = a[4], aty = a[5];
|
1928
|
+
|
1929
|
+
var det = aa * ad - ab * ac;
|
1930
|
+
if(!det){
|
1931
|
+
return null;
|
1932
|
+
}
|
1933
|
+
det = 1.0 / det;
|
1934
|
+
|
1935
|
+
out[0] = ad * det;
|
1936
|
+
out[1] = -ab * det;
|
1937
|
+
out[2] = -ac * det;
|
1938
|
+
out[3] = aa * det;
|
1939
|
+
out[4] = (ac * aty - ad * atx) * det;
|
1940
|
+
out[5] = (ab * atx - aa * aty) * det;
|
1941
|
+
return out;
|
1942
|
+
};
|
1943
|
+
|
1944
|
+
/**
|
1945
|
+
* Calculates the determinant of a mat2d
|
1946
|
+
*
|
1947
|
+
* @param {mat2d} a the source matrix
|
1948
|
+
* @returns {Number} determinant of a
|
1949
|
+
*/
|
1950
|
+
mat2d.determinant = function (a) {
|
1951
|
+
return a[0] * a[3] - a[1] * a[2];
|
1952
|
+
};
|
1953
|
+
|
1954
|
+
/**
|
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
|
+
*/
|
1962
|
+
mat2d.multiply = function (out, a, b) {
|
1963
|
+
var aa = a[0], ab = a[1], ac = a[2], ad = a[3],
|
1964
|
+
atx = a[4], aty = a[5],
|
1965
|
+
ba = b[0], bb = b[1], bc = b[2], bd = b[3],
|
1966
|
+
btx = b[4], bty = b[5];
|
1967
|
+
|
1968
|
+
out[0] = aa*ba + ab*bc;
|
1969
|
+
out[1] = aa*bb + ab*bd;
|
1970
|
+
out[2] = ac*ba + ad*bc;
|
1971
|
+
out[3] = ac*bb + ad*bd;
|
1972
|
+
out[4] = ba*atx + bc*aty + btx;
|
1973
|
+
out[5] = bb*atx + bd*aty + bty;
|
1974
|
+
return out;
|
1975
|
+
};
|
1976
|
+
|
1977
|
+
/**
|
1978
|
+
* Alias for {@link mat2d.multiply}
|
1979
|
+
* @function
|
1980
|
+
*/
|
1981
|
+
mat2d.mul = mat2d.multiply;
|
1982
|
+
|
1983
|
+
|
1984
|
+
/**
|
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
|
+
*/
|
1992
|
+
mat2d.rotate = function (out, a, rad) {
|
1993
|
+
var aa = a[0],
|
1994
|
+
ab = a[1],
|
1995
|
+
ac = a[2],
|
1996
|
+
ad = a[3],
|
1997
|
+
atx = a[4],
|
1998
|
+
aty = a[5],
|
1999
|
+
st = Math.sin(rad),
|
2000
|
+
ct = Math.cos(rad);
|
2001
|
+
|
2002
|
+
out[0] = aa*ct + ab*st;
|
2003
|
+
out[1] = -aa*st + ab*ct;
|
2004
|
+
out[2] = ac*ct + ad*st;
|
2005
|
+
out[3] = -ac*st + ct*ad;
|
2006
|
+
out[4] = ct*atx + st*aty;
|
2007
|
+
out[5] = ct*aty - st*atx;
|
2008
|
+
return out;
|
2009
|
+
};
|
2010
|
+
|
2011
|
+
/**
|
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
|
+
**/
|
2019
|
+
mat2d.scale = function(out, a, v) {
|
2020
|
+
var vx = v[0], vy = v[1];
|
2021
|
+
out[0] = a[0] * vx;
|
2022
|
+
out[1] = a[1] * vy;
|
2023
|
+
out[2] = a[2] * vx;
|
2024
|
+
out[3] = a[3] * vy;
|
2025
|
+
out[4] = a[4] * vx;
|
2026
|
+
out[5] = a[5] * vy;
|
2027
|
+
return out;
|
2028
|
+
};
|
2029
|
+
|
2030
|
+
/**
|
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
|
+
**/
|
2038
|
+
mat2d.translate = function(out, a, v) {
|
2039
|
+
out[0] = a[0];
|
2040
|
+
out[1] = a[1];
|
2041
|
+
out[2] = a[2];
|
2042
|
+
out[3] = a[3];
|
2043
|
+
out[4] = a[4] + v[0];
|
2044
|
+
out[5] = a[5] + v[1];
|
2045
|
+
return out;
|
2046
|
+
};
|
2047
|
+
|
2048
|
+
/**
|
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
|
+
*/
|
2054
|
+
mat2d.str = function (a) {
|
2055
|
+
return 'mat2d(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
|
2056
|
+
a[3] + ', ' + a[4] + ', ' + a[5] + ')';
|
2057
|
+
};
|
2058
|
+
|
2059
|
+
if(typeof(exports) !== 'undefined') {
|
2060
|
+
exports.mat2d = mat2d;
|
2061
|
+
}
|
2062
|
+
;
|
2063
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
2064
|
+
|
2065
|
+
Redistribution and use in source and binary forms, with or without modification,
|
2066
|
+
are permitted provided that the following conditions are met:
|
2067
|
+
|
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.
|
2073
|
+
|
2074
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
2075
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
2076
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2077
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
2078
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2079
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2080
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
2081
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2082
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2083
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
2084
|
+
|
2085
|
+
/**
|
2086
|
+
* @class 3x3 Matrix
|
2087
|
+
* @name mat3
|
2088
|
+
*/
|
1591
2089
|
|
1592
2090
|
var mat3 = {};
|
1593
2091
|
|
@@ -1597,27 +2095,33 @@ var mat3Identity = new Float32Array([
|
|
1597
2095
|
0, 0, 1
|
1598
2096
|
]);
|
1599
2097
|
|
1600
|
-
if(!GLMAT_EPSILON) {
|
1601
|
-
var GLMAT_EPSILON = 0.000001;
|
1602
|
-
}
|
1603
|
-
|
1604
2098
|
/**
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
2099
|
+
* Creates a new identity mat3
|
2100
|
+
*
|
2101
|
+
* @returns {mat3} a new 3x3 matrix
|
2102
|
+
*/
|
1609
2103
|
mat3.create = function() {
|
1610
|
-
|
2104
|
+
var out = new GLMAT_ARRAY_TYPE(9);
|
2105
|
+
out[0] = 1;
|
2106
|
+
out[1] = 0;
|
2107
|
+
out[2] = 0;
|
2108
|
+
out[3] = 0;
|
2109
|
+
out[4] = 1;
|
2110
|
+
out[5] = 0;
|
2111
|
+
out[6] = 0;
|
2112
|
+
out[7] = 0;
|
2113
|
+
out[8] = 1;
|
2114
|
+
return out;
|
1611
2115
|
};
|
1612
2116
|
|
1613
2117
|
/**
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
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
|
+
*/
|
1619
2123
|
mat3.clone = function(a) {
|
1620
|
-
var out = new
|
2124
|
+
var out = new GLMAT_ARRAY_TYPE(9);
|
1621
2125
|
out[0] = a[0];
|
1622
2126
|
out[1] = a[1];
|
1623
2127
|
out[2] = a[2];
|
@@ -1631,12 +2135,12 @@ mat3.clone = function(a) {
|
|
1631
2135
|
};
|
1632
2136
|
|
1633
2137
|
/**
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
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
|
+
*/
|
1640
2144
|
mat3.copy = function(out, a) {
|
1641
2145
|
out[0] = a[0];
|
1642
2146
|
out[1] = a[1];
|
@@ -1651,11 +2155,11 @@ mat3.copy = function(out, a) {
|
|
1651
2155
|
};
|
1652
2156
|
|
1653
2157
|
/**
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
2158
|
+
* Set a mat3 to the identity matrix
|
2159
|
+
*
|
2160
|
+
* @param {mat3} out the receiving matrix
|
2161
|
+
* @returns {mat3} out
|
2162
|
+
*/
|
1659
2163
|
mat3.identity = function(out) {
|
1660
2164
|
out[0] = 1;
|
1661
2165
|
out[1] = 0;
|
@@ -1670,12 +2174,12 @@ mat3.identity = function(out) {
|
|
1670
2174
|
};
|
1671
2175
|
|
1672
2176
|
/**
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
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
|
+
*/
|
1679
2183
|
mat3.transpose = function(out, a) {
|
1680
2184
|
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
1681
2185
|
if (out === a) {
|
@@ -1702,12 +2206,12 @@ mat3.transpose = function(out, a) {
|
|
1702
2206
|
};
|
1703
2207
|
|
1704
2208
|
/**
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
2209
|
+
* Inverts a mat3
|
2210
|
+
*
|
2211
|
+
* @param {mat3} out the receiving matrix
|
2212
|
+
* @param {mat3} a the source matrix
|
2213
|
+
* @returns {mat3} out
|
2214
|
+
*/
|
1711
2215
|
mat3.invert = function(out, a) {
|
1712
2216
|
var a00 = a[0], a01 = a[1], a02 = a[2],
|
1713
2217
|
a10 = a[3], a11 = a[4], a12 = a[5],
|
@@ -1720,8 +2224,8 @@ mat3.invert = function(out, a) {
|
|
1720
2224
|
// Calculate the determinant
|
1721
2225
|
det = a00 * b01 + a01 * b11 + a02 * b21;
|
1722
2226
|
|
1723
|
-
if (!det) {
|
1724
|
-
return null;
|
2227
|
+
if (!det) {
|
2228
|
+
return null;
|
1725
2229
|
}
|
1726
2230
|
det = 1.0 / det;
|
1727
2231
|
|
@@ -1738,12 +2242,12 @@ mat3.invert = function(out, a) {
|
|
1738
2242
|
};
|
1739
2243
|
|
1740
2244
|
/**
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
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
|
+
*/
|
1747
2251
|
mat3.adjoint = function(out, a) {
|
1748
2252
|
var a00 = a[0], a01 = a[1], a02 = a[2],
|
1749
2253
|
a10 = a[3], a11 = a[4], a12 = a[5],
|
@@ -1762,11 +2266,11 @@ mat3.adjoint = function(out, a) {
|
|
1762
2266
|
};
|
1763
2267
|
|
1764
2268
|
/**
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
2269
|
+
* Calculates the determinant of a mat3
|
2270
|
+
*
|
2271
|
+
* @param {mat3} a the source matrix
|
2272
|
+
* @returns {Number} determinant of a
|
2273
|
+
*/
|
1770
2274
|
mat3.determinant = function (a) {
|
1771
2275
|
var a00 = a[0], a01 = a[1], a02 = a[2],
|
1772
2276
|
a10 = a[3], a11 = a[4], a12 = a[5],
|
@@ -1776,14 +2280,14 @@ mat3.determinant = function (a) {
|
|
1776
2280
|
};
|
1777
2281
|
|
1778
2282
|
/**
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
mat3.
|
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
|
+
*/
|
2290
|
+
mat3.multiply = function (out, a, b) {
|
1787
2291
|
var a00 = a[0], a01 = a[1], a02 = a[2],
|
1788
2292
|
a10 = a[3], a11 = a[4], a12 = a[5],
|
1789
2293
|
a20 = a[6], a21 = a[7], a22 = a[8],
|
@@ -1807,14 +2311,165 @@ mat3.mul = mat3.multiply = function (out, a, b) {
|
|
1807
2311
|
};
|
1808
2312
|
|
1809
2313
|
/**
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
2314
|
+
* Alias for {@link mat3.multiply}
|
2315
|
+
* @function
|
2316
|
+
*/
|
2317
|
+
mat3.mul = mat3.multiply;
|
2318
|
+
|
2319
|
+
/**
|
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
|
+
*/
|
2327
|
+
mat3.translate = function(out, a, v) {
|
2328
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2329
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2330
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2331
|
+
x = v[0], y = v[1];
|
2332
|
+
|
2333
|
+
out[0] = a00;
|
2334
|
+
out[1] = a01;
|
2335
|
+
out[2] = a02;
|
2336
|
+
|
2337
|
+
out[3] = a10;
|
2338
|
+
out[4] = a11;
|
2339
|
+
out[5] = a12;
|
2340
|
+
|
2341
|
+
out[6] = x * a00 + y * a10 + a20;
|
2342
|
+
out[7] = x * a01 + y * a11 + a21;
|
2343
|
+
out[8] = x * a02 + y * a12 + a22;
|
2344
|
+
return out;
|
2345
|
+
};
|
2346
|
+
|
2347
|
+
/**
|
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
|
+
*/
|
2355
|
+
mat3.rotate = function (out, a, rad) {
|
2356
|
+
var a00 = a[0], a01 = a[1], a02 = a[2],
|
2357
|
+
a10 = a[3], a11 = a[4], a12 = a[5],
|
2358
|
+
a20 = a[6], a21 = a[7], a22 = a[8],
|
2359
|
+
|
2360
|
+
s = Math.sin(rad),
|
2361
|
+
c = Math.cos(rad);
|
2362
|
+
|
2363
|
+
out[0] = c * a00 + s * a10;
|
2364
|
+
out[1] = c * a01 + s * a11;
|
2365
|
+
out[2] = c * a02 + s * a12;
|
2366
|
+
|
2367
|
+
out[3] = c * a10 - s * a00;
|
2368
|
+
out[4] = c * a11 - s * a01;
|
2369
|
+
out[5] = c * a12 - s * a02;
|
2370
|
+
|
2371
|
+
out[6] = a20;
|
2372
|
+
out[7] = a21;
|
2373
|
+
out[8] = a22;
|
2374
|
+
return out;
|
2375
|
+
};
|
2376
|
+
|
2377
|
+
/**
|
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
|
+
**/
|
2385
|
+
mat3.scale = function(out, a, v) {
|
2386
|
+
var x = v[0], y = v[2];
|
2387
|
+
|
2388
|
+
out[0] = x * a[0];
|
2389
|
+
out[1] = x * a[1];
|
2390
|
+
out[2] = x * a[2];
|
2391
|
+
|
2392
|
+
out[3] = y * a[3];
|
2393
|
+
out[4] = y * a[4];
|
2394
|
+
out[5] = y * a[5];
|
2395
|
+
|
2396
|
+
out[6] = a[6];
|
2397
|
+
out[7] = a[7];
|
2398
|
+
out[8] = a[8];
|
2399
|
+
return out;
|
2400
|
+
};
|
2401
|
+
|
2402
|
+
/**
|
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
|
+
**/
|
2410
|
+
mat3.fromMat2d = function(out, a) {
|
2411
|
+
out[0] = a[0];
|
2412
|
+
out[1] = a[1];
|
2413
|
+
out[2] = 0;
|
2414
|
+
|
2415
|
+
out[3] = a[2];
|
2416
|
+
out[4] = a[3];
|
2417
|
+
out[5] = 0;
|
2418
|
+
|
2419
|
+
out[6] = a[4];
|
2420
|
+
out[7] = a[5];
|
2421
|
+
out[8] = 1;
|
2422
|
+
return out;
|
2423
|
+
};
|
2424
|
+
|
2425
|
+
/**
|
2426
|
+
* Calculates a 3x3 matrix from the given quaternion
|
2427
|
+
*
|
2428
|
+
* @param {mat3} out mat3 receiving operation result
|
2429
|
+
* @param {quat} q Quaternion to create matrix from
|
2430
|
+
*
|
2431
|
+
* @returns {mat3} out
|
2432
|
+
*/
|
2433
|
+
mat3.fromQuat = function (out, q) {
|
2434
|
+
var x = q[0], y = q[1], z = q[2], w = q[3],
|
2435
|
+
x2 = x + x,
|
2436
|
+
y2 = y + y,
|
2437
|
+
z2 = z + z,
|
2438
|
+
|
2439
|
+
xx = x * x2,
|
2440
|
+
xy = x * y2,
|
2441
|
+
xz = x * z2,
|
2442
|
+
yy = y * y2,
|
2443
|
+
yz = y * z2,
|
2444
|
+
zz = z * z2,
|
2445
|
+
wx = w * x2,
|
2446
|
+
wy = w * y2,
|
2447
|
+
wz = w * z2;
|
2448
|
+
|
2449
|
+
out[0] = 1 - (yy + zz);
|
2450
|
+
out[1] = xy + wz;
|
2451
|
+
out[2] = xz - wy;
|
2452
|
+
|
2453
|
+
out[3] = xy - wz;
|
2454
|
+
out[4] = 1 - (xx + zz);
|
2455
|
+
out[5] = yz + wx;
|
2456
|
+
|
2457
|
+
out[6] = xz + wy;
|
2458
|
+
out[7] = yz - wx;
|
2459
|
+
out[8] = 1 - (xx + yy);
|
2460
|
+
|
2461
|
+
return out;
|
2462
|
+
};
|
2463
|
+
|
2464
|
+
/**
|
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
|
+
*/
|
1815
2470
|
mat3.str = function (a) {
|
1816
|
-
return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
|
1817
|
-
a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
|
2471
|
+
return 'mat3(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' +
|
2472
|
+
a[3] + ', ' + a[4] + ', ' + a[5] + ', ' +
|
1818
2473
|
a[6] + ', ' + a[7] + ', ' + a[8] + ')';
|
1819
2474
|
};
|
1820
2475
|
|
@@ -1822,20 +2477,20 @@ if(typeof(exports) !== 'undefined') {
|
|
1822
2477
|
exports.mat3 = mat3;
|
1823
2478
|
}
|
1824
2479
|
;
|
1825
|
-
/* Copyright (c)
|
2480
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
1826
2481
|
|
1827
2482
|
Redistribution and use in source and binary forms, with or without modification,
|
1828
2483
|
are permitted provided that the following conditions are met:
|
1829
2484
|
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
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.
|
1835
2490
|
|
1836
2491
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
1837
2492
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
1838
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2493
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
1839
2494
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
1840
2495
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
1841
2496
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -1845,9 +2500,9 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
1845
2500
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
1846
2501
|
|
1847
2502
|
/**
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
2503
|
+
* @class 4x4 Matrix
|
2504
|
+
* @name mat4
|
2505
|
+
*/
|
1851
2506
|
|
1852
2507
|
var mat4 = {};
|
1853
2508
|
|
@@ -1858,27 +2513,40 @@ var mat4Identity = new Float32Array([
|
|
1858
2513
|
0, 0, 0, 1
|
1859
2514
|
]);
|
1860
2515
|
|
1861
|
-
if(!GLMAT_EPSILON) {
|
1862
|
-
var GLMAT_EPSILON = 0.000001;
|
1863
|
-
}
|
1864
|
-
|
1865
2516
|
/**
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
2517
|
+
* Creates a new identity mat4
|
2518
|
+
*
|
2519
|
+
* @returns {mat4} a new 4x4 matrix
|
2520
|
+
*/
|
1870
2521
|
mat4.create = function() {
|
1871
|
-
|
2522
|
+
var out = new GLMAT_ARRAY_TYPE(16);
|
2523
|
+
out[0] = 1;
|
2524
|
+
out[1] = 0;
|
2525
|
+
out[2] = 0;
|
2526
|
+
out[3] = 0;
|
2527
|
+
out[4] = 0;
|
2528
|
+
out[5] = 1;
|
2529
|
+
out[6] = 0;
|
2530
|
+
out[7] = 0;
|
2531
|
+
out[8] = 0;
|
2532
|
+
out[9] = 0;
|
2533
|
+
out[10] = 1;
|
2534
|
+
out[11] = 0;
|
2535
|
+
out[12] = 0;
|
2536
|
+
out[13] = 0;
|
2537
|
+
out[14] = 0;
|
2538
|
+
out[15] = 1;
|
2539
|
+
return out;
|
1872
2540
|
};
|
1873
2541
|
|
1874
2542
|
/**
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
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
|
+
*/
|
1880
2548
|
mat4.clone = function(a) {
|
1881
|
-
var out = new
|
2549
|
+
var out = new GLMAT_ARRAY_TYPE(16);
|
1882
2550
|
out[0] = a[0];
|
1883
2551
|
out[1] = a[1];
|
1884
2552
|
out[2] = a[2];
|
@@ -1899,12 +2567,12 @@ mat4.clone = function(a) {
|
|
1899
2567
|
};
|
1900
2568
|
|
1901
2569
|
/**
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
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
|
+
*/
|
1908
2576
|
mat4.copy = function(out, a) {
|
1909
2577
|
out[0] = a[0];
|
1910
2578
|
out[1] = a[1];
|
@@ -1926,11 +2594,11 @@ mat4.copy = function(out, a) {
|
|
1926
2594
|
};
|
1927
2595
|
|
1928
2596
|
/**
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
2597
|
+
* Set a mat4 to the identity matrix
|
2598
|
+
*
|
2599
|
+
* @param {mat4} out the receiving matrix
|
2600
|
+
* @returns {mat4} out
|
2601
|
+
*/
|
1934
2602
|
mat4.identity = function(out) {
|
1935
2603
|
out[0] = 1;
|
1936
2604
|
out[1] = 0;
|
@@ -1952,12 +2620,12 @@ mat4.identity = function(out) {
|
|
1952
2620
|
};
|
1953
2621
|
|
1954
2622
|
/**
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
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
|
+
*/
|
1961
2629
|
mat4.transpose = function(out, a) {
|
1962
2630
|
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
1963
2631
|
if (out === a) {
|
@@ -2000,12 +2668,12 @@ mat4.transpose = function(out, a) {
|
|
2000
2668
|
};
|
2001
2669
|
|
2002
2670
|
/**
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2671
|
+
* Inverts a mat4
|
2672
|
+
*
|
2673
|
+
* @param {mat4} out the receiving matrix
|
2674
|
+
* @param {mat4} a the source matrix
|
2675
|
+
* @returns {mat4} out
|
2676
|
+
*/
|
2009
2677
|
mat4.invert = function(out, a) {
|
2010
2678
|
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2011
2679
|
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
@@ -2028,8 +2696,8 @@ mat4.invert = function(out, a) {
|
|
2028
2696
|
// Calculate the determinant
|
2029
2697
|
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
2030
2698
|
|
2031
|
-
if (!det) {
|
2032
|
-
return null;
|
2699
|
+
if (!det) {
|
2700
|
+
return null;
|
2033
2701
|
}
|
2034
2702
|
det = 1.0 / det;
|
2035
2703
|
|
@@ -2054,43 +2722,43 @@ mat4.invert = function(out, a) {
|
|
2054
2722
|
};
|
2055
2723
|
|
2056
2724
|
/**
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
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
|
+
*/
|
2063
2731
|
mat4.adjoint = function(out, a) {
|
2064
2732
|
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2065
2733
|
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2066
2734
|
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2067
2735
|
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
2068
2736
|
|
2069
|
-
out[0]
|
2070
|
-
out[1]
|
2071
|
-
out[2]
|
2072
|
-
out[3]
|
2073
|
-
out[4]
|
2074
|
-
out[5]
|
2075
|
-
out[6]
|
2076
|
-
out[7]
|
2077
|
-
out[8]
|
2078
|
-
out[9]
|
2079
|
-
out[10] =
|
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));
|
2080
2748
|
out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
|
2081
2749
|
out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
|
2082
|
-
out[13] =
|
2750
|
+
out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
|
2083
2751
|
out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
|
2084
|
-
out[15] =
|
2752
|
+
out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
|
2085
2753
|
return out;
|
2086
2754
|
};
|
2087
2755
|
|
2088
2756
|
/**
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2757
|
+
* Calculates the determinant of a mat4
|
2758
|
+
*
|
2759
|
+
* @param {mat4} a the source matrix
|
2760
|
+
* @returns {Number} determinant of a
|
2761
|
+
*/
|
2094
2762
|
mat4.determinant = function (a) {
|
2095
2763
|
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2096
2764
|
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
@@ -2115,21 +2783,21 @@ mat4.determinant = function (a) {
|
|
2115
2783
|
};
|
2116
2784
|
|
2117
2785
|
/**
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
mat4.
|
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
|
+
*/
|
2793
|
+
mat4.multiply = function (out, a, b) {
|
2126
2794
|
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
|
2127
2795
|
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
|
2128
2796
|
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
|
2129
2797
|
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
|
2130
2798
|
|
2131
2799
|
// Cache only the current line of the second matrix
|
2132
|
-
var b0
|
2800
|
+
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
|
2133
2801
|
out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
|
2134
2802
|
out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
|
2135
2803
|
out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
|
@@ -2156,13 +2824,19 @@ mat4.mul = mat4.multiply = function (out, a, b) {
|
|
2156
2824
|
};
|
2157
2825
|
|
2158
2826
|
/**
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2827
|
+
* Alias for {@link mat4.multiply}
|
2828
|
+
* @function
|
2829
|
+
*/
|
2830
|
+
mat4.mul = mat4.multiply;
|
2831
|
+
|
2832
|
+
/**
|
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
|
+
*/
|
2166
2840
|
mat4.translate = function (out, a, v) {
|
2167
2841
|
var x = v[0], y = v[1], z = v[2],
|
2168
2842
|
a00, a01, a02, a03,
|
@@ -2193,13 +2867,13 @@ mat4.translate = function (out, a, v) {
|
|
2193
2867
|
};
|
2194
2868
|
|
2195
2869
|
/**
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
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
|
+
**/
|
2203
2877
|
mat4.scale = function(out, a, v) {
|
2204
2878
|
var x = v[0], y = v[1], z = v[2];
|
2205
2879
|
|
@@ -2223,14 +2897,14 @@ mat4.scale = function(out, a, v) {
|
|
2223
2897
|
};
|
2224
2898
|
|
2225
2899
|
/**
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
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
|
+
*/
|
2234
2908
|
mat4.rotate = function (out, a, rad, axis) {
|
2235
2909
|
var x = axis[0], y = axis[1], z = axis[2],
|
2236
2910
|
len = Math.sqrt(x * x + y * y + z * z),
|
@@ -2286,13 +2960,13 @@ mat4.rotate = function (out, a, rad, axis) {
|
|
2286
2960
|
};
|
2287
2961
|
|
2288
2962
|
/**
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
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
|
+
*/
|
2296
2970
|
mat4.rotateX = function (out, a, rad) {
|
2297
2971
|
var s = Math.sin(rad),
|
2298
2972
|
c = Math.cos(rad),
|
@@ -2306,10 +2980,10 @@ mat4.rotateX = function (out, a, rad) {
|
|
2306
2980
|
a23 = a[11];
|
2307
2981
|
|
2308
2982
|
if (a !== out) { // If the source and destination differ, copy the unchanged rows
|
2309
|
-
out[0]
|
2310
|
-
out[1]
|
2311
|
-
out[2]
|
2312
|
-
out[3]
|
2983
|
+
out[0] = a[0];
|
2984
|
+
out[1] = a[1];
|
2985
|
+
out[2] = a[2];
|
2986
|
+
out[3] = a[3];
|
2313
2987
|
out[12] = a[12];
|
2314
2988
|
out[13] = a[13];
|
2315
2989
|
out[14] = a[14];
|
@@ -2329,13 +3003,13 @@ mat4.rotateX = function (out, a, rad) {
|
|
2329
3003
|
};
|
2330
3004
|
|
2331
3005
|
/**
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
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
|
+
*/
|
2339
3013
|
mat4.rotateY = function (out, a, rad) {
|
2340
3014
|
var s = Math.sin(rad),
|
2341
3015
|
c = Math.cos(rad),
|
@@ -2349,10 +3023,10 @@ mat4.rotateY = function (out, a, rad) {
|
|
2349
3023
|
a23 = a[11];
|
2350
3024
|
|
2351
3025
|
if (a !== out) { // If the source and destination differ, copy the unchanged rows
|
2352
|
-
out[4]
|
2353
|
-
out[5]
|
2354
|
-
out[6]
|
2355
|
-
out[7]
|
3026
|
+
out[4] = a[4];
|
3027
|
+
out[5] = a[5];
|
3028
|
+
out[6] = a[6];
|
3029
|
+
out[7] = a[7];
|
2356
3030
|
out[12] = a[12];
|
2357
3031
|
out[13] = a[13];
|
2358
3032
|
out[14] = a[14];
|
@@ -2372,13 +3046,13 @@ mat4.rotateY = function (out, a, rad) {
|
|
2372
3046
|
};
|
2373
3047
|
|
2374
3048
|
/**
|
2375
|
-
|
2376
|
-
|
2377
|
-
|
2378
|
-
|
2379
|
-
|
2380
|
-
|
2381
|
-
|
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
|
+
*/
|
2382
3056
|
mat4.rotateZ = function (out, a, rad) {
|
2383
3057
|
var s = Math.sin(rad),
|
2384
3058
|
c = Math.cos(rad),
|
@@ -2392,8 +3066,8 @@ mat4.rotateZ = function (out, a, rad) {
|
|
2392
3066
|
a13 = a[7];
|
2393
3067
|
|
2394
3068
|
if (a !== out) { // If the source and destination differ, copy the unchanged last row
|
2395
|
-
out[8]
|
2396
|
-
out[9]
|
3069
|
+
out[8] = a[8];
|
3070
|
+
out[9] = a[9];
|
2397
3071
|
out[10] = a[10];
|
2398
3072
|
out[11] = a[11];
|
2399
3073
|
out[12] = a[12];
|
@@ -2415,20 +3089,20 @@ mat4.rotateZ = function (out, a, rad) {
|
|
2415
3089
|
};
|
2416
3090
|
|
2417
3091
|
/**
|
2418
|
-
|
2419
|
-
|
2420
|
-
|
2421
|
-
|
2422
|
-
|
2423
|
-
|
2424
|
-
|
2425
|
-
|
2426
|
-
|
2427
|
-
|
2428
|
-
|
2429
|
-
|
2430
|
-
|
2431
|
-
|
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
|
+
*/
|
2432
3106
|
mat4.fromRotationTranslation = function (out, q, v) {
|
2433
3107
|
// Quaternion math
|
2434
3108
|
var x = q[0], y = q[1], z = q[2], w = q[3],
|
@@ -2467,17 +3141,64 @@ mat4.fromRotationTranslation = function (out, q, v) {
|
|
2467
3141
|
};
|
2468
3142
|
|
2469
3143
|
/**
|
2470
|
-
|
2471
|
-
|
2472
|
-
|
2473
|
-
|
2474
|
-
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
|
2479
|
-
|
2480
|
-
|
3144
|
+
* Calculates a 4x4 matrix from the given quaternion
|
3145
|
+
*
|
3146
|
+
* @param {mat4} out mat4 receiving operation result
|
3147
|
+
* @param {quat} q Quaternion to create matrix from
|
3148
|
+
*
|
3149
|
+
* @returns {mat4} out
|
3150
|
+
*/
|
3151
|
+
mat4.fromQuat = function (out, q) {
|
3152
|
+
var x = q[0], y = q[1], z = q[2], w = q[3],
|
3153
|
+
x2 = x + x,
|
3154
|
+
y2 = y + y,
|
3155
|
+
z2 = z + z,
|
3156
|
+
|
3157
|
+
xx = x * x2,
|
3158
|
+
xy = x * y2,
|
3159
|
+
xz = x * z2,
|
3160
|
+
yy = y * y2,
|
3161
|
+
yz = y * z2,
|
3162
|
+
zz = z * z2,
|
3163
|
+
wx = w * x2,
|
3164
|
+
wy = w * y2,
|
3165
|
+
wz = w * z2;
|
3166
|
+
|
3167
|
+
out[0] = 1 - (yy + zz);
|
3168
|
+
out[1] = xy + wz;
|
3169
|
+
out[2] = xz - wy;
|
3170
|
+
out[3] = 0;
|
3171
|
+
|
3172
|
+
out[4] = xy - wz;
|
3173
|
+
out[5] = 1 - (xx + zz);
|
3174
|
+
out[6] = yz + wx;
|
3175
|
+
out[7] = 0;
|
3176
|
+
|
3177
|
+
out[8] = xz + wy;
|
3178
|
+
out[9] = yz - wx;
|
3179
|
+
out[10] = 1 - (xx + yy);
|
3180
|
+
out[11] = 0;
|
3181
|
+
|
3182
|
+
out[12] = 0;
|
3183
|
+
out[13] = 0;
|
3184
|
+
out[14] = 0;
|
3185
|
+
out[15] = 1;
|
3186
|
+
|
3187
|
+
return out;
|
3188
|
+
};
|
3189
|
+
|
3190
|
+
/**
|
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
|
+
*/
|
2481
3202
|
mat4.frustum = function (out, left, right, bottom, top, near, far) {
|
2482
3203
|
var rl = 1 / (right - left),
|
2483
3204
|
tb = 1 / (top - bottom),
|
@@ -2502,15 +3223,15 @@ mat4.frustum = function (out, left, right, bottom, top, near, far) {
|
|
2502
3223
|
};
|
2503
3224
|
|
2504
3225
|
/**
|
2505
|
-
|
2506
|
-
|
2507
|
-
|
2508
|
-
|
2509
|
-
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
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
|
+
*/
|
2514
3235
|
mat4.perspective = function (out, fovy, aspect, near, far) {
|
2515
3236
|
var f = 1.0 / Math.tan(fovy / 2),
|
2516
3237
|
nf = 1 / (near - far);
|
@@ -2534,17 +3255,17 @@ mat4.perspective = function (out, fovy, aspect, near, far) {
|
|
2534
3255
|
};
|
2535
3256
|
|
2536
3257
|
/**
|
2537
|
-
|
2538
|
-
|
2539
|
-
|
2540
|
-
|
2541
|
-
|
2542
|
-
|
2543
|
-
|
2544
|
-
|
2545
|
-
|
2546
|
-
|
2547
|
-
|
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
|
+
*/
|
2548
3269
|
mat4.ortho = function (out, left, right, bottom, top, near, far) {
|
2549
3270
|
var lr = 1 / (left - right),
|
2550
3271
|
bt = 1 / (bottom - top),
|
@@ -2569,14 +3290,14 @@ mat4.ortho = function (out, left, right, bottom, top, near, far) {
|
|
2569
3290
|
};
|
2570
3291
|
|
2571
3292
|
/**
|
2572
|
-
|
2573
|
-
|
2574
|
-
|
2575
|
-
|
2576
|
-
|
2577
|
-
|
2578
|
-
|
2579
|
-
|
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
|
+
*/
|
2580
3301
|
mat4.lookAt = function (out, eye, center, up) {
|
2581
3302
|
var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
|
2582
3303
|
eyex = eye[0],
|
@@ -2656,15 +3377,15 @@ mat4.lookAt = function (out, eye, center, up) {
|
|
2656
3377
|
};
|
2657
3378
|
|
2658
3379
|
/**
|
2659
|
-
|
2660
|
-
|
2661
|
-
|
2662
|
-
|
2663
|
-
|
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
|
+
*/
|
2664
3385
|
mat4.str = function (a) {
|
2665
3386
|
return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +
|
2666
3387
|
a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +
|
2667
|
-
a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
|
3388
|
+
a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
|
2668
3389
|
a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';
|
2669
3390
|
};
|
2670
3391
|
|
@@ -2672,20 +3393,20 @@ if(typeof(exports) !== 'undefined') {
|
|
2672
3393
|
exports.mat4 = mat4;
|
2673
3394
|
}
|
2674
3395
|
;
|
2675
|
-
/* Copyright (c)
|
3396
|
+
/* Copyright (c) 2013, Brandon Jones, Colin MacKenzie IV. All rights reserved.
|
2676
3397
|
|
2677
3398
|
Redistribution and use in source and binary forms, with or without modification,
|
2678
3399
|
are permitted provided that the following conditions are met:
|
2679
3400
|
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
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.
|
2685
3406
|
|
2686
3407
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
2687
3408
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
2688
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
3409
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
2689
3410
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
2690
3411
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
2691
3412
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
@@ -2695,73 +3416,78 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
2695
3416
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
|
2696
3417
|
|
2697
3418
|
/**
|
2698
|
-
|
2699
|
-
|
2700
|
-
|
3419
|
+
* @class Quaternion
|
3420
|
+
* @name quat
|
3421
|
+
*/
|
2701
3422
|
|
2702
3423
|
var quat = {};
|
2703
3424
|
|
2704
3425
|
var quatIdentity = new Float32Array([0, 0, 0, 1]);
|
2705
3426
|
|
2706
|
-
if(!GLMAT_EPSILON) {
|
2707
|
-
var GLMAT_EPSILON = 0.000001;
|
2708
|
-
}
|
2709
|
-
|
2710
3427
|
/**
|
2711
|
-
|
2712
|
-
|
2713
|
-
|
2714
|
-
|
3428
|
+
* Creates a new identity quat
|
3429
|
+
*
|
3430
|
+
* @returns {quat} a new quaternion
|
3431
|
+
*/
|
2715
3432
|
quat.create = function() {
|
2716
|
-
|
3433
|
+
var out = new GLMAT_ARRAY_TYPE(4);
|
3434
|
+
out[0] = 0;
|
3435
|
+
out[1] = 0;
|
3436
|
+
out[2] = 0;
|
3437
|
+
out[3] = 1;
|
3438
|
+
return out;
|
2717
3439
|
};
|
2718
3440
|
|
2719
3441
|
/**
|
2720
|
-
|
2721
|
-
|
2722
|
-
|
2723
|
-
|
2724
|
-
|
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
|
+
*/
|
2725
3448
|
quat.clone = vec4.clone;
|
2726
3449
|
|
2727
3450
|
/**
|
2728
|
-
|
2729
|
-
|
2730
|
-
|
2731
|
-
|
2732
|
-
|
2733
|
-
|
2734
|
-
|
2735
|
-
|
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
|
+
*/
|
2736
3460
|
quat.fromValues = vec4.fromValues;
|
2737
3461
|
|
2738
3462
|
/**
|
2739
|
-
|
2740
|
-
|
2741
|
-
|
2742
|
-
|
2743
|
-
|
2744
|
-
|
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
|
+
*/
|
2745
3470
|
quat.copy = vec4.copy;
|
2746
3471
|
|
2747
3472
|
/**
|
2748
|
-
|
2749
|
-
|
2750
|
-
|
2751
|
-
|
2752
|
-
|
2753
|
-
|
2754
|
-
|
2755
|
-
|
2756
|
-
|
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
|
+
*/
|
2757
3483
|
quat.set = vec4.set;
|
2758
3484
|
|
2759
3485
|
/**
|
2760
|
-
|
2761
|
-
|
2762
|
-
|
2763
|
-
|
2764
|
-
|
3486
|
+
* Set a quat to the identity quaternion
|
3487
|
+
*
|
3488
|
+
* @param {quat} out the receiving quaternion
|
3489
|
+
* @returns {quat} out
|
3490
|
+
*/
|
2765
3491
|
quat.identity = function(out) {
|
2766
3492
|
out[0] = 0;
|
2767
3493
|
out[1] = 0;
|
@@ -2771,14 +3497,14 @@ quat.identity = function(out) {
|
|
2771
3497
|
};
|
2772
3498
|
|
2773
3499
|
/**
|
2774
|
-
|
2775
|
-
|
2776
|
-
|
2777
|
-
|
2778
|
-
|
2779
|
-
|
2780
|
-
|
2781
|
-
|
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
|
+
**/
|
2782
3508
|
quat.setAxisAngle = function(out, axis, rad) {
|
2783
3509
|
rad = rad * 0.5;
|
2784
3510
|
var s = Math.sin(rad);
|
@@ -2790,24 +3516,25 @@ quat.setAxisAngle = function(out, axis, rad) {
|
|
2790
3516
|
};
|
2791
3517
|
|
2792
3518
|
/**
|
2793
|
-
|
2794
|
-
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
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
|
+
*/
|
2800
3527
|
quat.add = vec4.add;
|
2801
3528
|
|
2802
3529
|
/**
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
quat.
|
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
|
+
*/
|
3537
|
+
quat.multiply = function(out, a, b) {
|
2811
3538
|
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
2812
3539
|
bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
2813
3540
|
|
@@ -2819,25 +3546,32 @@ quat.mul = quat.multiply = function(out, a, b) {
|
|
2819
3546
|
};
|
2820
3547
|
|
2821
3548
|
/**
|
2822
|
-
|
2823
|
-
|
2824
|
-
|
2825
|
-
|
2826
|
-
|
2827
|
-
|
2828
|
-
|
3549
|
+
* Alias for {@link quat.multiply}
|
3550
|
+
* @function
|
3551
|
+
*/
|
3552
|
+
quat.mul = quat.multiply;
|
3553
|
+
|
3554
|
+
/**
|
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
|
+
*/
|
2829
3563
|
quat.scale = vec4.scale;
|
2830
3564
|
|
2831
3565
|
/**
|
2832
|
-
|
2833
|
-
|
2834
|
-
|
2835
|
-
|
2836
|
-
|
2837
|
-
|
2838
|
-
|
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
|
+
*/
|
2839
3573
|
quat.rotateX = function (out, a, rad) {
|
2840
|
-
rad *= 0.5;
|
3574
|
+
rad *= 0.5;
|
2841
3575
|
|
2842
3576
|
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
2843
3577
|
bx = Math.sin(rad), bw = Math.cos(rad);
|
@@ -2850,15 +3584,15 @@ quat.rotateX = function (out, a, rad) {
|
|
2850
3584
|
};
|
2851
3585
|
|
2852
3586
|
/**
|
2853
|
-
|
2854
|
-
|
2855
|
-
|
2856
|
-
|
2857
|
-
|
2858
|
-
|
2859
|
-
|
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
|
+
*/
|
2860
3594
|
quat.rotateY = function (out, a, rad) {
|
2861
|
-
rad *= 0.5;
|
3595
|
+
rad *= 0.5;
|
2862
3596
|
|
2863
3597
|
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
2864
3598
|
by = Math.sin(rad), bw = Math.cos(rad);
|
@@ -2871,15 +3605,15 @@ quat.rotateY = function (out, a, rad) {
|
|
2871
3605
|
};
|
2872
3606
|
|
2873
3607
|
/**
|
2874
|
-
|
2875
|
-
|
2876
|
-
|
2877
|
-
|
2878
|
-
|
2879
|
-
|
2880
|
-
|
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
|
+
*/
|
2881
3615
|
quat.rotateZ = function (out, a, rad) {
|
2882
|
-
rad *= 0.5;
|
3616
|
+
rad *= 0.5;
|
2883
3617
|
|
2884
3618
|
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
2885
3619
|
bz = Math.sin(rad), bw = Math.cos(rad);
|
@@ -2892,14 +3626,14 @@ quat.rotateZ = function (out, a, rad) {
|
|
2892
3626
|
};
|
2893
3627
|
|
2894
3628
|
/**
|
2895
|
-
|
2896
|
-
|
2897
|
-
|
2898
|
-
|
2899
|
-
|
2900
|
-
|
2901
|
-
|
2902
|
-
|
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
|
+
*/
|
2903
3637
|
quat.calculateW = function (out, a) {
|
2904
3638
|
var x = a[0], y = a[1], z = a[2];
|
2905
3639
|
|
@@ -2911,37 +3645,39 @@ quat.calculateW = function (out, a) {
|
|
2911
3645
|
};
|
2912
3646
|
|
2913
3647
|
/**
|
2914
|
-
|
2915
|
-
|
2916
|
-
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
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
|
+
*/
|
2920
3655
|
quat.dot = vec4.dot;
|
2921
3656
|
|
2922
3657
|
/**
|
2923
|
-
|
2924
|
-
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2930
|
-
|
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
|
+
*/
|
2931
3667
|
quat.lerp = vec4.lerp;
|
2932
3668
|
|
2933
3669
|
/**
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2937
|
-
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
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
|
+
*/
|
2942
3678
|
quat.slerp = function (out, a, b, t) {
|
2943
3679
|
var ax = a[0], ay = a[1], az = a[2], aw = a[3],
|
2944
|
-
bx = b[0], by = b[1], bz = b[2], bw =
|
3680
|
+
bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
2945
3681
|
|
2946
3682
|
var cosHalfTheta = ax * bx + ay * by + az * bz + aw * bw,
|
2947
3683
|
halfTheta,
|
@@ -2982,12 +3718,12 @@ quat.slerp = function (out, a, b, t) {
|
|
2982
3718
|
};
|
2983
3719
|
|
2984
3720
|
/**
|
2985
|
-
|
2986
|
-
|
2987
|
-
|
2988
|
-
|
2989
|
-
|
2990
|
-
|
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
|
+
*/
|
2991
3727
|
quat.invert = function(out, a) {
|
2992
3728
|
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3],
|
2993
3729
|
dot = a0*a0 + a1*a1 + a2*a2 + a3*a3,
|
@@ -3003,13 +3739,13 @@ quat.invert = function(out, a) {
|
|
3003
3739
|
};
|
3004
3740
|
|
3005
3741
|
/**
|
3006
|
-
|
3007
|
-
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
|
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
|
+
*/
|
3013
3749
|
quat.conjugate = function (out, a) {
|
3014
3750
|
out[0] = -a[0];
|
3015
3751
|
out[1] = -a[1];
|
@@ -3019,36 +3755,97 @@ quat.conjugate = function (out, a) {
|
|
3019
3755
|
};
|
3020
3756
|
|
3021
3757
|
/**
|
3022
|
-
|
3023
|
-
|
3024
|
-
|
3025
|
-
|
3026
|
-
|
3027
|
-
|
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
|
+
*/
|
3764
|
+
quat.length = vec4.length;
|
3765
|
+
|
3766
|
+
/**
|
3767
|
+
* Alias for {@link quat.length}
|
3768
|
+
* @function
|
3769
|
+
*/
|
3770
|
+
quat.len = quat.length;
|
3771
|
+
|
3772
|
+
/**
|
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
|
+
*/
|
3779
|
+
quat.squaredLength = vec4.squaredLength;
|
3028
3780
|
|
3029
3781
|
/**
|
3030
|
-
|
3031
|
-
|
3032
|
-
|
3033
|
-
|
3034
|
-
*/
|
3035
|
-
quat.sqrLen = quat.squaredLength = vec4.squaredLength;
|
3782
|
+
* Alias for {@link quat.squaredLength}
|
3783
|
+
* @function
|
3784
|
+
*/
|
3785
|
+
quat.sqrLen = quat.squaredLength;
|
3036
3786
|
|
3037
3787
|
/**
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
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
|
+
*/
|
3044
3795
|
quat.normalize = vec4.normalize;
|
3045
3796
|
|
3046
3797
|
/**
|
3047
|
-
|
3048
|
-
|
3049
|
-
|
3050
|
-
|
3051
|
-
|
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
|
+
*/
|
3805
|
+
quat.fromMat3 = (function() {
|
3806
|
+
var s_iNext = [1,2,0];
|
3807
|
+
return function(out, m) {
|
3808
|
+
// Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
|
3809
|
+
// article "Quaternion Calculus and Fast Animation".
|
3810
|
+
var fTrace = m[0] + m[4] + m[8];
|
3811
|
+
var fRoot;
|
3812
|
+
|
3813
|
+
if ( fTrace > 0.0 ) {
|
3814
|
+
// |w| > 1/2, may as well choose w > 1/2
|
3815
|
+
fRoot = Math.sqrt(fTrace + 1.0); // 2w
|
3816
|
+
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;
|
3821
|
+
} else {
|
3822
|
+
// |w| <= 1/2
|
3823
|
+
var i = 0;
|
3824
|
+
if ( m[4] > m[0] )
|
3825
|
+
i = 1;
|
3826
|
+
if ( m[8] > m[i*3+i] )
|
3827
|
+
i = 2;
|
3828
|
+
var j = s_iNext[i];
|
3829
|
+
var k = s_iNext[j];
|
3830
|
+
|
3831
|
+
fRoot = Math.sqrt(m[i*3+i]-m[j*3+j]-m[k*3+k] + 1.0);
|
3832
|
+
out[i] = 0.5 * fRoot;
|
3833
|
+
fRoot = 0.5 / fRoot;
|
3834
|
+
out[3] = (m[k*3+j] - m[j*3+k]) * fRoot;
|
3835
|
+
out[j] = (m[j*3+i] + m[i*3+j]) * fRoot;
|
3836
|
+
out[k] = (m[k*3+i] + m[i*3+k]) * fRoot;
|
3837
|
+
}
|
3838
|
+
|
3839
|
+
return out;
|
3840
|
+
};
|
3841
|
+
})();
|
3842
|
+
|
3843
|
+
/**
|
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
|
+
*/
|
3052
3849
|
quat.str = function (a) {
|
3053
3850
|
return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
|
3054
3851
|
};
|
@@ -3067,5 +3864,8 @@ if(typeof(exports) !== 'undefined') {
|
|
3067
3864
|
|
3068
3865
|
|
3069
3866
|
|
3867
|
+
|
3868
|
+
|
3869
|
+
|
3070
3870
|
})(shim.exports);
|
3071
|
-
})();
|
3871
|
+
})();
|