Constructor
new Matrix4()
Constructs a new 4x4 matrix.
Members
elements :Array.<number>
A column-major list of matrix values.
- Array.<number>
(readonly) isMatrix4 :boolean
This flag can be used for type testing.
- boolean
- Default Value
- true
Methods
clone() → {Matrix4}
Returns a matrix with copied values from this instance.
A clone of this instance.
- Type:
- Matrix4
compose(position, quaternion, scale) → {Matrix4}
Sets this matrix to the transformation composed of the given position, rotation (Quaternion) and scale.
Name | Type | Description |
---|---|---|
position | Vector3 | The position vector. |
quaternion | Quaternion | The rotation as a Quaternion. |
scale | Vector3 | The scale vector. |
A reference to this matrix.
- Type:
- Matrix4
copy(m) → {Matrix4}
Copies the values of the given matrix to this instance.
Name | Type | Description |
---|---|---|
m | Matrix4 | The matrix to copy. |
A reference to this matrix.
- Type:
- Matrix4
decompose(position, quaternion, scale) → {Matrix4}
Decomposes this matrix into its position, rotation and scale components and provides the result in the given objects. 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.
Name | Type | Description |
---|---|---|
position | Vector3 | The position vector. |
quaternion | Quaternion | The rotation as a Quaternion. |
scale | Vector3 | The scale vector. |
A reference to this matrix.
- Type:
- Matrix4
determinant() → {number}
Computes and returns the determinant of this matrix. Based on the method outlined here.
The determinant.
- Type:
- number
equals(matrix) → {boolean}
Returns true
if this matrix is equal with the given one.
Name | Type | Description |
---|---|---|
matrix | Matrix4 | The matrix to test for equality. |
Whether this matrix is equal with the given one.
- Type:
- boolean
extractBasis(xAxis, yAxis, zAxis) → {Matrix4}
Extracts the basis of this matrix into the three axis vectors provided.
Name | Type | Description |
---|---|---|
xAxis | Vector3 | The basis's x axis. |
yAxis | Vector3 | The basis's y axis. |
zAxis | Vector3 | The basis's z axis. |
A reference to this matrix.
- Type:
- Matrix4
extractRotation(m) → {Matrix4}
Extracts the rotation component of the given matrix into this matrix's rotation component.
Note: This method does not support reflection matrices.
Name | Type | Description |
---|---|---|
m | Matrix4 | The matrix. |
A reference to this matrix.
- Type:
- Matrix4
fromArray(array, offsetopt) → {Matrix4}
Sets the elements of the matrix from the given array.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<number> | The matrix elements in column-major order. | ||
offset | number | <optional> | 0 | Index of the first element in the array. |
A reference to this matrix.
- Type:
- Matrix4
getMaxScaleOnAxis() → {number}
Gets the maximum scale value of the three axes.
The maximum scale.
- Type:
- number
identity() → {Matrix4}
Sets this matrix to the 4x4 identity matrix.
A reference to this matrix.
- Type:
- Matrix4
invert() → {Matrix4}
Inverts this matrix, using the analytic method. You can not invert with a determinant of zero. If you attempt this, the method produces a zero matrix instead.
A reference to this matrix.
- Type:
- Matrix4
isIdentity() → {boolean}
Checks if the matrix is an identity matrix.
- True if the matrix is an identity matrix, false otherwise.
- Type:
- boolean
lerpMatrices(m1, m2, ratio) → {Matrix4}
Linearly interpolates between two matrix4.
- Type:
- Matrix4
lookAtRH(eye, target, up) → {Matrix4}
Constructs a rotation matrix, looking from eye towards center oriented by the up vector.
Name | Type | Description |
---|---|---|
eye | Vector3 | The eye vector. |
target | Vector3 | The target vector. |
up | Vector3 | The up vector. |
A reference to this matrix.
- Type:
- Matrix4
makeBasis(xAxis, yAxis, zAxis) → {Matrix4}
Sets the given basis vectors to this matrix.
Name | Type | Description |
---|---|---|
xAxis | Vector3 | The basis's x axis. |
yAxis | Vector3 | The basis's y axis. |
zAxis | Vector3 | The basis's z axis. |
A reference to this matrix.
- Type:
- Matrix4
makeRotationAxis(axis, angle) → {Matrix4}
Sets this matrix as a rotational transformation around the given axis by the given angle. This is a somewhat controversial but mathematically sound alternative to rotating via Quaternions. See the discussion here.
Name | Type | Description |
---|---|---|
axis | Vector3 | The normalized rotation axis. |
angle | number | The rotation in radians. |
A reference to this matrix.
- Type:
- Matrix4
makeRotationFromEuler(euler) → {Matrix4}
Sets the rotation component (the upper left 3x3 matrix) of this matrix to the rotation specified by the given Euler angles. The rest of the matrix is set to the identity. Depending on the Euler#order, there are six possible outcomes. See this page for a complete list.
Name | Type | Description |
---|---|---|
euler | Euler | The Euler angles. |
A reference to this matrix.
- Type:
- Matrix4
makeRotationFromQuaternion(q) → {Matrix4}
Sets the rotation component of this matrix to the rotation specified by q, as outlined here.
Name | Type | Description |
---|---|---|
q | Quaternion |
- Type:
- Matrix4
makeScale(x, y, z) → {Matrix4}
Sets this matrix as a scale transformation.
Name | Type | Description |
---|---|---|
x | number | The amount to scale in the X axis. |
y | number | The amount to scale in the Y axis. |
z | number | The amount to scale in the Z axis. |
A reference to this matrix.
- Type:
- Matrix4
makeTranslation(x, y, z) → {Matrix4}
Sets this matrix as a translation transform from the given vector.
Name | Type | Description |
---|---|---|
x | number | | The amount to translate in the X axis or alternatively a translation vector. |
y | number | The amount to translate in the Y axis. |
z | number | The amount to translate in the z axis. |
A reference to this matrix.
- Type:
- Matrix4
multiply(m) → {Matrix4}
Post-multiplies this matrix by the given 4x4 matrix.
Name | Type | Description |
---|---|---|
m | Matrix4 | The matrix to multiply with. |
A reference to this matrix.
- Type:
- Matrix4
multiplyMatrices(a, b) → {Matrix4}
Multiples the given 4x4 matrices and stores the result in this matrix.
A reference to this matrix.
- Type:
- Matrix4
premultiply(m) → {Matrix4}
Pre-multiplies this matrix by the given 4x4 matrix.
Name | Type | Description |
---|---|---|
m | Matrix4 | The matrix to multiply with. |
A reference to this matrix.
- Type:
- Matrix4
set(n11opt, n12opt, n13opt, n14opt, n21opt, n22opt, n23opt, n24opt, n31opt, n32opt, n33opt, n34opt, n41opt, n42opt, n43opt, n44opt) → {Matrix4}
Sets the elements of the matrix.The arguments are supposed to be in row-major order.
Name | Type | Attributes | Description |
---|---|---|---|
n11 | number | <optional> | 1-1 matrix element. |
n12 | number | <optional> | 1-2 matrix element. |
n13 | number | <optional> | 1-3 matrix element. |
n14 | number | <optional> | 1-4 matrix element. |
n21 | number | <optional> | 2-1 matrix element. |
n22 | number | <optional> | 2-2 matrix element. |
n23 | number | <optional> | 2-3 matrix element. |
n24 | number | <optional> | 2-4 matrix element. |
n31 | number | <optional> | 3-1 matrix element. |
n32 | number | <optional> | 3-2 matrix element. |
n33 | number | <optional> | 3-3 matrix element. |
n34 | number | <optional> | 3-4 matrix element. |
n41 | number | <optional> | 4-1 matrix element. |
n42 | number | <optional> | 4-2 matrix element. |
n43 | number | <optional> | 4-3 matrix element. |
n44 | number | <optional> | 4-4 matrix element. |
A reference to this matrix.
- Type:
- Matrix4
setFromMatrix3(m) → {Matrix4}
Set the upper 3x3 elements of this matrix to the values of given 3x3 matrix.
Name | Type | Description |
---|---|---|
m | Matrix3 | The 3x3 matrix. |
A reference to this matrix.
- Type:
- Matrix4
setPosition(x, y, z) → {Matrix4}
Sets the position component for this matrix from the given vector, without affecting the rest of the matrix.
Name | Type | Description |
---|---|---|
x | number | | The x component of the vector or alternatively the vector object. |
y | number | The y component of the vector. |
z | number | The z component of the vector. |
A reference to this matrix.
- Type:
- Matrix4
toArray(arrayopt, offsetopt) → {Array.<number>}
Writes the elements of this matrix to the given array. If no array is provided, the method returns a new instance.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | Array.<number> | <optional> | [] | The target array holding the matrix elements in column-major order. |
offset | number | <optional> | 0 | Index of the first element in the array. |
The matrix elements in column-major order.
- Type:
- Array.<number>
transpose() → {Matrix4}
Transposes this matrix in place.
A reference to this matrix.
- Type:
- Matrix4