|
@@ -1,37 +1,41 @@
|
|
|
import { Vector3 } from './Vector3.js';
|
|
|
|
|
|
const _v1 = new Vector3();
|
|
|
-const _m1 = new Matrix4();
|
|
|
+let _m1;
|
|
|
const _zero = new Vector3( 0, 0, 0 );
|
|
|
const _one = new Vector3( 1, 1, 1 );
|
|
|
const _x = new Vector3();
|
|
|
const _y = new Vector3();
|
|
|
const _z = new Vector3();
|
|
|
|
|
|
-function Matrix4() {
|
|
|
+class Matrix4 {
|
|
|
|
|
|
- this.elements = [
|
|
|
+ constructor() {
|
|
|
|
|
|
- 1, 0, 0, 0,
|
|
|
- 0, 1, 0, 0,
|
|
|
- 0, 0, 1, 0,
|
|
|
- 0, 0, 0, 1
|
|
|
+ this.elements = [
|
|
|
|
|
|
- ];
|
|
|
+ 1, 0, 0, 0,
|
|
|
+ 0, 1, 0, 0,
|
|
|
+ 0, 0, 1, 0,
|
|
|
+ 0, 0, 0, 1
|
|
|
+
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ( arguments.length > 0 ) {
|
|
|
|
|
|
- if ( arguments.length > 0 ) {
|
|
|
+ console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
|
|
|
|
|
|
- console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ get isMatrix4() {
|
|
|
|
|
|
-Object.assign( Matrix4.prototype, {
|
|
|
+ return true;
|
|
|
|
|
|
- isMatrix4: true,
|
|
|
+ }
|
|
|
|
|
|
- set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
|
|
|
+ set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -42,9 +46,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- identity: function () {
|
|
|
+ identity() {
|
|
|
|
|
|
this.set(
|
|
|
|
|
@@ -57,15 +61,15 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- clone: function () {
|
|
|
+ clone() {
|
|
|
|
|
|
return new Matrix4().fromArray( this.elements );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copy: function ( m ) {
|
|
|
+ copy( m ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
const me = m.elements;
|
|
@@ -77,9 +81,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- copyPosition: function ( m ) {
|
|
|
+ copyPosition( m ) {
|
|
|
|
|
|
const te = this.elements, me = m.elements;
|
|
|
|
|
@@ -89,9 +93,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- extractBasis: function ( xAxis, yAxis, zAxis ) {
|
|
|
+ extractBasis( xAxis, yAxis, zAxis ) {
|
|
|
|
|
|
xAxis.setFromMatrixColumn( this, 0 );
|
|
|
yAxis.setFromMatrixColumn( this, 1 );
|
|
@@ -99,9 +103,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeBasis: function ( xAxis, yAxis, zAxis ) {
|
|
|
+ makeBasis( xAxis, yAxis, zAxis ) {
|
|
|
|
|
|
this.set(
|
|
|
xAxis.x, yAxis.x, zAxis.x, 0,
|
|
@@ -112,9 +116,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- extractRotation: function ( m ) {
|
|
|
+ extractRotation( m ) {
|
|
|
|
|
|
// this method does not support reflection matrices
|
|
|
|
|
@@ -147,9 +151,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationFromEuler: function ( euler ) {
|
|
|
+ makeRotationFromEuler( euler ) {
|
|
|
|
|
|
if ( ! ( euler && euler.isEuler ) ) {
|
|
|
|
|
@@ -275,15 +279,15 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationFromQuaternion: function ( q ) {
|
|
|
+ makeRotationFromQuaternion( q ) {
|
|
|
|
|
|
return this.compose( _zero, q, _one );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- lookAt: function ( eye, target, up ) {
|
|
|
+ lookAt( eye, target, up ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -328,9 +332,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- multiply: function ( m, n ) {
|
|
|
+ multiply( m, n ) {
|
|
|
|
|
|
if ( n !== undefined ) {
|
|
|
|
|
@@ -341,15 +345,15 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this.multiplyMatrices( this, m );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- premultiply: function ( m ) {
|
|
|
+ premultiply( m ) {
|
|
|
|
|
|
return this.multiplyMatrices( m, this );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- multiplyMatrices: function ( a, b ) {
|
|
|
+ multiplyMatrices( a, b ) {
|
|
|
|
|
|
const ae = a.elements;
|
|
|
const be = b.elements;
|
|
@@ -387,9 +391,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- multiplyScalar: function ( s ) {
|
|
|
+ multiplyScalar( s ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -400,9 +404,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- determinant: function () {
|
|
|
+ determinant() {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -450,9 +454,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
);
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- transpose: function () {
|
|
|
+ transpose() {
|
|
|
|
|
|
const te = this.elements;
|
|
|
let tmp;
|
|
@@ -467,9 +471,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- setPosition: function ( x, y, z ) {
|
|
|
+ setPosition( x, y, z ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -489,9 +493,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getInverse: function ( m, throwOnDegenerate ) {
|
|
|
+ getInverse( m, throwOnDegenerate ) {
|
|
|
|
|
|
if ( throwOnDegenerate !== undefined ) {
|
|
|
|
|
@@ -541,9 +545,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- scale: function ( v ) {
|
|
|
+ scale( v ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
const x = v.x, y = v.y, z = v.z;
|
|
@@ -555,9 +559,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- getMaxScaleOnAxis: function () {
|
|
|
+ getMaxScaleOnAxis() {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -567,9 +571,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeTranslation: function ( x, y, z ) {
|
|
|
+ makeTranslation( x, y, z ) {
|
|
|
|
|
|
this.set(
|
|
|
|
|
@@ -582,9 +586,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationX: function ( theta ) {
|
|
|
+ makeRotationX( theta ) {
|
|
|
|
|
|
const c = Math.cos( theta ), s = Math.sin( theta );
|
|
|
|
|
@@ -599,9 +603,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationY: function ( theta ) {
|
|
|
+ makeRotationY( theta ) {
|
|
|
|
|
|
const c = Math.cos( theta ), s = Math.sin( theta );
|
|
|
|
|
@@ -616,9 +620,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationZ: function ( theta ) {
|
|
|
+ makeRotationZ( theta ) {
|
|
|
|
|
|
const c = Math.cos( theta ), s = Math.sin( theta );
|
|
|
|
|
@@ -633,9 +637,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeRotationAxis: function ( axis, angle ) {
|
|
|
+ makeRotationAxis( axis, angle ) {
|
|
|
|
|
|
// Based on http://www.gamedev.net/reference/articles/article1199.asp
|
|
|
|
|
@@ -654,11 +658,11 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
);
|
|
|
|
|
|
- return this;
|
|
|
+ return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeScale: function ( x, y, z ) {
|
|
|
+ makeScale( x, y, z ) {
|
|
|
|
|
|
this.set(
|
|
|
|
|
@@ -671,9 +675,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeShear: function ( x, y, z ) {
|
|
|
+ makeShear( x, y, z ) {
|
|
|
|
|
|
this.set(
|
|
|
|
|
@@ -686,9 +690,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- compose: function ( position, quaternion, scale ) {
|
|
|
+ compose( position, quaternion, scale ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -722,9 +726,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- decompose: function ( position, quaternion, scale ) {
|
|
|
+ decompose( position, quaternion, scale ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
|
|
@@ -767,9 +771,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makePerspective: function ( left, right, top, bottom, near, far ) {
|
|
|
+ makePerspective( left, right, top, bottom, near, far ) {
|
|
|
|
|
|
if ( far === undefined ) {
|
|
|
|
|
@@ -793,9 +797,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- makeOrthographic: function ( left, right, top, bottom, near, far ) {
|
|
|
+ makeOrthographic( left, right, top, bottom, near, far ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
const w = 1.0 / ( right - left );
|
|
@@ -813,9 +817,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- equals: function ( matrix ) {
|
|
|
+ equals( matrix ) {
|
|
|
|
|
|
const te = this.elements;
|
|
|
const me = matrix.elements;
|
|
@@ -828,9 +832,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- fromArray: function ( array, offset ) {
|
|
|
+ fromArray( array, offset ) {
|
|
|
|
|
|
if ( offset === undefined ) offset = 0;
|
|
|
|
|
@@ -842,9 +846,9 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
return this;
|
|
|
|
|
|
- },
|
|
|
+ }
|
|
|
|
|
|
- toArray: function ( array, offset ) {
|
|
|
+ toArray( array, offset ) {
|
|
|
|
|
|
if ( array === undefined ) array = [];
|
|
|
if ( offset === undefined ) offset = 0;
|
|
@@ -875,7 +879,8 @@ Object.assign( Matrix4.prototype, {
|
|
|
|
|
|
}
|
|
|
|
|
|
-} );
|
|
|
+}
|
|
|
|
|
|
+_m1 = new Matrix4();
|
|
|
|
|
|
export { Matrix4 };
|