jax 0.0.0.5 → 0.0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +26 -1
- data/Rakefile +3 -1
- data/builtin/shaders/picking/common.ejs +2 -0
- data/builtin/shaders/picking/fragment.ejs +4 -0
- data/builtin/shaders/picking/material.js +14 -0
- data/builtin/shaders/picking/vertex.ejs +24 -0
- data/lib/jax/generators/app/templates/public/javascripts/jax.js +289 -681
- data/lib/jax/generators/app/templates/spec/javascripts/support/spec_layout.html.erb +55 -2
- data/lib/jax/generators/shader/templates/common.ejs.tt +2 -2
- data/lib/jax/packager/sprockets_template.rb +1 -4
- data/lib/jax/routes.rb +3 -0
- data/lib/jax/version.rb +1 -1
- data/spec/example_app/app/controllers/noise_controller.js +37 -5
- data/spec/example_app/app/controllers/picking_controller.js +32 -0
- data/spec/example_app/app/helpers/picking_helper.js +3 -0
- data/spec/example_app/app/models/blob.js +38 -0
- data/spec/example_app/app/resources/blobs/default.yml +2 -0
- data/spec/example_app/app/resources/materials/blob.yml +2 -2
- data/spec/example_app/app/shaders/blob/common.ejs +8 -13
- data/spec/example_app/app/shaders/blob/fragment.ejs +1 -1
- data/spec/example_app/app/shaders/blob/material.js +15 -12
- data/spec/example_app/app/shaders/blob/vertex.ejs +33 -8
- data/spec/example_app/app/views/picking/index.js +4 -0
- data/spec/example_app/config/routes.rb +1 -0
- data/spec/example_app/spec/javascripts/controllers/picking_controller_spec.js +11 -0
- data/spec/example_app/spec/javascripts/helpers/picking_helper_spec.js +12 -0
- data/spec/example_app/spec/javascripts/models/blob_spec.js +11 -0
- data/spec/example_app/spec/javascripts/support/spec_layout.html.erb +40 -2
- data/spec/javascripts/jax/model_spec.js +10 -0
- data/spec/javascripts/jax/world_spec.js +74 -1
- data/spec/javascripts/shaders/preprocessor_spec.js +35 -0
- data/src/constants.yml +1 -1
- data/src/jax.js +30 -8
- data/src/jax/anim_frame.js +6 -2
- data/src/jax/builtin/meshes/cube.js +22 -1
- data/src/jax/builtin/meshes/plane.js +27 -0
- data/src/jax/builtin/meshes/quad.js +7 -1
- data/src/jax/builtin/meshes/sphere.js +20 -1
- data/src/jax/builtin/meshes/teapot.js +10 -0
- data/src/jax/builtin/meshes/torus.js +18 -0
- data/src/jax/compatibility.js +165 -2
- data/src/jax/context.js +176 -9
- data/src/jax/core.js +6 -3
- data/src/jax/core/math.js +18 -3
- data/src/jax/core/matrix_stack.js +4 -3
- data/src/jax/core/util.js +15 -0
- data/src/jax/events.js +67 -12
- data/src/jax/geometry.js +5 -1
- data/src/jax/geometry/plane.js +59 -5
- data/src/jax/{controller.js → mvc/controller.js} +38 -0
- data/src/jax/mvc/helper.js +35 -0
- data/src/jax/mvc/model.js +301 -0
- data/src/jax/{route_set.js → mvc/route_set.js} +0 -0
- data/src/jax/{view.js → mvc/view.js} +6 -0
- data/src/jax/{view_manager.js → mvc/view_manager.js} +1 -0
- data/src/jax/noise.js +13 -0
- data/src/jax/prototype/class.js +3 -0
- data/src/jax/prototype/extensions.js +26 -8
- data/src/jax/webgl/camera.js +6 -6
- data/src/jax/webgl/core/framebuffer.js +4 -4
- data/src/jax/webgl/material.js +16 -0
- data/src/jax/webgl/mesh.js +19 -4
- data/src/jax/webgl/scene/light_manager.js +8 -0
- data/src/jax/webgl/scene/light_source.js +3 -3
- data/src/jax/webgl/shader.js +4 -2
- data/src/jax/webgl/shader_chain.js +1 -0
- data/src/jax/webgl/world.js +157 -6
- data/vendor/glmatrix/glMatrix.js +365 -408
- metadata +32 -10
- data/src/jax/helper.js +0 -8
- data/src/jax/model.js +0 -163
data/vendor/glmatrix/glMatrix.js
CHANGED
@@ -35,22 +35,22 @@ if(typeof Float32Array != 'undefined') {
|
|
35
35
|
glMatrixArrayType = Array;
|
36
36
|
}
|
37
37
|
|
38
|
-
|
39
|
-
* vec3
|
40
|
-
|
38
|
+
/**
|
39
|
+
* vec3
|
40
|
+
* 3 Dimensional Vector
|
41
|
+
**/
|
41
42
|
var vec3 = {};
|
42
43
|
|
43
|
-
|
44
|
-
* vec3.create
|
44
|
+
/**
|
45
|
+
* vec3.create([vec]) -> vec3
|
46
|
+
* - vec (vec3): optional vec3 containing values to initialize with
|
47
|
+
*
|
45
48
|
* Creates a new instance of a vec3 using the default array type
|
46
49
|
* Any javascript array containing at least 3 numeric elements can serve as a vec3
|
47
50
|
*
|
48
|
-
* Params:
|
49
|
-
* vec - Optional, vec3 containing values to initialize with
|
50
|
-
*
|
51
51
|
* Returns:
|
52
52
|
* New vec3
|
53
|
-
|
53
|
+
**/
|
54
54
|
vec3.create = function(vec) {
|
55
55
|
var dest = new glMatrixArrayType(3);
|
56
56
|
|
@@ -63,17 +63,16 @@ vec3.create = function(vec) {
|
|
63
63
|
return dest;
|
64
64
|
};
|
65
65
|
|
66
|
-
|
67
|
-
* vec3.set
|
68
|
-
*
|
66
|
+
/**
|
67
|
+
* vec3.set(vec, dest) -> vec3
|
68
|
+
* - vec (vec3) : vec3 containing values to copy
|
69
|
+
* - dest (vec3) : vec3 receiving copied values
|
69
70
|
*
|
70
|
-
*
|
71
|
-
* vec - vec3 containing values to copy
|
72
|
-
* dest - vec3 receiving copied values
|
71
|
+
* Copies the values of one vec3 to another
|
73
72
|
*
|
74
73
|
* Returns:
|
75
74
|
* dest
|
76
|
-
|
75
|
+
**/
|
77
76
|
vec3.set = function(vec, dest) {
|
78
77
|
dest[0] = vec[0];
|
79
78
|
dest[1] = vec[1];
|
@@ -82,18 +81,17 @@ vec3.set = function(vec, dest) {
|
|
82
81
|
return dest;
|
83
82
|
};
|
84
83
|
|
85
|
-
|
86
|
-
* vec3.add
|
87
|
-
*
|
84
|
+
/**
|
85
|
+
* vec3.add(vec, vec2[, dest]) -> vec3
|
86
|
+
* - vec (vec3) : first operand
|
87
|
+
* - vec2 (vec3) : second operand
|
88
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
88
89
|
*
|
89
|
-
*
|
90
|
-
* vec - vec3, first operand
|
91
|
-
* vec2 - vec3, second operand
|
92
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
90
|
+
* Performs a vector addition
|
93
91
|
*
|
94
92
|
* Returns:
|
95
93
|
* dest if specified, vec otherwise
|
96
|
-
|
94
|
+
**/
|
97
95
|
vec3.add = function(vec, vec2, dest) {
|
98
96
|
if(!dest || vec == dest) {
|
99
97
|
vec[0] += vec2[0];
|
@@ -108,18 +106,17 @@ vec3.add = function(vec, vec2, dest) {
|
|
108
106
|
return dest;
|
109
107
|
};
|
110
108
|
|
111
|
-
|
112
|
-
* vec3.subtract
|
113
|
-
*
|
109
|
+
/**
|
110
|
+
* vec3.subtract(vec, vec2[, dest]) -> vec3
|
111
|
+
* - vec (vec3) : first operand
|
112
|
+
* - vec2 (vec3) : second operand
|
113
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
114
114
|
*
|
115
|
-
*
|
116
|
-
* vec - vec3, first operand
|
117
|
-
* vec2 - vec3, second operand
|
118
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
115
|
+
* Performs a vector subtraction
|
119
116
|
*
|
120
117
|
* Returns:
|
121
118
|
* dest if specified, vec otherwise
|
122
|
-
|
119
|
+
**/
|
123
120
|
vec3.subtract = function(vec, vec2, dest) {
|
124
121
|
if(!dest || vec == dest) {
|
125
122
|
vec[0] -= vec2[0];
|
@@ -134,17 +131,16 @@ vec3.subtract = function(vec, vec2, dest) {
|
|
134
131
|
return dest;
|
135
132
|
};
|
136
133
|
|
137
|
-
|
138
|
-
* vec3.negate
|
139
|
-
*
|
134
|
+
/**
|
135
|
+
* vec3.negate(vec[, dest]) -> vec3
|
136
|
+
* - vec (vec3) : vec3 to negate
|
137
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
140
138
|
*
|
141
|
-
*
|
142
|
-
* vec - vec3 to negate
|
143
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
139
|
+
* Negates the components of a vec3
|
144
140
|
*
|
145
141
|
* Returns:
|
146
142
|
* dest if specified, vec otherwise
|
147
|
-
|
143
|
+
**/
|
148
144
|
vec3.negate = function(vec, dest) {
|
149
145
|
if(!dest) { dest = vec; }
|
150
146
|
|
@@ -154,18 +150,17 @@ vec3.negate = function(vec, dest) {
|
|
154
150
|
return dest;
|
155
151
|
};
|
156
152
|
|
157
|
-
|
158
|
-
* vec3.scale
|
159
|
-
*
|
153
|
+
/**
|
154
|
+
* vec3.scale(vec, val[, dest]) -> vec3
|
155
|
+
* - vec (vec3) : vec3 to scale
|
156
|
+
* - val (Number) : numeric value to scale by
|
157
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
160
158
|
*
|
161
|
-
*
|
162
|
-
* vec - vec3 to scale
|
163
|
-
* val - Numeric value to scale by
|
164
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
159
|
+
* Multiplies the components of a vec3 by a scalar value
|
165
160
|
*
|
166
161
|
* Returns:
|
167
162
|
* dest if specified, vec otherwise
|
168
|
-
|
163
|
+
**/
|
169
164
|
vec3.scale = function(vec, val, dest) {
|
170
165
|
if(!dest || vec == dest) {
|
171
166
|
vec[0] *= val;
|
@@ -180,18 +175,17 @@ vec3.scale = function(vec, val, dest) {
|
|
180
175
|
return dest;
|
181
176
|
};
|
182
177
|
|
183
|
-
|
184
|
-
* vec3.normalize
|
178
|
+
/**
|
179
|
+
* vec3.normalize(vec[, dest]) -> vec3
|
180
|
+
* - vec (vec3) : vec3 to normalize
|
181
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
182
|
+
*
|
185
183
|
* Generates a unit vector of the same direction as the provided vec3
|
186
184
|
* If vector length is 0, returns [0, 0, 0]
|
187
185
|
*
|
188
|
-
* Params:
|
189
|
-
* vec - vec3 to normalize
|
190
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
191
|
-
*
|
192
186
|
* Returns:
|
193
187
|
* dest if specified, vec otherwise
|
194
|
-
|
188
|
+
**/
|
195
189
|
vec3.normalize = function(vec, dest) {
|
196
190
|
if(!dest) { dest = vec; }
|
197
191
|
|
@@ -217,18 +211,17 @@ vec3.normalize = function(vec, dest) {
|
|
217
211
|
return dest;
|
218
212
|
};
|
219
213
|
|
220
|
-
|
221
|
-
* vec3.cross
|
214
|
+
/**
|
215
|
+
* vec3.cross(vec, vec2[, dest]) -> vec3
|
216
|
+
* - vec (vec3) : first operand
|
217
|
+
* - vec2 (vec3) : second operand
|
218
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
219
|
+
*
|
222
220
|
* Generates the cross product of two vec3s
|
223
221
|
*
|
224
|
-
* Params:
|
225
|
-
* vec - vec3, first operand
|
226
|
-
* vec2 - vec3, second operand
|
227
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
228
|
-
*
|
229
222
|
* Returns:
|
230
223
|
* dest if specified, vec otherwise
|
231
|
-
|
224
|
+
**/
|
232
225
|
vec3.cross = function(vec, vec2, dest){
|
233
226
|
if(!dest) { dest = vec; }
|
234
227
|
|
@@ -241,48 +234,45 @@ vec3.cross = function(vec, vec2, dest){
|
|
241
234
|
return dest;
|
242
235
|
};
|
243
236
|
|
244
|
-
|
245
|
-
* vec3.length
|
246
|
-
*
|
237
|
+
/**
|
238
|
+
* vec3.length(vec) -> Number
|
239
|
+
* - vec (vec3) : vec3 to calculate length of
|
247
240
|
*
|
248
|
-
*
|
249
|
-
* vec - vec3 to calculate length of
|
241
|
+
* Caclulates the length of a vec3
|
250
242
|
*
|
251
243
|
* Returns:
|
252
244
|
* Length of vec
|
253
|
-
|
245
|
+
**/
|
254
246
|
vec3.length = function(vec){
|
255
247
|
var x = vec[0], y = vec[1], z = vec[2];
|
256
248
|
return Math.sqrt(x*x + y*y + z*z);
|
257
249
|
};
|
258
250
|
|
259
|
-
|
260
|
-
* vec3.dot
|
261
|
-
*
|
251
|
+
/**
|
252
|
+
* vec3.dot(vec, vec2) -> Number
|
253
|
+
* - vec (vec3) : first operand
|
254
|
+
* - vec2 (vec3) : second operand
|
262
255
|
*
|
263
|
-
*
|
264
|
-
* vec - vec3, first operand
|
265
|
-
* vec2 - vec3, second operand
|
256
|
+
* Caclulates the dot product of two vec3s
|
266
257
|
*
|
267
258
|
* Returns:
|
268
259
|
* Dot product of vec and vec2
|
269
|
-
|
260
|
+
**/
|
270
261
|
vec3.dot = function(vec, vec2){
|
271
262
|
return vec[0]*vec2[0] + vec[1]*vec2[1] + vec[2]*vec2[2];
|
272
263
|
};
|
273
264
|
|
274
|
-
|
275
|
-
* vec3.direction
|
276
|
-
*
|
265
|
+
/**
|
266
|
+
* vec3.direction(vec, vec2[, dest]) -> vec3
|
267
|
+
* - vec (vec3) : origin vec3
|
268
|
+
* - vec2 (vec3) : vec3 to point to
|
269
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
277
270
|
*
|
278
|
-
*
|
279
|
-
* vec - origin vec3
|
280
|
-
* vec2 - vec3 to point to
|
281
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
271
|
+
* Generates a unit vector pointing from one vector to another
|
282
272
|
*
|
283
273
|
* Returns:
|
284
274
|
* dest if specified, vec otherwise
|
285
|
-
|
275
|
+
**/
|
286
276
|
vec3.direction = function(vec, vec2, dest) {
|
287
277
|
if(!dest) { dest = vec; }
|
288
278
|
|
@@ -305,19 +295,18 @@ vec3.direction = function(vec, vec2, dest) {
|
|
305
295
|
return dest;
|
306
296
|
};
|
307
297
|
|
308
|
-
|
309
|
-
* vec3.lerp
|
310
|
-
*
|
298
|
+
/**
|
299
|
+
* vec3.lerp(vec, vec2, lerp[, dest]) -> vec3
|
300
|
+
* - vec (vec3) : first vector
|
301
|
+
* - vec2 (vec3) : second vector
|
302
|
+
* - lerp (Number) : interpolation amount between the two inputs
|
303
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
311
304
|
*
|
312
|
-
*
|
313
|
-
* vec - vec3, first vector
|
314
|
-
* vec2 - vec3, second vector
|
315
|
-
* lerp - interpolation amount between the two inputs
|
316
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
305
|
+
* Performs a linear interpolation between two vec3
|
317
306
|
*
|
318
307
|
* Returns:
|
319
308
|
* dest if specified, vec otherwise
|
320
|
-
|
309
|
+
**/
|
321
310
|
vec3.lerp = function(vec, vec2, lerp, dest){
|
322
311
|
if(!dest) { dest = vec; }
|
323
312
|
|
@@ -328,36 +317,35 @@ vec3.lerp = function(vec, vec2, lerp, dest){
|
|
328
317
|
return dest;
|
329
318
|
}
|
330
319
|
|
331
|
-
|
332
|
-
* vec3.str
|
333
|
-
*
|
320
|
+
/**
|
321
|
+
* vec3.str(vec) -> String
|
322
|
+
* - vec (vec3) : vec3 to represent as a string
|
334
323
|
*
|
335
|
-
*
|
336
|
-
* vec - vec3 to represent as a string
|
324
|
+
* Returns a string representation of a vector
|
337
325
|
*
|
338
326
|
* Returns:
|
339
327
|
* string representation of vec
|
340
|
-
|
328
|
+
**/
|
341
329
|
vec3.str = function(vec) {
|
342
330
|
return '[' + vec[0] + ', ' + vec[1] + ', ' + vec[2] + ']';
|
343
331
|
};
|
344
332
|
|
345
|
-
|
346
|
-
* mat3
|
347
|
-
|
333
|
+
/**
|
334
|
+
* mat3
|
335
|
+
* 3x3 Matrix
|
336
|
+
**/
|
348
337
|
var mat3 = {};
|
349
338
|
|
350
|
-
|
351
|
-
* mat3.create
|
339
|
+
/**
|
340
|
+
* mat3.create([mat]) -> mat3
|
341
|
+
* - mat (mat3) : optional mat3 containing values to initialize with
|
342
|
+
*
|
352
343
|
* Creates a new instance of a mat3 using the default array type
|
353
344
|
* Any javascript array containing at least 9 numeric elements can serve as a mat3
|
354
345
|
*
|
355
|
-
* Params:
|
356
|
-
* mat - Optional, mat3 containing values to initialize with
|
357
|
-
*
|
358
346
|
* Returns:
|
359
347
|
* New mat3
|
360
|
-
|
348
|
+
**/
|
361
349
|
mat3.create = function(mat) {
|
362
350
|
var dest = new glMatrixArrayType(9);
|
363
351
|
|
@@ -377,17 +365,16 @@ mat3.create = function(mat) {
|
|
377
365
|
return dest;
|
378
366
|
};
|
379
367
|
|
380
|
-
|
381
|
-
* mat3.set
|
382
|
-
*
|
368
|
+
/**
|
369
|
+
* mat3.set(mat, dest) -> mat3
|
370
|
+
* - mat (mat3) : mat3 containing values to copy
|
371
|
+
* - dest (mat3) : mat3 receiving copied values
|
383
372
|
*
|
384
|
-
*
|
385
|
-
* mat - mat3 containing values to copy
|
386
|
-
* dest - mat3 receiving copied values
|
373
|
+
* Copies the values of one mat3 to another
|
387
374
|
*
|
388
375
|
* Returns:
|
389
376
|
* dest
|
390
|
-
|
377
|
+
**/
|
391
378
|
mat3.set = function(mat, dest) {
|
392
379
|
dest[0] = mat[0];
|
393
380
|
dest[1] = mat[1];
|
@@ -401,16 +388,15 @@ mat3.set = function(mat, dest) {
|
|
401
388
|
return dest;
|
402
389
|
};
|
403
390
|
|
404
|
-
|
405
|
-
* mat3.identity
|
406
|
-
*
|
391
|
+
/**
|
392
|
+
* mat3.identity(dest) -> mat3
|
393
|
+
* - dest (mat3) : mat3 to set
|
407
394
|
*
|
408
|
-
*
|
409
|
-
* dest - mat3 to set
|
395
|
+
* Sets a mat3 to an identity matrix
|
410
396
|
*
|
411
397
|
* Returns:
|
412
398
|
* dest
|
413
|
-
|
399
|
+
**/
|
414
400
|
mat3.identity = function(dest) {
|
415
401
|
dest[0] = 1;
|
416
402
|
dest[1] = 0;
|
@@ -424,17 +410,16 @@ mat3.identity = function(dest) {
|
|
424
410
|
return dest;
|
425
411
|
};
|
426
412
|
|
427
|
-
|
428
|
-
*
|
429
|
-
*
|
413
|
+
/**
|
414
|
+
* mat3.transpose(mat[, dest]) -> mat3
|
415
|
+
* - mat (mat3) : mat3 to transpose
|
416
|
+
* - dest (mat3) : optional mat3 receiving operation result. If not specified, result is written to +mat+.
|
430
417
|
*
|
431
|
-
*
|
432
|
-
* mat - mat3 to transpose
|
433
|
-
* dest - Optional, mat3 receiving transposed values. If not specified result is written to mat
|
418
|
+
* Transposes a mat3 (flips the values over the diagonal)
|
434
419
|
*
|
435
420
|
* Returns:
|
436
|
-
* dest
|
437
|
-
|
421
|
+
* dest if specified, mat otherwise
|
422
|
+
**/
|
438
423
|
mat3.transpose = function(mat, dest) {
|
439
424
|
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
440
425
|
if(!dest || mat == dest) {
|
@@ -462,17 +447,16 @@ mat3.transpose = function(mat, dest) {
|
|
462
447
|
return dest;
|
463
448
|
};
|
464
449
|
|
465
|
-
|
466
|
-
* mat3.toMat4
|
467
|
-
*
|
450
|
+
/**
|
451
|
+
* mat3.toMat4(mat[, dest]) -> mat4
|
452
|
+
* - mat (mat3) : mat3 containing values to copy
|
453
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to a new mat4.
|
468
454
|
*
|
469
|
-
*
|
470
|
-
* mat - mat3 containing values to copy
|
471
|
-
* dest - Optional, mat4 receiving copied values
|
455
|
+
* Copies the elements of a mat3 into the upper 3x3 elements of a mat4
|
472
456
|
*
|
473
457
|
* Returns:
|
474
458
|
* dest if specified, a new mat4 otherwise
|
475
|
-
|
459
|
+
**/
|
476
460
|
mat3.toMat4 = function(mat, dest) {
|
477
461
|
if(!dest) { dest = mat4.create(); }
|
478
462
|
|
@@ -499,38 +483,37 @@ mat3.toMat4 = function(mat, dest) {
|
|
499
483
|
return dest;
|
500
484
|
}
|
501
485
|
|
502
|
-
|
503
|
-
* mat3.str
|
504
|
-
*
|
486
|
+
/**
|
487
|
+
* mat3.str(mat) -> String
|
488
|
+
* - mat (mat3) : mat3 to represent as a string
|
505
489
|
*
|
506
|
-
*
|
507
|
-
* mat - mat3 to represent as a string
|
490
|
+
* Returns a string representation of a mat3
|
508
491
|
*
|
509
492
|
* Returns:
|
510
493
|
* string representation of mat
|
511
|
-
|
494
|
+
**/
|
512
495
|
mat3.str = function(mat) {
|
513
496
|
return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] +
|
514
497
|
', ' + mat[3] + ', '+ mat[4] + ', ' + mat[5] +
|
515
498
|
', ' + mat[6] + ', ' + mat[7] + ', '+ mat[8] + ']';
|
516
499
|
};
|
517
500
|
|
518
|
-
|
519
|
-
* mat4
|
520
|
-
|
501
|
+
/**
|
502
|
+
* mat4
|
503
|
+
* 4x4 Matrix
|
504
|
+
**/
|
521
505
|
var mat4 = {};
|
522
506
|
|
523
|
-
|
524
|
-
* mat4.create
|
507
|
+
/**
|
508
|
+
* mat4.create([mat]) -> mat4
|
509
|
+
* - mat (mat4) : optional mat4 containing values to initialize with
|
510
|
+
*
|
525
511
|
* Creates a new instance of a mat4 using the default array type
|
526
512
|
* Any javascript array containing at least 16 numeric elements can serve as a mat4
|
527
513
|
*
|
528
|
-
* Params:
|
529
|
-
* mat - Optional, mat4 containing values to initialize with
|
530
|
-
*
|
531
514
|
* Returns:
|
532
515
|
* New mat4
|
533
|
-
|
516
|
+
**/
|
534
517
|
mat4.create = function(mat) {
|
535
518
|
var dest = new glMatrixArrayType(16);
|
536
519
|
|
@@ -556,17 +539,16 @@ mat4.create = function(mat) {
|
|
556
539
|
return dest;
|
557
540
|
};
|
558
541
|
|
559
|
-
|
560
|
-
* mat4.set
|
561
|
-
*
|
542
|
+
/**
|
543
|
+
* mat4.set(mat, dest) -> mat4
|
544
|
+
* - mat (mat4) : mat4 containing values to copy
|
545
|
+
* - dest (mat4) : mat4 receiving copied values
|
562
546
|
*
|
563
|
-
*
|
564
|
-
* mat - mat4 containing values to copy
|
565
|
-
* dest - mat4 receiving copied values
|
547
|
+
* Copies the values of one mat4 to another
|
566
548
|
*
|
567
549
|
* Returns:
|
568
550
|
* dest
|
569
|
-
|
551
|
+
**/
|
570
552
|
mat4.set = function(mat, dest) {
|
571
553
|
dest[0] = mat[0];
|
572
554
|
dest[1] = mat[1];
|
@@ -587,16 +569,15 @@ mat4.set = function(mat, dest) {
|
|
587
569
|
return dest;
|
588
570
|
};
|
589
571
|
|
590
|
-
|
591
|
-
* mat4.identity
|
592
|
-
*
|
572
|
+
/**
|
573
|
+
* mat4.identity(dest) -> mat4
|
574
|
+
* - dest (mat4) : mat4 to set
|
593
575
|
*
|
594
|
-
*
|
595
|
-
* dest - mat4 to set
|
576
|
+
* Sets a mat4 to an identity matrix
|
596
577
|
*
|
597
578
|
* Returns:
|
598
579
|
* dest
|
599
|
-
|
580
|
+
**/
|
600
581
|
mat4.identity = function(dest) {
|
601
582
|
dest[0] = 1;
|
602
583
|
dest[1] = 0;
|
@@ -617,17 +598,16 @@ mat4.identity = function(dest) {
|
|
617
598
|
return dest;
|
618
599
|
};
|
619
600
|
|
620
|
-
|
621
|
-
* mat4.transpose
|
622
|
-
*
|
601
|
+
/**
|
602
|
+
* mat4.transpose(mat[, dest]) -> mat4
|
603
|
+
* - mat (mat4) : mat4 to transpose
|
604
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
623
605
|
*
|
624
|
-
*
|
625
|
-
* mat - mat4 to transpose
|
626
|
-
* dest - Optional, mat4 receiving transposed values. If not specified result is written to mat
|
606
|
+
* Transposes a mat4 (flips the values over the diagonal)
|
627
607
|
*
|
628
608
|
* Returns:
|
629
609
|
* dest is specified, mat otherwise
|
630
|
-
|
610
|
+
**/
|
631
611
|
mat4.transpose = function(mat, dest) {
|
632
612
|
// If we are transposing ourselves we can skip a few steps but have to cache some values
|
633
613
|
if(!dest || mat == dest) {
|
@@ -669,16 +649,15 @@ mat4.transpose = function(mat, dest) {
|
|
669
649
|
return dest;
|
670
650
|
};
|
671
651
|
|
672
|
-
|
673
|
-
* mat4.determinant
|
674
|
-
*
|
652
|
+
/**
|
653
|
+
* mat4.determinant(mat) -> mat4
|
654
|
+
* - mat (mat4) : mat4 to calculate determinant of
|
675
655
|
*
|
676
|
-
*
|
677
|
-
* mat - mat4 to calculate determinant of
|
656
|
+
* Calculates the determinant of a mat4
|
678
657
|
*
|
679
658
|
* Returns:
|
680
659
|
* determinant of mat
|
681
|
-
|
660
|
+
**/
|
682
661
|
mat4.determinant = function(mat) {
|
683
662
|
// Cache the matrix values (makes for huge speed increases!)
|
684
663
|
var a00 = mat[0], a01 = mat[1], a02 = mat[2], a03 = mat[3];
|
@@ -694,17 +673,16 @@ mat4.determinant = function(mat) {
|
|
694
673
|
a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
|
695
674
|
};
|
696
675
|
|
697
|
-
|
698
|
-
* mat4.inverse
|
699
|
-
*
|
676
|
+
/**
|
677
|
+
* mat4.inverse(mat[, dest]) -> mat4
|
678
|
+
* - mat (mat4) : mat4 to calculate inverse of
|
679
|
+
* - dest (mat4) : optional mat4 receiving inverse matrix. If not specified, result is written to +mat+.
|
700
680
|
*
|
701
|
-
*
|
702
|
-
* mat - mat4 to calculate inverse of
|
703
|
-
* dest - Optional, mat4 receiving inverse matrix. If not specified result is written to mat
|
681
|
+
* Calculates the inverse matrix of a mat4
|
704
682
|
*
|
705
683
|
* Returns:
|
706
684
|
* dest is specified, mat otherwise
|
707
|
-
|
685
|
+
**/
|
708
686
|
mat4.inverse = function(mat, dest) {
|
709
687
|
if(!dest) { dest = mat; }
|
710
688
|
|
@@ -750,17 +728,16 @@ mat4.inverse = function(mat, dest) {
|
|
750
728
|
return dest;
|
751
729
|
};
|
752
730
|
|
753
|
-
|
754
|
-
* mat4.toRotationMat
|
755
|
-
*
|
731
|
+
/**
|
732
|
+
* mat4.toRotationMat(mat[, dest]) -> mat4
|
733
|
+
* - mat (mat4) : mat4 containing values to copy
|
734
|
+
* - dest (mat4) : optional mat4 receiving copied values. If not specified, result is written to +mat+.
|
756
735
|
*
|
757
|
-
*
|
758
|
-
* mat - mat4 containing values to copy
|
759
|
-
* dest - Optional, mat4 receiving copied values
|
736
|
+
* Copies the upper 3x3 elements of a mat4 into another mat4
|
760
737
|
*
|
761
738
|
* Returns:
|
762
739
|
* dest is specified, a new mat4 otherwise
|
763
|
-
|
740
|
+
**/
|
764
741
|
mat4.toRotationMat = function(mat, dest) {
|
765
742
|
if(!dest) { dest = mat4.create(); }
|
766
743
|
|
@@ -784,17 +761,16 @@ mat4.toRotationMat = function(mat, dest) {
|
|
784
761
|
return dest;
|
785
762
|
};
|
786
763
|
|
787
|
-
|
788
|
-
* mat4.toMat3
|
789
|
-
*
|
764
|
+
/**
|
765
|
+
* mat4.toMat3(mat[, dest]) -> mat3
|
766
|
+
* - mat (mat4) : mat4 containing values to copy
|
767
|
+
* - dest (mat3) : optional mat3 receiving copied values. If not specified, a new mat3 is created.
|
790
768
|
*
|
791
|
-
*
|
792
|
-
* mat - mat4 containing values to copy
|
793
|
-
* dest - Optional, mat3 receiving copied values
|
769
|
+
* Copies the upper 3x3 elements of a mat4 into a mat3
|
794
770
|
*
|
795
771
|
* Returns:
|
796
772
|
* dest is specified, a new mat3 otherwise
|
797
|
-
|
773
|
+
**/
|
798
774
|
mat4.toMat3 = function(mat, dest) {
|
799
775
|
if(!dest) { dest = mat3.create(); }
|
800
776
|
|
@@ -811,18 +787,17 @@ mat4.toMat3 = function(mat, dest) {
|
|
811
787
|
return dest;
|
812
788
|
};
|
813
789
|
|
814
|
-
|
815
|
-
* mat4.toInverseMat3
|
790
|
+
/**
|
791
|
+
* mat4.toInverseMat3(mat[, dest]) -> mat3
|
792
|
+
* - mat (mat4) : mat4 containing values to invert and copy
|
793
|
+
* - dest (mat3) : optional mat3 receiving values
|
794
|
+
*
|
816
795
|
* Calculates the inverse of the upper 3x3 elements of a mat4 and copies the result into a mat3
|
817
796
|
* The resulting matrix is useful for calculating transformed normals
|
818
797
|
*
|
819
|
-
* Params:
|
820
|
-
* mat - mat4 containing values to invert and copy
|
821
|
-
* dest - Optional, mat3 receiving values
|
822
|
-
*
|
823
798
|
* Returns:
|
824
799
|
* dest is specified, a new mat3 otherwise
|
825
|
-
|
800
|
+
**/
|
826
801
|
mat4.toInverseMat3 = function(mat, dest) {
|
827
802
|
// Cache the matrix values (makes for huge speed increases!)
|
828
803
|
var a00 = mat[0], a01 = mat[1], a02 = mat[2];
|
@@ -852,18 +827,17 @@ mat4.toInverseMat3 = function(mat, dest) {
|
|
852
827
|
return dest;
|
853
828
|
};
|
854
829
|
|
855
|
-
|
856
|
-
* mat4.multiply
|
857
|
-
*
|
830
|
+
/**
|
831
|
+
* mat4.multiply(mat, mat2[, dest]) -> mat4
|
832
|
+
* - mat (mat4) : first operand
|
833
|
+
* - mat2 (mat4) : second operand
|
834
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
858
835
|
*
|
859
|
-
*
|
860
|
-
* mat - mat4, first operand
|
861
|
-
* mat2 - mat4, second operand
|
862
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
836
|
+
* Performs a matrix multiplication
|
863
837
|
*
|
864
838
|
* Returns:
|
865
839
|
* dest if specified, mat otherwise
|
866
|
-
|
840
|
+
**/
|
867
841
|
mat4.multiply = function(mat, mat2, dest) {
|
868
842
|
if(!dest) { dest = mat }
|
869
843
|
|
@@ -898,19 +872,18 @@ mat4.multiply = function(mat, mat2, dest) {
|
|
898
872
|
return dest;
|
899
873
|
};
|
900
874
|
|
901
|
-
|
902
|
-
* mat4.multiplyVec3
|
875
|
+
/**
|
876
|
+
* mat4.multiplyVec3(mat, vec[, dest]) -> vec3
|
877
|
+
* - mat (mat4) : mat4 to transform the vector with
|
878
|
+
* - vec (vec3) : vec3 to transform
|
879
|
+
* - dest (vec3) : optional vec3 receiving operation result. If not specified, result is written to +vec+.
|
880
|
+
*
|
903
881
|
* Transforms a vec3 with the given matrix
|
904
882
|
* 4th vector component is implicitly '1'
|
905
883
|
*
|
906
|
-
* Params:
|
907
|
-
* mat - mat4 to transform the vector with
|
908
|
-
* vec - vec3 to transform
|
909
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
910
|
-
*
|
911
884
|
* Returns:
|
912
|
-
* dest if specified,
|
913
|
-
|
885
|
+
* dest if specified, vec3 otherwise
|
886
|
+
**/
|
914
887
|
mat4.multiplyVec3 = function(mat, vec, dest) {
|
915
888
|
if(!dest) { dest = vec }
|
916
889
|
|
@@ -923,18 +896,17 @@ mat4.multiplyVec3 = function(mat, vec, dest) {
|
|
923
896
|
return dest;
|
924
897
|
};
|
925
898
|
|
926
|
-
|
927
|
-
* mat4.multiplyVec4
|
928
|
-
*
|
899
|
+
/**
|
900
|
+
* mat4.multiplyVec4(mat, vec[, dest]) -> vec4
|
901
|
+
* - mat (mat4) : mat4 to transform the vector with
|
902
|
+
* - vec (vec4) : vec4 to transform
|
903
|
+
* - dest (vec4) : optional vec4 receiving operation result. If not specified, result is written to +vec+.
|
929
904
|
*
|
930
|
-
*
|
931
|
-
* mat - mat4 to transform the vector with
|
932
|
-
* vec - vec4 to transform
|
933
|
-
* dest - Optional, vec4 receiving operation result. If not specified result is written to vec
|
905
|
+
* Transforms a vec4 with the given matrix
|
934
906
|
*
|
935
907
|
* Returns:
|
936
908
|
* dest if specified, vec otherwise
|
937
|
-
|
909
|
+
**/
|
938
910
|
mat4.multiplyVec4 = function(mat, vec, dest) {
|
939
911
|
if(!dest) { dest = vec }
|
940
912
|
|
@@ -948,18 +920,17 @@ mat4.multiplyVec4 = function(mat, vec, dest) {
|
|
948
920
|
return dest;
|
949
921
|
};
|
950
922
|
|
951
|
-
|
952
|
-
* mat4.translate
|
953
|
-
*
|
923
|
+
/**
|
924
|
+
* mat4.translate(mat, vec[, dest]) -> mat4
|
925
|
+
* - mat (mat4) : mat4 to translate
|
926
|
+
* - vec (vec3) : vec3 specifying the translation
|
927
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
954
928
|
*
|
955
|
-
*
|
956
|
-
* mat - mat4 to translate
|
957
|
-
* vec - vec3 specifying the translation
|
958
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
929
|
+
* Translates a matrix by the given vector
|
959
930
|
*
|
960
931
|
* Returns:
|
961
932
|
* dest if specified, mat otherwise
|
962
|
-
|
933
|
+
**/
|
963
934
|
mat4.translate = function(mat, vec, dest) {
|
964
935
|
var x = vec[0], y = vec[1], z = vec[2];
|
965
936
|
|
@@ -995,18 +966,17 @@ mat4.translate = function(mat, vec, dest) {
|
|
995
966
|
return dest;
|
996
967
|
};
|
997
968
|
|
998
|
-
|
999
|
-
* mat4.scale
|
1000
|
-
*
|
969
|
+
/**
|
970
|
+
* mat4.scale(mat, vec[, dest]) -> mat4
|
971
|
+
* - mat (mat4) : mat4 to scale
|
972
|
+
* - vec (vec3) : vec3 specifying the scale for each axis
|
973
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1001
974
|
*
|
1002
|
-
*
|
1003
|
-
* mat - mat4 to scale
|
1004
|
-
* vec - vec3 specifying the scale for each axis
|
1005
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
975
|
+
* Scales a matrix by the given vector
|
1006
976
|
*
|
1007
977
|
* Returns:
|
1008
978
|
* dest if specified, mat otherwise
|
1009
|
-
|
979
|
+
**/
|
1010
980
|
mat4.scale = function(mat, vec, dest) {
|
1011
981
|
var x = vec[0], y = vec[1], z = vec[2];
|
1012
982
|
|
@@ -1045,20 +1015,19 @@ mat4.scale = function(mat, vec, dest) {
|
|
1045
1015
|
return dest;
|
1046
1016
|
};
|
1047
1017
|
|
1048
|
-
|
1049
|
-
* mat4.rotate
|
1018
|
+
/**
|
1019
|
+
* mat4.rotate(mat, angle, axis[, dest]) -> mat4
|
1020
|
+
* - mat (mat4) : mat4 to rotate
|
1021
|
+
* - angle (Number) : angle (in radians) to rotate
|
1022
|
+
* - axis (vec3) : vec3 representing the axis to rotate around
|
1023
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1024
|
+
*
|
1050
1025
|
* Rotates a matrix by the given angle around the specified axis
|
1051
1026
|
* If rotating around a primary axis (X,Y,Z) one of the specialized rotation functions should be used instead for performance
|
1052
1027
|
*
|
1053
|
-
* Params:
|
1054
|
-
* mat - mat4 to rotate
|
1055
|
-
* angle - angle (in radians) to rotate
|
1056
|
-
* axis - vec3 representing the axis to rotate around
|
1057
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
1058
|
-
*
|
1059
1028
|
* Returns:
|
1060
1029
|
* dest if specified, mat otherwise
|
1061
|
-
|
1030
|
+
**/
|
1062
1031
|
mat4.rotate = function(mat, angle, axis, dest) {
|
1063
1032
|
var x = axis[0], y = axis[1], z = axis[2];
|
1064
1033
|
var len = Math.sqrt(x*x + y*y + z*z);
|
@@ -1111,18 +1080,17 @@ mat4.rotate = function(mat, angle, axis, dest) {
|
|
1111
1080
|
return dest;
|
1112
1081
|
};
|
1113
1082
|
|
1114
|
-
|
1115
|
-
* mat4.rotateX
|
1116
|
-
*
|
1083
|
+
/**
|
1084
|
+
* mat4.rotateX(mat, angle[, dest]) -> mat4
|
1085
|
+
* - mat (mat4) : mat4 to rotate
|
1086
|
+
* - angle (Number) : angle (in radians) to rotate
|
1087
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1117
1088
|
*
|
1118
|
-
*
|
1119
|
-
* mat - mat4 to rotate
|
1120
|
-
* angle - angle (in radians) to rotate
|
1121
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
1089
|
+
* Rotates a matrix by the given angle around the X axis
|
1122
1090
|
*
|
1123
1091
|
* Returns:
|
1124
1092
|
* dest if specified, mat otherwise
|
1125
|
-
|
1093
|
+
**/
|
1126
1094
|
mat4.rotateX = function(mat, angle, dest) {
|
1127
1095
|
var s = Math.sin(angle);
|
1128
1096
|
var c = Math.cos(angle);
|
@@ -1158,18 +1126,17 @@ mat4.rotateX = function(mat, angle, dest) {
|
|
1158
1126
|
return dest;
|
1159
1127
|
};
|
1160
1128
|
|
1161
|
-
|
1162
|
-
* mat4.rotateY
|
1163
|
-
*
|
1129
|
+
/**
|
1130
|
+
* mat4.rotateY(mat, angle[, dest]) -> mat4
|
1131
|
+
* - mat (mat4) : mat4 to rotate
|
1132
|
+
* - angle (Number) : angle (in radians) to rotate
|
1133
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1164
1134
|
*
|
1165
|
-
*
|
1166
|
-
* mat - mat4 to rotate
|
1167
|
-
* angle - angle (in radians) to rotate
|
1168
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
1135
|
+
* Rotates a matrix by the given angle around the Y axis
|
1169
1136
|
*
|
1170
1137
|
* Returns:
|
1171
1138
|
* dest if specified, mat otherwise
|
1172
|
-
|
1139
|
+
**/
|
1173
1140
|
mat4.rotateY = function(mat, angle, dest) {
|
1174
1141
|
var s = Math.sin(angle);
|
1175
1142
|
var c = Math.cos(angle);
|
@@ -1205,18 +1172,17 @@ mat4.rotateY = function(mat, angle, dest) {
|
|
1205
1172
|
return dest;
|
1206
1173
|
};
|
1207
1174
|
|
1208
|
-
|
1209
|
-
* mat4.rotateZ
|
1210
|
-
*
|
1175
|
+
/**
|
1176
|
+
* mat4.rotateZ(mat, angle[, dest]) -> mat4
|
1177
|
+
* - mat (mat4) : mat4 to rotate
|
1178
|
+
* - angle (Number) : angle (in radians) to rotate
|
1179
|
+
* - dest (mat4) : optional mat4 receiving operation result. If not specified, result is written to +mat+.
|
1211
1180
|
*
|
1212
|
-
*
|
1213
|
-
* mat - mat4 to rotate
|
1214
|
-
* angle - angle (in radians) to rotate
|
1215
|
-
* dest - Optional, mat4 receiving operation result. If not specified result is written to mat
|
1181
|
+
* Rotates a matrix by the given angle around the Z axis
|
1216
1182
|
*
|
1217
1183
|
* Returns:
|
1218
1184
|
* dest if specified, mat otherwise
|
1219
|
-
|
1185
|
+
**/
|
1220
1186
|
mat4.rotateZ = function(mat, angle, dest) {
|
1221
1187
|
var s = Math.sin(angle);
|
1222
1188
|
var c = Math.cos(angle);
|
@@ -1253,19 +1219,21 @@ mat4.rotateZ = function(mat, angle, dest) {
|
|
1253
1219
|
return dest;
|
1254
1220
|
};
|
1255
1221
|
|
1256
|
-
|
1257
|
-
* mat4.frustum
|
1258
|
-
*
|
1222
|
+
/**
|
1223
|
+
* mat4.frustum(left, right, bottom, top, near, far[, dest]) -> mat4
|
1224
|
+
* - left (Number) : scalar, left bounds of the frustum
|
1225
|
+
* - right (Number) : scalar, right bounds of the frustum
|
1226
|
+
* - bottom (Number) : scalar, bottom bounds of the frustum
|
1227
|
+
* - top (Number) : scalar, top bounds of the frustum
|
1228
|
+
* - near (Number) : scalar, near bounds of the frustum
|
1229
|
+
* - far (Number) : scalar, far bounds of the frustum
|
1230
|
+
* - dest (mat4) : optional mat4 frustum matrix will be written into. If not specified, a new mat4 is created.
|
1259
1231
|
*
|
1260
|
-
*
|
1261
|
-
* left, right - scalar, left and right bounds of the frustum
|
1262
|
-
* bottom, top - scalar, bottom and top bounds of the frustum
|
1263
|
-
* near, far - scalar, near and far bounds of the frustum
|
1264
|
-
* dest - Optional, mat4 frustum matrix will be written into
|
1232
|
+
* Generates a frustum matrix with the given bounds
|
1265
1233
|
*
|
1266
1234
|
* Returns:
|
1267
1235
|
* dest if specified, a new mat4 otherwise
|
1268
|
-
|
1236
|
+
**/
|
1269
1237
|
mat4.frustum = function(left, right, bottom, top, near, far, dest) {
|
1270
1238
|
if(!dest) { dest = mat4.create(); }
|
1271
1239
|
var rl = (right - left);
|
@@ -1290,38 +1258,40 @@ mat4.frustum = function(left, right, bottom, top, near, far, dest) {
|
|
1290
1258
|
return dest;
|
1291
1259
|
};
|
1292
1260
|
|
1293
|
-
|
1294
|
-
* mat4.perspective
|
1295
|
-
*
|
1261
|
+
/**
|
1262
|
+
* mat4.perspective(fovy, aspect, near, far[, dest]) -> mat4
|
1263
|
+
* - fovy (Number) : scalar, vertical field of view
|
1264
|
+
* - aspect (Number) : scalar, aspect ratio. Typically viewport width/height
|
1265
|
+
* - near (Number) : scalar, near bounds of the frustum
|
1266
|
+
* - far (Number) : scalar, far bounds of the frustum
|
1267
|
+
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1296
1268
|
*
|
1297
|
-
*
|
1298
|
-
* fovy - scalar, vertical field of view
|
1299
|
-
* aspect - scalar, aspect ratio. typically viewport width/height
|
1300
|
-
* near, far - scalar, near and far bounds of the frustum
|
1301
|
-
* dest - Optional, mat4 frustum matrix will be written into
|
1269
|
+
* Generates a perspective projection matrix with the given bounds
|
1302
1270
|
*
|
1303
1271
|
* Returns:
|
1304
1272
|
* dest if specified, a new mat4 otherwise
|
1305
|
-
|
1273
|
+
**/
|
1306
1274
|
mat4.perspective = function(fovy, aspect, near, far, dest) {
|
1307
1275
|
var top = near*Math.tan(fovy*Math.PI / 360.0);
|
1308
1276
|
var right = top*aspect;
|
1309
1277
|
return mat4.frustum(-right, right, -top, top, near, far, dest);
|
1310
1278
|
};
|
1311
1279
|
|
1312
|
-
|
1313
|
-
* mat4.ortho
|
1314
|
-
*
|
1280
|
+
/**
|
1281
|
+
* mat4.ortho(left, right, bottom, top, near, far[, dest]) -> mat4
|
1282
|
+
* - left (Number) : scalar, left bounds of the frustum
|
1283
|
+
* - right (Number) : scalar, right bounds of the frustum
|
1284
|
+
* - bottom (Number) : scalar, bottom bounds of the frustum
|
1285
|
+
* - top (Number) : scalar, top bounds of the frustum
|
1286
|
+
* - near (Number) : scalar, near bounds of the frustum
|
1287
|
+
* - far (Number) : scalar, far bounds of the frustum
|
1288
|
+
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1315
1289
|
*
|
1316
|
-
*
|
1317
|
-
* left, right - scalar, left and right bounds of the frustum
|
1318
|
-
* bottom, top - scalar, bottom and top bounds of the frustum
|
1319
|
-
* near, far - scalar, near and far bounds of the frustum
|
1320
|
-
* dest - Optional, mat4 frustum matrix will be written into
|
1290
|
+
* Generates a orthogonal projection matrix with the given bounds
|
1321
1291
|
*
|
1322
1292
|
* Returns:
|
1323
1293
|
* dest if specified, a new mat4 otherwise
|
1324
|
-
|
1294
|
+
**/
|
1325
1295
|
mat4.ortho = function(left, right, bottom, top, near, far, dest) {
|
1326
1296
|
if(!dest) { dest = mat4.create(); }
|
1327
1297
|
var rl = (right - left);
|
@@ -1346,19 +1316,18 @@ mat4.ortho = function(left, right, bottom, top, near, far, dest) {
|
|
1346
1316
|
return dest;
|
1347
1317
|
};
|
1348
1318
|
|
1349
|
-
|
1350
|
-
* mat4.
|
1351
|
-
*
|
1319
|
+
/**
|
1320
|
+
* mat4.lookAt(eye, center, up[, dest]) -> mat4
|
1321
|
+
* - eye (vec3) : position of the viewer
|
1322
|
+
* - center (vec3) : the point the viewer is looking at
|
1323
|
+
* - up (vec3) : vec3 pointing "up"
|
1324
|
+
* - dest (mat4) : optional mat4 the frustum matrix will be written into. If not specified, a new mat4 is created.
|
1352
1325
|
*
|
1353
|
-
*
|
1354
|
-
* eye - vec3, position of the viewer
|
1355
|
-
* center - vec3, point the viewer is looking at
|
1356
|
-
* up - vec3 pointing "up"
|
1357
|
-
* dest - Optional, mat4 frustum matrix will be written into
|
1326
|
+
* Generates a look-at matrix with the given eye position, focal point, and up axis
|
1358
1327
|
*
|
1359
1328
|
* Returns:
|
1360
1329
|
* dest if specified, a new mat4 otherwise
|
1361
|
-
|
1330
|
+
**/
|
1362
1331
|
mat4.lookAt = function(eye, center, up, dest) {
|
1363
1332
|
if(!dest) { dest = mat4.create(); }
|
1364
1333
|
|
@@ -1442,16 +1411,15 @@ mat4.lookAt = function(eye, center, up, dest) {
|
|
1442
1411
|
return dest;
|
1443
1412
|
};
|
1444
1413
|
|
1445
|
-
|
1446
|
-
* mat4.str
|
1447
|
-
*
|
1414
|
+
/**
|
1415
|
+
* mat4.str(mat) -> String
|
1416
|
+
* - mat (mat4) : mat4 to represent as a string
|
1448
1417
|
*
|
1449
|
-
*
|
1450
|
-
* mat - mat4 to represent as a string
|
1418
|
+
* Returns a string representation of a mat4
|
1451
1419
|
*
|
1452
1420
|
* Returns:
|
1453
1421
|
* string representation of mat
|
1454
|
-
|
1422
|
+
**/
|
1455
1423
|
mat4.str = function(mat) {
|
1456
1424
|
return '[' + mat[0] + ', ' + mat[1] + ', ' + mat[2] + ', ' + mat[3] +
|
1457
1425
|
', '+ mat[4] + ', ' + mat[5] + ', ' + mat[6] + ', ' + mat[7] +
|
@@ -1459,22 +1427,22 @@ mat4.str = function(mat) {
|
|
1459
1427
|
', '+ mat[12] + ', ' + mat[13] + ', ' + mat[14] + ', ' + mat[15] + ']';
|
1460
1428
|
};
|
1461
1429
|
|
1462
|
-
|
1463
|
-
* quat4
|
1464
|
-
|
1430
|
+
/**
|
1431
|
+
* quat4
|
1432
|
+
* Quaternions
|
1433
|
+
**/
|
1465
1434
|
quat4 = {};
|
1466
1435
|
|
1467
|
-
|
1468
|
-
* quat4.create
|
1436
|
+
/**
|
1437
|
+
* quat4.create([quat]) -> quat4
|
1438
|
+
* - quat (quat4) : optional quat4 containing values to initialize with
|
1439
|
+
*
|
1469
1440
|
* Creates a new instance of a quat4 using the default array type
|
1470
1441
|
* Any javascript array containing at least 4 numeric elements can serve as a quat4
|
1471
1442
|
*
|
1472
|
-
* Params:
|
1473
|
-
* quat - Optional, quat4 containing values to initialize with
|
1474
|
-
*
|
1475
1443
|
* Returns:
|
1476
1444
|
* New quat4
|
1477
|
-
|
1445
|
+
**/
|
1478
1446
|
quat4.create = function(quat) {
|
1479
1447
|
var dest = new glMatrixArrayType(4);
|
1480
1448
|
|
@@ -1488,17 +1456,16 @@ quat4.create = function(quat) {
|
|
1488
1456
|
return dest;
|
1489
1457
|
};
|
1490
1458
|
|
1491
|
-
|
1492
|
-
* quat4.set
|
1493
|
-
*
|
1459
|
+
/**
|
1460
|
+
* quat4.set(quat, dest) -> quat4
|
1461
|
+
* - quat (quat4) : quat4 containing values to copy
|
1462
|
+
* - dest (quat4) : quat4 receiving copied values
|
1494
1463
|
*
|
1495
|
-
*
|
1496
|
-
* quat - quat4 containing values to copy
|
1497
|
-
* dest - quat4 receiving copied values
|
1464
|
+
* Copies the values of one quat4 to another
|
1498
1465
|
*
|
1499
1466
|
* Returns:
|
1500
1467
|
* dest
|
1501
|
-
|
1468
|
+
**/
|
1502
1469
|
quat4.set = function(quat, dest) {
|
1503
1470
|
dest[0] = quat[0];
|
1504
1471
|
dest[1] = quat[1];
|
@@ -1508,19 +1475,18 @@ quat4.set = function(quat, dest) {
|
|
1508
1475
|
return dest;
|
1509
1476
|
};
|
1510
1477
|
|
1511
|
-
|
1512
|
-
* quat4.calculateW
|
1478
|
+
/**
|
1479
|
+
* quat4.calculateW(quat[, dest]) -> quat4
|
1480
|
+
* - quat (quat4) : quat4 to calculate W component of
|
1481
|
+
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1482
|
+
*
|
1513
1483
|
* Calculates the W component of a quat4 from the X, Y, and Z components.
|
1514
1484
|
* Assumes that quaternion is 1 unit in length.
|
1515
1485
|
* Any existing W component will be ignored.
|
1516
1486
|
*
|
1517
|
-
* Params:
|
1518
|
-
* quat - quat4 to calculate W component of
|
1519
|
-
* dest - Optional, quat4 receiving calculated values. If not specified result is written to quat
|
1520
|
-
*
|
1521
1487
|
* Returns:
|
1522
1488
|
* dest if specified, quat otherwise
|
1523
|
-
|
1489
|
+
**/
|
1524
1490
|
quat4.calculateW = function(quat, dest) {
|
1525
1491
|
var x = quat[0], y = quat[1], z = quat[2];
|
1526
1492
|
|
@@ -1535,17 +1501,16 @@ quat4.calculateW = function(quat, dest) {
|
|
1535
1501
|
return dest;
|
1536
1502
|
}
|
1537
1503
|
|
1538
|
-
|
1539
|
-
* quat4.inverse
|
1540
|
-
*
|
1504
|
+
/**
|
1505
|
+
* quat4.inverse(quat[, dest]) -> quat4
|
1506
|
+
* - quat (quat4) : quat4 to calculate inverse of
|
1507
|
+
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1541
1508
|
*
|
1542
|
-
*
|
1543
|
-
* quat - quat4 to calculate inverse of
|
1544
|
-
* dest - Optional, quat4 receiving inverse values. If not specified result is written to quat
|
1509
|
+
* Calculates the inverse of a quat4
|
1545
1510
|
*
|
1546
1511
|
* Returns:
|
1547
1512
|
* dest if specified, quat otherwise
|
1548
|
-
|
1513
|
+
**/
|
1549
1514
|
quat4.inverse = function(quat, dest) {
|
1550
1515
|
if(!dest || quat == dest) {
|
1551
1516
|
quat[0] *= 1;
|
@@ -1560,33 +1525,31 @@ quat4.inverse = function(quat, dest) {
|
|
1560
1525
|
return dest;
|
1561
1526
|
}
|
1562
1527
|
|
1563
|
-
|
1564
|
-
* quat4.length
|
1565
|
-
*
|
1528
|
+
/**
|
1529
|
+
* quat4.length(quat) -> quat4
|
1530
|
+
* - quat (quat4) : quat4 to calculate length of
|
1566
1531
|
*
|
1567
|
-
*
|
1568
|
-
* quat - quat4 to calculate length of
|
1532
|
+
* Calculates the length of a quat4
|
1569
1533
|
*
|
1570
1534
|
* Returns:
|
1571
1535
|
* Length of quat
|
1572
|
-
|
1536
|
+
**/
|
1573
1537
|
quat4.length = function(quat) {
|
1574
1538
|
var x = quat[0], y = quat[1], z = quat[2], w = quat[3];
|
1575
1539
|
return Math.sqrt(x*x + y*y + z*z + w*w);
|
1576
1540
|
}
|
1577
1541
|
|
1578
|
-
|
1579
|
-
* quat4.normalize
|
1542
|
+
/**
|
1543
|
+
* quat4.normalize(quat[, dest]) -> quat4
|
1544
|
+
* - quat (quat4) : quat4 to normalize
|
1545
|
+
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1546
|
+
*
|
1580
1547
|
* Generates a unit quaternion of the same direction as the provided quat4
|
1581
1548
|
* If quaternion length is 0, returns [0, 0, 0, 0]
|
1582
1549
|
*
|
1583
|
-
* Params:
|
1584
|
-
* quat - quat4 to normalize
|
1585
|
-
* dest - Optional, quat4 receiving operation result. If not specified result is written to quat
|
1586
|
-
*
|
1587
1550
|
* Returns:
|
1588
1551
|
* dest if specified, quat otherwise
|
1589
|
-
|
1552
|
+
**/
|
1590
1553
|
quat4.normalize = function(quat, dest) {
|
1591
1554
|
if(!dest) { dest = quat; }
|
1592
1555
|
|
@@ -1608,18 +1571,17 @@ quat4.normalize = function(quat, dest) {
|
|
1608
1571
|
return dest;
|
1609
1572
|
}
|
1610
1573
|
|
1611
|
-
|
1612
|
-
* quat4.multiply
|
1613
|
-
*
|
1574
|
+
/**
|
1575
|
+
* quat4.multiply(quat, quat2[, dest]) -> quat4
|
1576
|
+
* - quat (quat4) : first operand
|
1577
|
+
* - quat2 (quat4) : second operand
|
1578
|
+
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to quat.
|
1614
1579
|
*
|
1615
|
-
*
|
1616
|
-
* quat - quat4, first operand
|
1617
|
-
* quat2 - quat4, second operand
|
1618
|
-
* dest - Optional, quat4 receiving operation result. If not specified result is written to quat
|
1580
|
+
* Performs a quaternion multiplication
|
1619
1581
|
*
|
1620
1582
|
* Returns:
|
1621
1583
|
* dest if specified, quat otherwise
|
1622
|
-
|
1584
|
+
**/
|
1623
1585
|
quat4.multiply = function(quat, quat2, dest) {
|
1624
1586
|
if(!dest) { dest = quat; }
|
1625
1587
|
|
@@ -1634,18 +1596,17 @@ quat4.multiply = function(quat, quat2, dest) {
|
|
1634
1596
|
return dest;
|
1635
1597
|
}
|
1636
1598
|
|
1637
|
-
|
1638
|
-
* quat4.multiplyVec3
|
1639
|
-
*
|
1599
|
+
/**
|
1600
|
+
* quat4.multiplyVec3(quat, vec[, dest]) -> vec3
|
1601
|
+
* - quat (quat4) : quat4 to transform the vector with
|
1602
|
+
* - vec (vec3) : vec3 to transform
|
1603
|
+
* - dest (vec3) : optional vec3 receiving calculated values. If not specified, result is written to +vec+.
|
1640
1604
|
*
|
1641
|
-
*
|
1642
|
-
* quat - quat4 to transform the vector with
|
1643
|
-
* vec - vec3 to transform
|
1644
|
-
* dest - Optional, vec3 receiving operation result. If not specified result is written to vec
|
1605
|
+
* Transforms a vec3 with the given quaternion
|
1645
1606
|
*
|
1646
1607
|
* Returns:
|
1647
1608
|
* dest if specified, vec otherwise
|
1648
|
-
|
1609
|
+
**/
|
1649
1610
|
quat4.multiplyVec3 = function(quat, vec, dest) {
|
1650
1611
|
if(!dest) { dest = vec; }
|
1651
1612
|
|
@@ -1666,17 +1627,16 @@ quat4.multiplyVec3 = function(quat, vec, dest) {
|
|
1666
1627
|
return dest;
|
1667
1628
|
}
|
1668
1629
|
|
1669
|
-
|
1670
|
-
* quat4.toMat3
|
1671
|
-
*
|
1630
|
+
/**
|
1631
|
+
* quat4.toMat3(quat[, dest]) -> mat3
|
1632
|
+
* - quat (quat4) : quat4 to create matrix from
|
1633
|
+
* - dest (mat3) : optional mat3 receiving operation result. If not specified, a new mat3 is created.
|
1672
1634
|
*
|
1673
|
-
*
|
1674
|
-
* quat - quat4 to create matrix from
|
1675
|
-
* dest - Optional, mat3 receiving operation result
|
1635
|
+
* Calculates a 3x3 matrix from the given quat4
|
1676
1636
|
*
|
1677
1637
|
* Returns:
|
1678
1638
|
* dest if specified, a new mat3 otherwise
|
1679
|
-
|
1639
|
+
**/
|
1680
1640
|
quat4.toMat3 = function(quat, dest) {
|
1681
1641
|
if(!dest) { dest = mat3.create(); }
|
1682
1642
|
|
@@ -1713,17 +1673,16 @@ quat4.toMat3 = function(quat, dest) {
|
|
1713
1673
|
return dest;
|
1714
1674
|
}
|
1715
1675
|
|
1716
|
-
|
1717
|
-
* quat4.toMat4
|
1718
|
-
*
|
1676
|
+
/**
|
1677
|
+
* quat4.toMat4(quat[, dest]) -> mat4
|
1678
|
+
* - quat (quat4) : quat4 to create matrix from
|
1679
|
+
* - dest (mat4) : optional mat4 receiving calculated values. If not specified, a new mat4 is created.
|
1719
1680
|
*
|
1720
|
-
*
|
1721
|
-
* quat - quat4 to create matrix from
|
1722
|
-
* dest - Optional, mat4 receiving operation result
|
1681
|
+
* Calculates a 4x4 matrix from the given quat4
|
1723
1682
|
*
|
1724
1683
|
* Returns:
|
1725
1684
|
* dest if specified, a new mat4 otherwise
|
1726
|
-
|
1685
|
+
**/
|
1727
1686
|
quat4.toMat4 = function(quat, dest) {
|
1728
1687
|
if(!dest) { dest = mat4.create(); }
|
1729
1688
|
|
@@ -1768,19 +1727,18 @@ quat4.toMat4 = function(quat, dest) {
|
|
1768
1727
|
return dest;
|
1769
1728
|
}
|
1770
1729
|
|
1771
|
-
|
1772
|
-
* quat4.slerp
|
1773
|
-
*
|
1730
|
+
/**
|
1731
|
+
* quat4.slerp(quat, quat2, lerp[, dest]) -> quat4
|
1732
|
+
* - quat (quat4) : first quarternion
|
1733
|
+
* - quat2 (quat4) : second quaternion
|
1734
|
+
* - lerp (Number) : interpolation amount between the two inputs
|
1735
|
+
* - dest (quat4) : optional quat4 receiving calculated values. If not specified, result is written to +quat+.
|
1774
1736
|
*
|
1775
|
-
*
|
1776
|
-
* quat - quat4, first quaternion
|
1777
|
-
* quat2 - quat4, second quaternion
|
1778
|
-
* lerp - interpolation amount between the two inputs
|
1779
|
-
* dest - Optional, quat4 receiving operation result. If not specified result is written to quat
|
1737
|
+
* Performs a spherical linear interpolation between two quat4
|
1780
1738
|
*
|
1781
1739
|
* Returns:
|
1782
1740
|
* dest if specified, quat otherwise
|
1783
|
-
|
1741
|
+
**/
|
1784
1742
|
quat4.slerp = function(quat, quat2, lerp, dest) {
|
1785
1743
|
if(!dest) { dest = quat; }
|
1786
1744
|
|
@@ -1799,16 +1757,15 @@ quat4.slerp = function(quat, quat2, lerp, dest) {
|
|
1799
1757
|
return dest;
|
1800
1758
|
}
|
1801
1759
|
|
1802
|
-
|
1803
|
-
* quat4.str
|
1804
|
-
*
|
1760
|
+
/**
|
1761
|
+
* quat4.str(quat) -> String
|
1762
|
+
* - quat (quat4) : quat4 to represent as a string
|
1805
1763
|
*
|
1806
|
-
*
|
1807
|
-
* quat - quat4 to represent as a string
|
1764
|
+
* Returns a string representation of a quaternion
|
1808
1765
|
*
|
1809
1766
|
* Returns:
|
1810
1767
|
* string representation of quat
|
1811
|
-
|
1768
|
+
**/
|
1812
1769
|
quat4.str = function(quat) {
|
1813
1770
|
return '[' + quat[0] + ', ' + quat[1] + ', ' + quat[2] + ', ' + quat[3] + ']';
|
1814
1771
|
}
|