forked from processing-js/processing-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPMatrix3D.js
More file actions
executable file
·597 lines (574 loc) · 25.1 KB
/
Copy pathPMatrix3D.js
File metadata and controls
executable file
·597 lines (574 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
module.exports = function(options, undef) {
// FIXME: hack
var p = options.p;
/**
* PMatrix3D is a 4x4 matrix implementation. The constructor accepts another PMatrix3D or a list of six or sixteen float elements.
* If no parameters are provided the matrix is set to the identity matrix.
*/
var PMatrix3D = function() {
// When a matrix is created, it is set to an identity matrix
this.reset();
};
/**
* PMatrix3D methods
*/
PMatrix3D.prototype = {
/**
* @member PMatrix2D
* The set() function sets the matrix elements. The function accepts either another PMatrix3D, an array of elements, or a list of six or sixteen floats.
*
* @param {PMatrix3D} matrix the initial matrix to set to
* @param {float[]} elements an array of elements to set this matrix to
* @param {float} m00 the first element of the matrix
* @param {float} m01 the second element of the matrix
* @param {float} m02 the third element of the matrix
* @param {float} m03 the fourth element of the matrix
* @param {float} m10 the fifth element of the matrix
* @param {float} m11 the sixth element of the matrix
* @param {float} m12 the seventh element of the matrix
* @param {float} m13 the eight element of the matrix
* @param {float} m20 the nineth element of the matrix
* @param {float} m21 the tenth element of the matrix
* @param {float} m22 the eleventh element of the matrix
* @param {float} m23 the twelveth element of the matrix
* @param {float} m30 the thirteenth element of the matrix
* @param {float} m31 the fourtheenth element of the matrix
* @param {float} m32 the fivetheenth element of the matrix
* @param {float} m33 the sixteenth element of the matrix
*/
set: function() {
if (arguments.length === 16) {
this.elements = Array.prototype.slice.call(arguments);
} else if (arguments.length === 1 && arguments[0] instanceof PMatrix3D) {
this.elements = arguments[0].array();
} else if (arguments.length === 1 && arguments[0] instanceof Array) {
this.elements = arguments[0].slice();
}
},
/**
* @member PMatrix3D
* The get() function returns a copy of this PMatrix3D.
*
* @return {PMatrix3D} a copy of this PMatrix3D
*/
get: function() {
var outgoing = new PMatrix3D();
outgoing.set(this.elements);
return outgoing;
},
/**
* @member PMatrix3D
* The reset() function sets this PMatrix3D to the identity matrix.
*/
reset: function() {
this.elements = [1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1];
},
/**
* @member PMatrix3D
* The array() function returns a copy of the element values.
* @addon
*
* @return {float[]} returns a copy of the element values
*/
array: function array() {
return this.elements.slice();
},
/**
* @member PMatrix3D
* The translate() function translates this matrix by moving the current coordinates to the location specified by tx, ty, and tz.
*
* @param {float} tx the x-axis coordinate to move to
* @param {float} ty the y-axis coordinate to move to
* @param {float} tz the z-axis coordinate to move to
*/
translate: function(tx, ty, tz) {
if (tz === undef) {
tz = 0;
}
this.elements[3] += tx * this.elements[0] + ty * this.elements[1] + tz * this.elements[2];
this.elements[7] += tx * this.elements[4] + ty * this.elements[5] + tz * this.elements[6];
this.elements[11] += tx * this.elements[8] + ty * this.elements[9] + tz * this.elements[10];
this.elements[15] += tx * this.elements[12] + ty * this.elements[13] + tz * this.elements[14];
},
/**
* @member PMatrix3D
* The transpose() function transpose this matrix.
*/
transpose: function() {
var temp = this.elements[4];
this.elements[4] = this.elements[1];
this.elements[1] = temp;
temp = this.elements[8];
this.elements[8] = this.elements[2];
this.elements[2] = temp;
temp = this.elements[6];
this.elements[6] = this.elements[9];
this.elements[9] = temp;
temp = this.elements[3];
this.elements[3] = this.elements[12];
this.elements[12] = temp;
temp = this.elements[7];
this.elements[7] = this.elements[13];
this.elements[13] = temp;
temp = this.elements[11];
this.elements[11] = this.elements[14];
this.elements[14] = temp;
},
/**
* @member PMatrix3D
* The mult() function multiplied this matrix.
* If two array elements are passed in the function will multiply a two element vector against this matrix.
* If target is null or not length four, a new float array will be returned.
* The values for vec and target can be the same (though that's less efficient).
* If two PVectors are passed in the function multiply the x and y coordinates of a PVector against this matrix.
*
* @param {PVector} source, target the PVectors used to multiply this matrix
* @param {float[]} source, target the arrays used to multiply this matrix
*
* @return {PVector|float[]} returns a PVector or an array representing the new matrix
*/
mult: function(source, target) {
var x, y, z, w;
if (source instanceof PVector) {
x = source.x;
y = source.y;
z = source.z;
w = 1;
if (!target) {
target = new PVector();
}
} else if (source instanceof Array) {
x = source[0];
y = source[1];
z = source[2];
w = source[3] || 1;
if ( !target || (target.length !== 3 && target.length !== 4) ) {
target = [0, 0, 0];
}
}
if (target instanceof Array) {
if (target.length === 3) {
target[0] = this.elements[0] * x + this.elements[1] * y + this.elements[2] * z + this.elements[3];
target[1] = this.elements[4] * x + this.elements[5] * y + this.elements[6] * z + this.elements[7];
target[2] = this.elements[8] * x + this.elements[9] * y + this.elements[10] * z + this.elements[11];
} else if (target.length === 4) {
target[0] = this.elements[0] * x + this.elements[1] * y + this.elements[2] * z + this.elements[3] * w;
target[1] = this.elements[4] * x + this.elements[5] * y + this.elements[6] * z + this.elements[7] * w;
target[2] = this.elements[8] * x + this.elements[9] * y + this.elements[10] * z + this.elements[11] * w;
target[3] = this.elements[12] * x + this.elements[13] * y + this.elements[14] * z + this.elements[15] * w;
}
}
if (target instanceof PVector) {
target.x = this.elements[0] * x + this.elements[1] * y + this.elements[2] * z + this.elements[3];
target.y = this.elements[4] * x + this.elements[5] * y + this.elements[6] * z + this.elements[7];
target.z = this.elements[8] * x + this.elements[9] * y + this.elements[10] * z + this.elements[11];
}
return target;
},
/**
* @member PMatrix3D
* The preApply() function applies another matrix to the left of this one. Note that either a PMatrix3D or elements of a matrix can be passed in.
*
* @param {PMatrix3D} matrix the matrix to apply this matrix to
* @param {float} m00 the first element of the matrix
* @param {float} m01 the second element of the matrix
* @param {float} m02 the third element of the matrix
* @param {float} m03 the fourth element of the matrix
* @param {float} m10 the fifth element of the matrix
* @param {float} m11 the sixth element of the matrix
* @param {float} m12 the seventh element of the matrix
* @param {float} m13 the eight element of the matrix
* @param {float} m20 the nineth element of the matrix
* @param {float} m21 the tenth element of the matrix
* @param {float} m22 the eleventh element of the matrix
* @param {float} m23 the twelveth element of the matrix
* @param {float} m30 the thirteenth element of the matrix
* @param {float} m31 the fourtheenth element of the matrix
* @param {float} m32 the fivetheenth element of the matrix
* @param {float} m33 the sixteenth element of the matrix
*/
preApply: function() {
var source;
if (arguments.length === 1 && arguments[0] instanceof PMatrix3D) {
source = arguments[0].array();
} else if (arguments.length === 16) {
source = Array.prototype.slice.call(arguments);
} else if (arguments.length === 1 && arguments[0] instanceof Array) {
source = arguments[0];
}
var result = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
var e = 0;
for (var row = 0; row < 4; row++) {
for (var col = 0; col < 4; col++, e++) {
result[e] += this.elements[col + 0] * source[row * 4 + 0] + this.elements[col + 4] *
source[row * 4 + 1] + this.elements[col + 8] * source[row * 4 + 2] +
this.elements[col + 12] * source[row * 4 + 3];
}
}
this.elements = result.slice();
},
/**
* @member PMatrix3D
* The apply() function multiplies the current matrix by the one specified through the parameters. Note that either a PMatrix3D or a list of floats can be passed in.
*
* @param {PMatrix3D} matrix the matrix to apply this matrix to
* @param {float} m00 the first element of the matrix
* @param {float} m01 the second element of the matrix
* @param {float} m02 the third element of the matrix
* @param {float} m03 the fourth element of the matrix
* @param {float} m10 the fifth element of the matrix
* @param {float} m11 the sixth element of the matrix
* @param {float} m12 the seventh element of the matrix
* @param {float} m13 the eight element of the matrix
* @param {float} m20 the nineth element of the matrix
* @param {float} m21 the tenth element of the matrix
* @param {float} m22 the eleventh element of the matrix
* @param {float} m23 the twelveth element of the matrix
* @param {float} m30 the thirteenth element of the matrix
* @param {float} m31 the fourtheenth element of the matrix
* @param {float} m32 the fivetheenth element of the matrix
* @param {float} m33 the sixteenth element of the matrix
*/
apply: function() {
var source;
if (arguments.length === 1 && arguments[0] instanceof PMatrix3D) {
source = arguments[0].array();
} else if (arguments.length === 16) {
source = Array.prototype.slice.call(arguments);
} else if (arguments.length === 1 && arguments[0] instanceof Array) {
source = arguments[0];
}
var result = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
var e = 0;
for (var row = 0; row < 4; row++) {
for (var col = 0; col < 4; col++, e++) {
result[e] += this.elements[row * 4 + 0] * source[col + 0] + this.elements[row * 4 + 1] *
source[col + 4] + this.elements[row * 4 + 2] * source[col + 8] +
this.elements[row * 4 + 3] * source[col + 12];
}
}
this.elements = result.slice();
},
/**
* @member PMatrix3D
* The rotate() function rotates the matrix.
*
* @param {float} angle the angle of rotation in radiants
*/
rotate: function(angle, v0, v1, v2) {
if (!v1) {
this.rotateZ(angle);
} else {
// TODO should make sure this vector is normalized
var c = Math.cos(angle);
var s = Math.sin(angle);
var t = 1.0 - c;
this.apply((t * v0 * v0) + c,
(t * v0 * v1) - (s * v2),
(t * v0 * v2) + (s * v1),
0,
(t * v0 * v1) + (s * v2),
(t * v1 * v1) + c,
(t * v1 * v2) - (s * v0),
0,
(t * v0 * v2) - (s * v1),
(t * v1 * v2) + (s * v0),
(t * v2 * v2) + c,
0,
0, 0, 0, 1);
}
},
/**
* @member PMatrix3D
* The invApply() function applies the inverted matrix to this matrix.
*
* @param {float} m00 the first element of the matrix
* @param {float} m01 the second element of the matrix
* @param {float} m02 the third element of the matrix
* @param {float} m03 the fourth element of the matrix
* @param {float} m10 the fifth element of the matrix
* @param {float} m11 the sixth element of the matrix
* @param {float} m12 the seventh element of the matrix
* @param {float} m13 the eight element of the matrix
* @param {float} m20 the nineth element of the matrix
* @param {float} m21 the tenth element of the matrix
* @param {float} m22 the eleventh element of the matrix
* @param {float} m23 the twelveth element of the matrix
* @param {float} m30 the thirteenth element of the matrix
* @param {float} m31 the fourtheenth element of the matrix
* @param {float} m32 the fivetheenth element of the matrix
* @param {float} m33 the sixteenth element of the matrix
*
* @return {boolean} returns true if the operation was successful.
*/
invApply: function() {
if (inverseCopy === undef) {
inverseCopy = new PMatrix3D();
}
var a = arguments;
inverseCopy.set(a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8],
a[9], a[10], a[11], a[12], a[13], a[14], a[15]);
if (!inverseCopy.invert()) {
return false;
}
this.preApply(inverseCopy);
return true;
},
/**
* @member PMatrix3D
* The rotateZ() function rotates the matrix.
*
* @param {float} angle the angle of rotation in radiants
*/
rotateX: function(angle) {
var c = Math.cos(angle);
var s = Math.sin(angle);
this.apply([1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1]);
},
/**
* @member PMatrix3D
* The rotateY() function rotates the matrix.
*
* @param {float} angle the angle of rotation in radiants
*/
rotateY: function(angle) {
var c = Math.cos(angle);
var s = Math.sin(angle);
this.apply([c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1]);
},
/**
* @member PMatrix3D
* The rotateZ() function rotates the matrix.
*
* @param {float} angle the angle of rotation in radiants
*/
rotateZ: function(angle) {
var c = Math.cos(angle);
var s = Math.sin(angle);
this.apply([c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
},
/**
* @member PMatrix3D
* The scale() function increases or decreases the size of a matrix by expanding and contracting vertices. When only one parameter is specified scale will occur in all dimensions.
* This is equivalent to a three parameter call.
*
* @param {float} sx the amount to scale on the x-axis
* @param {float} sy the amount to scale on the y-axis
* @param {float} sz the amount to scale on the z-axis
*/
scale: function(sx, sy, sz) {
if (sx && !sy && !sz) {
sy = sz = sx;
} else if (sx && sy && !sz) {
sz = 1;
}
if (sx && sy && sz) {
this.elements[0] *= sx;
this.elements[1] *= sy;
this.elements[2] *= sz;
this.elements[4] *= sx;
this.elements[5] *= sy;
this.elements[6] *= sz;
this.elements[8] *= sx;
this.elements[9] *= sy;
this.elements[10] *= sz;
this.elements[12] *= sx;
this.elements[13] *= sy;
this.elements[14] *= sz;
}
},
/**
* @member PMatrix3D
* The skewX() function skews the matrix along the x-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of skew specified in radians
*/
skewX: function(angle) {
var t = Math.tan(angle);
this.apply(1, t, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
},
/**
* @member PMatrix3D
* The skewY() function skews the matrix along the y-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of skew specified in radians
*/
skewY: function(angle) {
var t = Math.tan(angle);
this.apply(1, 0, 0, 0, t, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
},
/**
* @member PMatrix3D
* The shearX() function shears the matrix along the x-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of shear specified in radians
*/
shearX: function(angle) {
var t = Math.tan(angle);
this.apply(1, t, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
},
/**
* @member PMatrix3D
* The shearY() function shears the matrix along the y-axis the amount specified by the angle parameter.
* Angles should be specified in radians (values from 0 to PI*2) or converted to radians with the <b>radians()</b> function.
*
* @param {float} angle angle of shear specified in radians
*/
shearY: function(angle) {
var t = Math.tan(angle);
this.apply(1, 0, 0, 0, t, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
},
multX: function(x, y, z, w) {
if (!z) {
return this.elements[0] * x + this.elements[1] * y + this.elements[3];
}
if (!w) {
return this.elements[0] * x + this.elements[1] * y + this.elements[2] * z + this.elements[3];
}
return this.elements[0] * x + this.elements[1] * y + this.elements[2] * z + this.elements[3] * w;
},
multY: function(x, y, z, w) {
if (!z) {
return this.elements[4] * x + this.elements[5] * y + this.elements[7];
}
if (!w) {
return this.elements[4] * x + this.elements[5] * y + this.elements[6] * z + this.elements[7];
}
return this.elements[4] * x + this.elements[5] * y + this.elements[6] * z + this.elements[7] * w;
},
multZ: function(x, y, z, w) {
if (!w) {
return this.elements[8] * x + this.elements[9] * y + this.elements[10] * z + this.elements[11];
}
return this.elements[8] * x + this.elements[9] * y + this.elements[10] * z + this.elements[11] * w;
},
multW: function(x, y, z, w) {
if (!w) {
return this.elements[12] * x + this.elements[13] * y + this.elements[14] * z + this.elements[15];
}
return this.elements[12] * x + this.elements[13] * y + this.elements[14] * z + this.elements[15] * w;
},
/**
* @member PMatrix3D
* The invert() function inverts this matrix
*
* @return {boolean} true if successful
*/
invert: function() {
var fA0 = this.elements[0] * this.elements[5] - this.elements[1] * this.elements[4];
var fA1 = this.elements[0] * this.elements[6] - this.elements[2] * this.elements[4];
var fA2 = this.elements[0] * this.elements[7] - this.elements[3] * this.elements[4];
var fA3 = this.elements[1] * this.elements[6] - this.elements[2] * this.elements[5];
var fA4 = this.elements[1] * this.elements[7] - this.elements[3] * this.elements[5];
var fA5 = this.elements[2] * this.elements[7] - this.elements[3] * this.elements[6];
var fB0 = this.elements[8] * this.elements[13] - this.elements[9] * this.elements[12];
var fB1 = this.elements[8] * this.elements[14] - this.elements[10] * this.elements[12];
var fB2 = this.elements[8] * this.elements[15] - this.elements[11] * this.elements[12];
var fB3 = this.elements[9] * this.elements[14] - this.elements[10] * this.elements[13];
var fB4 = this.elements[9] * this.elements[15] - this.elements[11] * this.elements[13];
var fB5 = this.elements[10] * this.elements[15] - this.elements[11] * this.elements[14];
// Determinant
var fDet = fA0 * fB5 - fA1 * fB4 + fA2 * fB3 + fA3 * fB2 - fA4 * fB1 + fA5 * fB0;
// Account for a very small value
// return false if not successful.
if (Math.abs(fDet) <= 1e-9) {
return false;
}
var kInv = [];
kInv[0] = +this.elements[5] * fB5 - this.elements[6] * fB4 + this.elements[7] * fB3;
kInv[4] = -this.elements[4] * fB5 + this.elements[6] * fB2 - this.elements[7] * fB1;
kInv[8] = +this.elements[4] * fB4 - this.elements[5] * fB2 + this.elements[7] * fB0;
kInv[12] = -this.elements[4] * fB3 + this.elements[5] * fB1 - this.elements[6] * fB0;
kInv[1] = -this.elements[1] * fB5 + this.elements[2] * fB4 - this.elements[3] * fB3;
kInv[5] = +this.elements[0] * fB5 - this.elements[2] * fB2 + this.elements[3] * fB1;
kInv[9] = -this.elements[0] * fB4 + this.elements[1] * fB2 - this.elements[3] * fB0;
kInv[13] = +this.elements[0] * fB3 - this.elements[1] * fB1 + this.elements[2] * fB0;
kInv[2] = +this.elements[13] * fA5 - this.elements[14] * fA4 + this.elements[15] * fA3;
kInv[6] = -this.elements[12] * fA5 + this.elements[14] * fA2 - this.elements[15] * fA1;
kInv[10] = +this.elements[12] * fA4 - this.elements[13] * fA2 + this.elements[15] * fA0;
kInv[14] = -this.elements[12] * fA3 + this.elements[13] * fA1 - this.elements[14] * fA0;
kInv[3] = -this.elements[9] * fA5 + this.elements[10] * fA4 - this.elements[11] * fA3;
kInv[7] = +this.elements[8] * fA5 - this.elements[10] * fA2 + this.elements[11] * fA1;
kInv[11] = -this.elements[8] * fA4 + this.elements[9] * fA2 - this.elements[11] * fA0;
kInv[15] = +this.elements[8] * fA3 - this.elements[9] * fA1 + this.elements[10] * fA0;
// Inverse using Determinant
var fInvDet = 1.0 / fDet;
kInv[0] *= fInvDet;
kInv[1] *= fInvDet;
kInv[2] *= fInvDet;
kInv[3] *= fInvDet;
kInv[4] *= fInvDet;
kInv[5] *= fInvDet;
kInv[6] *= fInvDet;
kInv[7] *= fInvDet;
kInv[8] *= fInvDet;
kInv[9] *= fInvDet;
kInv[10] *= fInvDet;
kInv[11] *= fInvDet;
kInv[12] *= fInvDet;
kInv[13] *= fInvDet;
kInv[14] *= fInvDet;
kInv[15] *= fInvDet;
this.elements = kInv.slice();
return true;
},
toString: function() {
var str = "";
for (var i = 0; i < 15; i++) {
str += this.elements[i] + ", ";
}
str += this.elements[15];
return str;
},
/**
* @member PMatrix3D
* The print() function prints out the elements of this matrix
*/
print: function() {
var digits = printMatrixHelper(this.elements);
var output = "" + p.nfs(this.elements[0], digits, 4) + " " + p.nfs(this.elements[1], digits, 4) +
" " + p.nfs(this.elements[2], digits, 4) + " " + p.nfs(this.elements[3], digits, 4) +
"\n" + p.nfs(this.elements[4], digits, 4) + " " + p.nfs(this.elements[5], digits, 4) +
" " + p.nfs(this.elements[6], digits, 4) + " " + p.nfs(this.elements[7], digits, 4) +
"\n" + p.nfs(this.elements[8], digits, 4) + " " + p.nfs(this.elements[9], digits, 4) +
" " + p.nfs(this.elements[10], digits, 4) + " " + p.nfs(this.elements[11], digits, 4) +
"\n" + p.nfs(this.elements[12], digits, 4) + " " + p.nfs(this.elements[13], digits, 4) +
" " + p.nfs(this.elements[14], digits, 4) + " " + p.nfs(this.elements[15], digits, 4) + "\n\n";
p.println(output);
},
invTranslate: function(tx, ty, tz) {
this.preApply(1, 0, 0, -tx, 0, 1, 0, -ty, 0, 0, 1, -tz, 0, 0, 0, 1);
},
invRotateX: function(angle) {
var c = Math.cos(-angle);
var s = Math.sin(-angle);
this.preApply([1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1]);
},
invRotateY: function(angle) {
var c = Math.cos(-angle);
var s = Math.sin(-angle);
this.preApply([c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1]);
},
invRotateZ: function(angle) {
var c = Math.cos(-angle);
var s = Math.sin(-angle);
this.preApply([c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
},
invScale: function(x, y, z) {
this.preApply([1 / x, 0, 0, 0, 0, 1 / y, 0, 0, 0, 0, 1 / z, 0, 0, 0, 0, 1]);
}
};
return PMatrix3D;
};