1 | import { Vector3 } from './Vector3.js';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function Matrix4() {
|
17 |
|
18 | this.elements = [
|
19 |
|
20 | 1, 0, 0, 0,
|
21 | 0, 1, 0, 0,
|
22 | 0, 0, 1, 0,
|
23 | 0, 0, 0, 1
|
24 |
|
25 | ];
|
26 |
|
27 | if ( arguments.length > 0 ) {
|
28 |
|
29 | console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
|
30 |
|
31 | }
|
32 |
|
33 | }
|
34 |
|
35 | Object.assign( Matrix4.prototype, {
|
36 |
|
37 | isMatrix4: true,
|
38 |
|
39 | set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
|
40 |
|
41 | var te = this.elements;
|
42 |
|
43 | te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
|
44 | te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
|
45 | te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
|
46 | te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
|
47 |
|
48 | return this;
|
49 |
|
50 | },
|
51 |
|
52 | identity: function () {
|
53 |
|
54 | this.set(
|
55 |
|
56 | 1, 0, 0, 0,
|
57 | 0, 1, 0, 0,
|
58 | 0, 0, 1, 0,
|
59 | 0, 0, 0, 1
|
60 |
|
61 | );
|
62 |
|
63 | return this;
|
64 |
|
65 | },
|
66 |
|
67 | clone: function () {
|
68 |
|
69 | return new Matrix4().fromArray( this.elements );
|
70 |
|
71 | },
|
72 |
|
73 | copy: function ( m ) {
|
74 |
|
75 | var te = this.elements;
|
76 | var me = m.elements;
|
77 |
|
78 | te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
|
79 | te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
|
80 | te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
|
81 | te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
|
82 |
|
83 | return this;
|
84 |
|
85 | },
|
86 |
|
87 | copyPosition: function ( m ) {
|
88 |
|
89 | var te = this.elements, me = m.elements;
|
90 |
|
91 | te[ 12 ] = me[ 12 ];
|
92 | te[ 13 ] = me[ 13 ];
|
93 | te[ 14 ] = me[ 14 ];
|
94 |
|
95 | return this;
|
96 |
|
97 | },
|
98 |
|
99 | extractBasis: function ( xAxis, yAxis, zAxis ) {
|
100 |
|
101 | xAxis.setFromMatrixColumn( this, 0 );
|
102 | yAxis.setFromMatrixColumn( this, 1 );
|
103 | zAxis.setFromMatrixColumn( this, 2 );
|
104 |
|
105 | return this;
|
106 |
|
107 | },
|
108 |
|
109 | makeBasis: function ( xAxis, yAxis, zAxis ) {
|
110 |
|
111 | this.set(
|
112 | xAxis.x, yAxis.x, zAxis.x, 0,
|
113 | xAxis.y, yAxis.y, zAxis.y, 0,
|
114 | xAxis.z, yAxis.z, zAxis.z, 0,
|
115 | 0, 0, 0, 1
|
116 | );
|
117 |
|
118 | return this;
|
119 |
|
120 | },
|
121 |
|
122 | extractRotation: function () {
|
123 |
|
124 | var v1 = new Vector3();
|
125 |
|
126 | return function extractRotation( m ) {
|
127 |
|
128 | var te = this.elements;
|
129 | var me = m.elements;
|
130 |
|
131 | var scaleX = 1 / v1.setFromMatrixColumn( m, 0 ).length();
|
132 | var scaleY = 1 / v1.setFromMatrixColumn( m, 1 ).length();
|
133 | var scaleZ = 1 / v1.setFromMatrixColumn( m, 2 ).length();
|
134 |
|
135 | te[ 0 ] = me[ 0 ] * scaleX;
|
136 | te[ 1 ] = me[ 1 ] * scaleX;
|
137 | te[ 2 ] = me[ 2 ] * scaleX;
|
138 |
|
139 | te[ 4 ] = me[ 4 ] * scaleY;
|
140 | te[ 5 ] = me[ 5 ] * scaleY;
|
141 | te[ 6 ] = me[ 6 ] * scaleY;
|
142 |
|
143 | te[ 8 ] = me[ 8 ] * scaleZ;
|
144 | te[ 9 ] = me[ 9 ] * scaleZ;
|
145 | te[ 10 ] = me[ 10 ] * scaleZ;
|
146 |
|
147 | return this;
|
148 |
|
149 | };
|
150 |
|
151 | }(),
|
152 |
|
153 | makeRotationFromEuler: function ( euler ) {
|
154 |
|
155 | if ( ! ( euler && euler.isEuler ) ) {
|
156 |
|
157 | console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
|
158 |
|
159 | }
|
160 |
|
161 | var te = this.elements;
|
162 |
|
163 | var x = euler.x, y = euler.y, z = euler.z;
|
164 | var a = Math.cos( x ), b = Math.sin( x );
|
165 | var c = Math.cos( y ), d = Math.sin( y );
|
166 | var e = Math.cos( z ), f = Math.sin( z );
|
167 |
|
168 | if ( euler.order === 'XYZ' ) {
|
169 |
|
170 | var ae = a * e, af = a * f, be = b * e, bf = b * f;
|
171 |
|
172 | te[ 0 ] = c * e;
|
173 | te[ 4 ] = - c * f;
|
174 | te[ 8 ] = d;
|
175 |
|
176 | te[ 1 ] = af + be * d;
|
177 | te[ 5 ] = ae - bf * d;
|
178 | te[ 9 ] = - b * c;
|
179 |
|
180 | te[ 2 ] = bf - ae * d;
|
181 | te[ 6 ] = be + af * d;
|
182 | te[ 10 ] = a * c;
|
183 |
|
184 | } else if ( euler.order === 'YXZ' ) {
|
185 |
|
186 | var ce = c * e, cf = c * f, de = d * e, df = d * f;
|
187 |
|
188 | te[ 0 ] = ce + df * b;
|
189 | te[ 4 ] = de * b - cf;
|
190 | te[ 8 ] = a * d;
|
191 |
|
192 | te[ 1 ] = a * f;
|
193 | te[ 5 ] = a * e;
|
194 | te[ 9 ] = - b;
|
195 |
|
196 | te[ 2 ] = cf * b - de;
|
197 | te[ 6 ] = df + ce * b;
|
198 | te[ 10 ] = a * c;
|
199 |
|
200 | } else if ( euler.order === 'ZXY' ) {
|
201 |
|
202 | var ce = c * e, cf = c * f, de = d * e, df = d * f;
|
203 |
|
204 | te[ 0 ] = ce - df * b;
|
205 | te[ 4 ] = - a * f;
|
206 | te[ 8 ] = de + cf * b;
|
207 |
|
208 | te[ 1 ] = cf + de * b;
|
209 | te[ 5 ] = a * e;
|
210 | te[ 9 ] = df - ce * b;
|
211 |
|
212 | te[ 2 ] = - a * d;
|
213 | te[ 6 ] = b;
|
214 | te[ 10 ] = a * c;
|
215 |
|
216 | } else if ( euler.order === 'ZYX' ) {
|
217 |
|
218 | var ae = a * e, af = a * f, be = b * e, bf = b * f;
|
219 |
|
220 | te[ 0 ] = c * e;
|
221 | te[ 4 ] = be * d - af;
|
222 | te[ 8 ] = ae * d + bf;
|
223 |
|
224 | te[ 1 ] = c * f;
|
225 | te[ 5 ] = bf * d + ae;
|
226 | te[ 9 ] = af * d - be;
|
227 |
|
228 | te[ 2 ] = - d;
|
229 | te[ 6 ] = b * c;
|
230 | te[ 10 ] = a * c;
|
231 |
|
232 | } else if ( euler.order === 'YZX' ) {
|
233 |
|
234 | var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
235 |
|
236 | te[ 0 ] = c * e;
|
237 | te[ 4 ] = bd - ac * f;
|
238 | te[ 8 ] = bc * f + ad;
|
239 |
|
240 | te[ 1 ] = f;
|
241 | te[ 5 ] = a * e;
|
242 | te[ 9 ] = - b * e;
|
243 |
|
244 | te[ 2 ] = - d * e;
|
245 | te[ 6 ] = ad * f + bc;
|
246 | te[ 10 ] = ac - bd * f;
|
247 |
|
248 | } else if ( euler.order === 'XZY' ) {
|
249 |
|
250 | var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
|
251 |
|
252 | te[ 0 ] = c * e;
|
253 | te[ 4 ] = - f;
|
254 | te[ 8 ] = d * e;
|
255 |
|
256 | te[ 1 ] = ac * f + bd;
|
257 | te[ 5 ] = a * e;
|
258 | te[ 9 ] = ad * f - bc;
|
259 |
|
260 | te[ 2 ] = bc * f - ad;
|
261 | te[ 6 ] = b * e;
|
262 | te[ 10 ] = bd * f + ac;
|
263 |
|
264 | }
|
265 |
|
266 |
|
267 | te[ 3 ] = 0;
|
268 | te[ 7 ] = 0;
|
269 | te[ 11 ] = 0;
|
270 |
|
271 |
|
272 | te[ 12 ] = 0;
|
273 | te[ 13 ] = 0;
|
274 | te[ 14 ] = 0;
|
275 | te[ 15 ] = 1;
|
276 |
|
277 | return this;
|
278 |
|
279 | },
|
280 |
|
281 | makeRotationFromQuaternion: function ( q ) {
|
282 |
|
283 | var te = this.elements;
|
284 |
|
285 | var x = q._x, y = q._y, z = q._z, w = q._w;
|
286 | var x2 = x + x, y2 = y + y, z2 = z + z;
|
287 | var xx = x * x2, xy = x * y2, xz = x * z2;
|
288 | var yy = y * y2, yz = y * z2, zz = z * z2;
|
289 | var wx = w * x2, wy = w * y2, wz = w * z2;
|
290 |
|
291 | te[ 0 ] = 1 - ( yy + zz );
|
292 | te[ 4 ] = xy - wz;
|
293 | te[ 8 ] = xz + wy;
|
294 |
|
295 | te[ 1 ] = xy + wz;
|
296 | te[ 5 ] = 1 - ( xx + zz );
|
297 | te[ 9 ] = yz - wx;
|
298 |
|
299 | te[ 2 ] = xz - wy;
|
300 | te[ 6 ] = yz + wx;
|
301 | te[ 10 ] = 1 - ( xx + yy );
|
302 |
|
303 |
|
304 | te[ 3 ] = 0;
|
305 | te[ 7 ] = 0;
|
306 | te[ 11 ] = 0;
|
307 |
|
308 |
|
309 | te[ 12 ] = 0;
|
310 | te[ 13 ] = 0;
|
311 | te[ 14 ] = 0;
|
312 | te[ 15 ] = 1;
|
313 |
|
314 | return this;
|
315 |
|
316 | },
|
317 |
|
318 | lookAt: function () {
|
319 |
|
320 | var x = new Vector3();
|
321 | var y = new Vector3();
|
322 | var z = new Vector3();
|
323 |
|
324 | return function lookAt( eye, target, up ) {
|
325 |
|
326 | var te = this.elements;
|
327 |
|
328 | z.subVectors( eye, target );
|
329 |
|
330 | if ( z.lengthSq() === 0 ) {
|
331 |
|
332 |
|
333 |
|
334 | z.z = 1;
|
335 |
|
336 | }
|
337 |
|
338 | z.normalize();
|
339 | x.crossVectors( up, z );
|
340 |
|
341 | if ( x.lengthSq() === 0 ) {
|
342 |
|
343 |
|
344 |
|
345 | if ( Math.abs( up.z ) === 1 ) {
|
346 |
|
347 | z.x += 0.0001;
|
348 |
|
349 | } else {
|
350 |
|
351 | z.z += 0.0001;
|
352 |
|
353 | }
|
354 |
|
355 | z.normalize();
|
356 | x.crossVectors( up, z );
|
357 |
|
358 | }
|
359 |
|
360 | x.normalize();
|
361 | y.crossVectors( z, x );
|
362 |
|
363 | te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
|
364 | te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
|
365 | te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
|
366 |
|
367 | return this;
|
368 |
|
369 | };
|
370 |
|
371 | }(),
|
372 |
|
373 | multiply: function ( m, n ) {
|
374 |
|
375 | if ( n !== undefined ) {
|
376 |
|
377 | console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
|
378 | return this.multiplyMatrices( m, n );
|
379 |
|
380 | }
|
381 |
|
382 | return this.multiplyMatrices( this, m );
|
383 |
|
384 | },
|
385 |
|
386 | premultiply: function ( m ) {
|
387 |
|
388 | return this.multiplyMatrices( m, this );
|
389 |
|
390 | },
|
391 |
|
392 | multiplyMatrices: function ( a, b ) {
|
393 |
|
394 | var ae = a.elements;
|
395 | var be = b.elements;
|
396 | var te = this.elements;
|
397 |
|
398 | var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
|
399 | var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
|
400 | var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
|
401 | var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
|
402 |
|
403 | var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
|
404 | var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
|
405 | var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
|
406 | var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
|
407 |
|
408 | te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
|
409 | te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
|
410 | te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
|
411 | te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
|
412 |
|
413 | te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
|
414 | te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
|
415 | te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
|
416 | te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
|
417 |
|
418 | te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
|
419 | te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
|
420 | te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
|
421 | te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
|
422 |
|
423 | te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
|
424 | te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
|
425 | te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
|
426 | te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
|
427 |
|
428 | return this;
|
429 |
|
430 | },
|
431 |
|
432 | multiplyScalar: function ( s ) {
|
433 |
|
434 | var te = this.elements;
|
435 |
|
436 | te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
|
437 | te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
|
438 | te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
|
439 | te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
|
440 |
|
441 | return this;
|
442 |
|
443 | },
|
444 |
|
445 | applyToBufferAttribute: function () {
|
446 |
|
447 | var v1 = new Vector3();
|
448 |
|
449 | return function applyToBufferAttribute( attribute ) {
|
450 |
|
451 | for ( var i = 0, l = attribute.count; i < l; i ++ ) {
|
452 |
|
453 | v1.x = attribute.getX( i );
|
454 | v1.y = attribute.getY( i );
|
455 | v1.z = attribute.getZ( i );
|
456 |
|
457 | v1.applyMatrix4( this );
|
458 |
|
459 | attribute.setXYZ( i, v1.x, v1.y, v1.z );
|
460 |
|
461 | }
|
462 |
|
463 | return attribute;
|
464 |
|
465 | };
|
466 |
|
467 | }(),
|
468 |
|
469 | determinant: function () {
|
470 |
|
471 | var te = this.elements;
|
472 |
|
473 | var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
|
474 | var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
|
475 | var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
|
476 | var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
|
477 |
|
478 |
|
479 |
|
480 |
|
481 | return (
|
482 | n41 * (
|
483 | + n14 * n23 * n32
|
484 | - n13 * n24 * n32
|
485 | - n14 * n22 * n33
|
486 | + n12 * n24 * n33
|
487 | + n13 * n22 * n34
|
488 | - n12 * n23 * n34
|
489 | ) +
|
490 | n42 * (
|
491 | + n11 * n23 * n34
|
492 | - n11 * n24 * n33
|
493 | + n14 * n21 * n33
|
494 | - n13 * n21 * n34
|
495 | + n13 * n24 * n31
|
496 | - n14 * n23 * n31
|
497 | ) +
|
498 | n43 * (
|
499 | + n11 * n24 * n32
|
500 | - n11 * n22 * n34
|
501 | - n14 * n21 * n32
|
502 | + n12 * n21 * n34
|
503 | + n14 * n22 * n31
|
504 | - n12 * n24 * n31
|
505 | ) +
|
506 | n44 * (
|
507 | - n13 * n22 * n31
|
508 | - n11 * n23 * n32
|
509 | + n11 * n22 * n33
|
510 | + n13 * n21 * n32
|
511 | - n12 * n21 * n33
|
512 | + n12 * n23 * n31
|
513 | )
|
514 |
|
515 | );
|
516 |
|
517 | },
|
518 |
|
519 | transpose: function () {
|
520 |
|
521 | var te = this.elements;
|
522 | var tmp;
|
523 |
|
524 | tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
|
525 | tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
|
526 | tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
|
527 |
|
528 | tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
|
529 | tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
|
530 | tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
|
531 |
|
532 | return this;
|
533 |
|
534 | },
|
535 |
|
536 | setPosition: function ( v ) {
|
537 |
|
538 | var te = this.elements;
|
539 |
|
540 | te[ 12 ] = v.x;
|
541 | te[ 13 ] = v.y;
|
542 | te[ 14 ] = v.z;
|
543 |
|
544 | return this;
|
545 |
|
546 | },
|
547 |
|
548 | getInverse: function ( m, throwOnDegenerate ) {
|
549 |
|
550 |
|
551 | var te = this.elements,
|
552 | me = m.elements,
|
553 |
|
554 | n11 = me[ 0 ], n21 = me[ 1 ], n31 = me[ 2 ], n41 = me[ 3 ],
|
555 | n12 = me[ 4 ], n22 = me[ 5 ], n32 = me[ 6 ], n42 = me[ 7 ],
|
556 | n13 = me[ 8 ], n23 = me[ 9 ], n33 = me[ 10 ], n43 = me[ 11 ],
|
557 | n14 = me[ 12 ], n24 = me[ 13 ], n34 = me[ 14 ], n44 = me[ 15 ],
|
558 |
|
559 | t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
|
560 | t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
|
561 | t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
|
562 | t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
|
563 |
|
564 | var det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
|
565 |
|
566 | if ( det === 0 ) {
|
567 |
|
568 | var msg = "THREE.Matrix4: .getInverse() can't invert matrix, determinant is 0";
|
569 |
|
570 | if ( throwOnDegenerate === true ) {
|
571 |
|
572 | throw new Error( msg );
|
573 |
|
574 | } else {
|
575 |
|
576 | console.warn( msg );
|
577 |
|
578 | }
|
579 |
|
580 | return this.identity();
|
581 |
|
582 | }
|
583 |
|
584 | var detInv = 1 / det;
|
585 |
|
586 | te[ 0 ] = t11 * detInv;
|
587 | te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
|
588 | te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
|
589 | te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
|
590 |
|
591 | te[ 4 ] = t12 * detInv;
|
592 | te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
|
593 | te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
|
594 | te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
|
595 |
|
596 | te[ 8 ] = t13 * detInv;
|
597 | te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
|
598 | te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
|
599 | te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
|
600 |
|
601 | te[ 12 ] = t14 * detInv;
|
602 | te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
|
603 | te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
|
604 | te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
|
605 |
|
606 | return this;
|
607 |
|
608 | },
|
609 |
|
610 | scale: function ( v ) {
|
611 |
|
612 | var te = this.elements;
|
613 | var x = v.x, y = v.y, z = v.z;
|
614 |
|
615 | te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
|
616 | te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
|
617 | te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
|
618 | te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
|
619 |
|
620 | return this;
|
621 |
|
622 | },
|
623 |
|
624 | getMaxScaleOnAxis: function () {
|
625 |
|
626 | var te = this.elements;
|
627 |
|
628 | var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
|
629 | var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
|
630 | var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
|
631 |
|
632 | return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
|
633 |
|
634 | },
|
635 |
|
636 | makeTranslation: function ( x, y, z ) {
|
637 |
|
638 | this.set(
|
639 |
|
640 | 1, 0, 0, x,
|
641 | 0, 1, 0, y,
|
642 | 0, 0, 1, z,
|
643 | 0, 0, 0, 1
|
644 |
|
645 | );
|
646 |
|
647 | return this;
|
648 |
|
649 | },
|
650 |
|
651 | makeRotationX: function ( theta ) {
|
652 |
|
653 | var c = Math.cos( theta ), s = Math.sin( theta );
|
654 |
|
655 | this.set(
|
656 |
|
657 | 1, 0, 0, 0,
|
658 | 0, c, - s, 0,
|
659 | 0, s, c, 0,
|
660 | 0, 0, 0, 1
|
661 |
|
662 | );
|
663 |
|
664 | return this;
|
665 |
|
666 | },
|
667 |
|
668 | makeRotationY: function ( theta ) {
|
669 |
|
670 | var c = Math.cos( theta ), s = Math.sin( theta );
|
671 |
|
672 | this.set(
|
673 |
|
674 | c, 0, s, 0,
|
675 | 0, 1, 0, 0,
|
676 | - s, 0, c, 0,
|
677 | 0, 0, 0, 1
|
678 |
|
679 | );
|
680 |
|
681 | return this;
|
682 |
|
683 | },
|
684 |
|
685 | makeRotationZ: function ( theta ) {
|
686 |
|
687 | var c = Math.cos( theta ), s = Math.sin( theta );
|
688 |
|
689 | this.set(
|
690 |
|
691 | c, - s, 0, 0,
|
692 | s, c, 0, 0,
|
693 | 0, 0, 1, 0,
|
694 | 0, 0, 0, 1
|
695 |
|
696 | );
|
697 |
|
698 | return this;
|
699 |
|
700 | },
|
701 |
|
702 | makeRotationAxis: function ( axis, angle ) {
|
703 |
|
704 |
|
705 |
|
706 | var c = Math.cos( angle );
|
707 | var s = Math.sin( angle );
|
708 | var t = 1 - c;
|
709 | var x = axis.x, y = axis.y, z = axis.z;
|
710 | var tx = t * x, ty = t * y;
|
711 |
|
712 | this.set(
|
713 |
|
714 | tx * x + c, tx * y - s * z, tx * z + s * y, 0,
|
715 | tx * y + s * z, ty * y + c, ty * z - s * x, 0,
|
716 | tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
|
717 | 0, 0, 0, 1
|
718 |
|
719 | );
|
720 |
|
721 | return this;
|
722 |
|
723 | },
|
724 |
|
725 | makeScale: function ( x, y, z ) {
|
726 |
|
727 | this.set(
|
728 |
|
729 | x, 0, 0, 0,
|
730 | 0, y, 0, 0,
|
731 | 0, 0, z, 0,
|
732 | 0, 0, 0, 1
|
733 |
|
734 | );
|
735 |
|
736 | return this;
|
737 |
|
738 | },
|
739 |
|
740 | makeShear: function ( x, y, z ) {
|
741 |
|
742 | this.set(
|
743 |
|
744 | 1, y, z, 0,
|
745 | x, 1, z, 0,
|
746 | x, y, 1, 0,
|
747 | 0, 0, 0, 1
|
748 |
|
749 | );
|
750 |
|
751 | return this;
|
752 |
|
753 | },
|
754 |
|
755 | compose: function ( position, quaternion, scale ) {
|
756 |
|
757 | this.makeRotationFromQuaternion( quaternion );
|
758 | this.scale( scale );
|
759 | this.setPosition( position );
|
760 |
|
761 | return this;
|
762 |
|
763 | },
|
764 |
|
765 | decompose: function () {
|
766 |
|
767 | var vector = new Vector3();
|
768 | var matrix = new Matrix4();
|
769 |
|
770 | return function decompose( position, quaternion, scale ) {
|
771 |
|
772 | var te = this.elements;
|
773 |
|
774 | var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
|
775 | var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
|
776 | var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
|
777 |
|
778 |
|
779 | var det = this.determinant();
|
780 | if ( det < 0 ) sx = - sx;
|
781 |
|
782 | position.x = te[ 12 ];
|
783 | position.y = te[ 13 ];
|
784 | position.z = te[ 14 ];
|
785 |
|
786 |
|
787 | matrix.copy( this );
|
788 |
|
789 | var invSX = 1 / sx;
|
790 | var invSY = 1 / sy;
|
791 | var invSZ = 1 / sz;
|
792 |
|
793 | matrix.elements[ 0 ] *= invSX;
|
794 | matrix.elements[ 1 ] *= invSX;
|
795 | matrix.elements[ 2 ] *= invSX;
|
796 |
|
797 | matrix.elements[ 4 ] *= invSY;
|
798 | matrix.elements[ 5 ] *= invSY;
|
799 | matrix.elements[ 6 ] *= invSY;
|
800 |
|
801 | matrix.elements[ 8 ] *= invSZ;
|
802 | matrix.elements[ 9 ] *= invSZ;
|
803 | matrix.elements[ 10 ] *= invSZ;
|
804 |
|
805 | quaternion.setFromRotationMatrix( matrix );
|
806 |
|
807 | scale.x = sx;
|
808 | scale.y = sy;
|
809 | scale.z = sz;
|
810 |
|
811 | return this;
|
812 |
|
813 | };
|
814 |
|
815 | }(),
|
816 |
|
817 | makePerspective: function ( left, right, top, bottom, near, far ) {
|
818 |
|
819 | if ( far === undefined ) {
|
820 |
|
821 | console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
|
822 |
|
823 | }
|
824 |
|
825 | var te = this.elements;
|
826 | var x = 2 * near / ( right - left );
|
827 | var y = 2 * near / ( top - bottom );
|
828 |
|
829 | var a = ( right + left ) / ( right - left );
|
830 | var b = ( top + bottom ) / ( top - bottom );
|
831 | var c = - ( far + near ) / ( far - near );
|
832 | var d = - 2 * far * near / ( far - near );
|
833 |
|
834 | te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
|
835 | te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
|
836 | te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
|
837 | te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
|
838 |
|
839 | return this;
|
840 |
|
841 | },
|
842 |
|
843 | makeOrthographic: function ( left, right, top, bottom, near, far ) {
|
844 |
|
845 | var te = this.elements;
|
846 | var w = 1.0 / ( right - left );
|
847 | var h = 1.0 / ( top - bottom );
|
848 | var p = 1.0 / ( far - near );
|
849 |
|
850 | var x = ( right + left ) * w;
|
851 | var y = ( top + bottom ) * h;
|
852 | var z = ( far + near ) * p;
|
853 |
|
854 | te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
|
855 | te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
|
856 | te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
|
857 | te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
|
858 |
|
859 | return this;
|
860 |
|
861 | },
|
862 |
|
863 | equals: function ( matrix ) {
|
864 |
|
865 | var te = this.elements;
|
866 | var me = matrix.elements;
|
867 |
|
868 | for ( var i = 0; i < 16; i ++ ) {
|
869 |
|
870 | if ( te[ i ] !== me[ i ] ) return false;
|
871 |
|
872 | }
|
873 |
|
874 | return true;
|
875 |
|
876 | },
|
877 |
|
878 | fromArray: function ( array, offset ) {
|
879 |
|
880 | if ( offset === undefined ) offset = 0;
|
881 |
|
882 | for ( var i = 0; i < 16; i ++ ) {
|
883 |
|
884 | this.elements[ i ] = array[ i + offset ];
|
885 |
|
886 | }
|
887 |
|
888 | return this;
|
889 |
|
890 | },
|
891 |
|
892 | toArray: function ( array, offset ) {
|
893 |
|
894 | if ( array === undefined ) array = [];
|
895 | if ( offset === undefined ) offset = 0;
|
896 |
|
897 | var te = this.elements;
|
898 |
|
899 | array[ offset ] = te[ 0 ];
|
900 | array[ offset + 1 ] = te[ 1 ];
|
901 | array[ offset + 2 ] = te[ 2 ];
|
902 | array[ offset + 3 ] = te[ 3 ];
|
903 |
|
904 | array[ offset + 4 ] = te[ 4 ];
|
905 | array[ offset + 5 ] = te[ 5 ];
|
906 | array[ offset + 6 ] = te[ 6 ];
|
907 | array[ offset + 7 ] = te[ 7 ];
|
908 |
|
909 | array[ offset + 8 ] = te[ 8 ];
|
910 | array[ offset + 9 ] = te[ 9 ];
|
911 | array[ offset + 10 ] = te[ 10 ];
|
912 | array[ offset + 11 ] = te[ 11 ];
|
913 |
|
914 | array[ offset + 12 ] = te[ 12 ];
|
915 | array[ offset + 13 ] = te[ 13 ];
|
916 | array[ offset + 14 ] = te[ 14 ];
|
917 | array[ offset + 15 ] = te[ 15 ];
|
918 |
|
919 | return array;
|
920 |
|
921 | }
|
922 |
|
923 | } );
|
924 |
|
925 |
|
926 | export { Matrix4 };
|