Matrix4
Overview
A 4x4 Matrix.
Constructor
Matrix4( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 )
Initialises the matrix with the supplied row-major values n11..n44, or just creates an identity matrix if no values are passed.
// Simple rig for rotating around 3 axes var m = new THREE.Matrix4(); var m1 = new THREE.Matrix4(); var m2 = new THREE.Matrix4(); var m3 = new THREE.Matrix4(); var alpha = 0; var beta = Math.PI; var gamma = Math.PI/2; m1.makeRotationX( alpha ); m2.makeRotationY( beta ); m3.makeRotationZ( gamma ); m.multiplyMatrices( m1, m2 ); m.multiply( m3 );
Properties
.elements
A column-major list of matrix values.
Methods
.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) this
Sets all fields of this matrix to the supplied row-major values n11..n44.
.identity() this
Resets this matrix to identity.
.copy( m ) this
Copies a matrix m into this matrix.
.copyPosition( m ) this
Copies the translation component of the supplied matrix m into this matrix translation component.
.extractRotation( m ) this
Extracts the rotation of the supplied matrix m into this matrix rotation component.
.lookAt( eye, center, up, ) this
Constructs a rotation matrix, looking from eye towards center with defined up vector.
.multiply( m ) this
Multiplies this matrix by m.
.multiplyMatrices( a, b ) this
Sets this matrix to a x b.
.multiplyToArray( a, b, r ) this
Sets this matrix to a x b and stores the result into the flat array r.
r can be either a regular Array or a TypedArray.
r can be either a regular Array or a TypedArray.
.multiplyScalar( s ) this
Multiplies this matrix by s.
.determinant() Float
Computes determinant of this matrix.
Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
.transpose() this
Transposes this matrix.
.flattenToArray( flat ) Array
Flattens this matrix into supplied flat array.
.flattenToArrayOffset( flat, offset ) Array
Flattens this matrix into supplied flat array starting from offset position in the array.
.setPosition( v ) this
Sets the position component for this matrix from vector v.
.getInverse( m ) this
Sets this matrix to the inverse of matrix m.
Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.
Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.
.makeRotationFromEuler( v, order ) this
v — Rotation vector. order — The order of rotations. Eg. "XYZ".
Sets the rotation submatrix of this matrix to the rotation specified by Euler angles, the rest of the matrix is identity.
Default order is "XYZ".
Default order is "XYZ".
.makeRotationFromQuaternion( q ) this
Sets the rotation submatrix of this matrix to the rotation specified by q. The rest of the matrix is identity.
.scale( v ) this
Multiplies the columns of this matrix by vector v.
.compose( translation, quaternion, scale ) this
Sets this matrix to the transformation composed of translation, quaternion and scale.
.decompose( translation, quaternion, scale ) Array
Decomposes this matrix into the translation, quaternion and scale components.
If parameters are not passed, new instances will be created.
If parameters are not passed, new instances will be created.
.makeTranslation( x, y, z ) this
Sets this matrix as translation transform.
.makeRotationX( theta ) this
theta — Rotation angle in radians.
Sets this matrix as rotation transform around x axis by theta radians.
.makeRotationY( theta ) this
theta — Rotation angle in radians.
Sets this matrix as rotation transform around y axis by theta radians.
.makeRotationZ( theta ) this
theta — Rotation angle in radians.
Sets this matrix as rotation transform around z axis by theta radians.
.makeRotationAxis( axis, theta ) this
axis — Rotation axis, should be normalized. theta — Rotation angle in radians.
Sets this matrix as rotation transform around axis by angle radians.
Based on http://www.gamedev.net/reference/articles/article1199.asp.
Based on http://www.gamedev.net/reference/articles/article1199.asp.
.makeScale( x, y, z ) this
Sets this matrix as scale transform.
.makeFrustum( left, right, bottom, top, near, far ) this
Creates a frustum matrix.
.makePerspective( fov, aspect, near, far ) this
Creates a perspective projection matrix.
.makeOrthographic( left, right, bottom, top, near, far ) this
Creates an orthographic projection matrix.
.clone() Matrix4
Clones this matrix.
.multiplyVector3Array(a) Array
array -- An array in the form [vector1x, vector1y, vector1z, vector2x, vector2y, vector2z, ...]
Multiply (apply) this matrix against every vector3 in the array.
.getMaxScaleOnAxis() Float
Gets the max scale value of the 3 axes.