A column-major list of matrix values.
Read-only flag to check if a given object is of type Matrix.
Read-only flag to check if a given object is of type Matrix4.
Sets this matrix to the transformation composed of position, quaternion and scale.
This instance
The source position
The source quaternion
The source scale
Decomposes this matrix into its position, quaternion and scale components.
Note: Not all matrices are decomposable in this way. For example, if an object has a non-uniformly scaled parent, then the object's world matrix may not be decomposable, and this method may not be appropriate.
This instance.
The output position
The output quaternion
The output vector
Extracts the basis of this matrix into the three axis vectors provided. If this matrix is:
a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p
then the xAxis, yAxis, zAxis will be set to:
xAxis = (a, e, i)
yAxis = (b, f, j)
zAxis = (c, g, k)
This instance.
Creates an orthographic projection matrix.
This insance.
The left coordinate
The right coordinate
The top coordinate
The bottom coordinate
The closest distance.
The distance to horizon
Creates a perspective projection matrix.
This insance.
The left coordinate
The right coordinate
The top coordinate
The bottom coordinate
The closest distance.
The distance to horizon
Sets this matrix as rotation transform around axis by theta radians. This is a somewhat controversial but mathematically sound alternative to rotating via Quaternions. See the discussion here
This instance
Rotation axis, should be normalized.
Rotation angle in radians.
Sets the rotation component (the upper left 3x3 matrix) of this matrix to the rotation specified by the given Euler Angle. The rest of the matrix is set to the identity. Depending on the order of the euler, there are six possible outcomes. See this page for a complete list.
This instance.
The Euler to update from.
Sets the rotation component of this matrix to the rotation specified by q, as outlined here. The rest of the matrix is set to the identity. So, given q = w + xi + yj + zk, the resulting matrix will be:
1-2y²-2z² 2xy-2zw 2xz+2yw 0
2xy+2zw 1-2x²-2z² 2yz-2xw 0
2xz-2yw 2yz+2xw 1-2x²-2y² 0
0 0 0 1
This instance
The source quaternion
Sets this matrix as scale transform:
x, 0, 0, 0,
0, y, 0, 0,
0, 0, z, 0,
0, 0, 0, 1
This instance
the amount to scale in the X axis.
the amount to scale in the Y axis.
the amount to scale in the Z axis.
Sets this matrix as a shear transform:
1, yx, zx, 0,
xy, 1, zy, 0,
xz, yz, 1, 0,
0, 0, 0, 1
xy - the amount to shear X by Y. xz - the amount to shear X by Z. yx - the amount to shear Y by X. yz - the amount to shear Y by Z. zx - the amount to shear Z by X. zy - the amount to shear Z by Y.
This instance
Sets this matrix as a translation transform:
1, 0, 0, x,
0, 1, 0, y,
0, 0, 1, z,
0, 0, 0, 1
This instance.
the amount to translate in the X axis.
the amount to translate in the Y axis.
the amount to translate in the Z axis.
Set the elements of this matrix to the supplied row-major values n11, n12, ... n44.
This instance.
Sets the position component for this matrix from vector v, without affecting the rest of the matrix
a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p
This becomes:
a, b, c, v.x,
e, f, g, v.y,
i, j, k, v.z,
m, n, o, p
This instance.
The position vector.
Sets the position component for this matrix from vector v, without affecting the rest of the matrix
This instance.
The X component of position
The Y component of position
The Z component of position
Writes the elements of this matrix to a array[16] in column-major format.
The new array[16].
Optional
array: number[](optional) array to store the resulting vector in.
Optional
offset: number(optional) offset in the array at which to put the result.
A class representing a 4x4 matrix.
The most common use of a 4x4 matrix in 3D computer graphics is as a Transformation Matrix. For an introduction to transformation matrices as used in WebGL, check out this tutorial. This allows a Vector3 representing a point in 3D space to undergo transformations such as translation, rotation, shear, scale, reflection, orthogonal or perspective projection and so on, by being multiplied by the matrix. This is known as applying the matrix to the vector.
A Note on Row-Major and Column-Major Ordering The set() method takes arguments in row-major order, while internally they are stored in the elements array in column-major order. This means that calling
will result in the elements array containing:
and internally all calculations are performed using column-major ordering. However, as the actual ordering makes no difference mathematically and most people are used to thinking about matrices in row-major order, the three.js documentation shows matrices in row-major order. Just bear in mind that if you are reading the source code, you'll have to take the transpose of any matrices outlined here to make sense of the calculations.
Extracting position, rotation and scale There are several options available for extracting position, rotation and scale from a Matrix4. Vector3.setFromMatrixPosition: can be used to extract the translation component. Vector3.setFromMatrixScale: can be used to extract the scale component. Quaternion.setFromRotationMatrix, Euler.setFromRotationMatrix or extractRotation can be used to extract the rotation component from a pure (unscaled) matrix. decompose can be used to extract position, rotation and scale all at once.
Example