Constructs a Matrix4 object with a 4x4 identity matrix
Array of 16 numbers representing the elements in the Matrix4
Static ReadonlyIDENTITYStatic field to provide quick access to the identity matrix. (Note: Be careful not to change the value of this field! It is marked readonly, but typescipt do not completely enforce this!)
// Good use of IDENTITY:
const M = gfx.Matrix4();
if (M.equals(gfx.Matrix4.IDENTITY)) {
console.log("We have an identity matrix.")
}
// Dangerous use of IDENTITY!!!!
const M = gfx.Matrix4.IDENTITY; // makes M a reference to gfx.Matrix4.IDENTITY
M.set(3.0, 3, 3); // changes the underlying matrix in gfx.Matrix4.IDENTITY!
// Do this instead:
const M = gfx.Matrix4.makeIdentity(); // create a new identity matrix M
M.set(3.0, 3, 3
Creates a new Matrix4 object with the same values as this Matrix4.
A new Matrix4 object with the same values as this Matrix4.
Sets the matrix to a composition of three basic transformations (this = T * R * S), where scale is applied first, then rotation, then translation.
The position of the Matrix4 object (default Vector3.ZERO)
The rotation of the Matrix4 object (default Quaternion.IDENTITY)
The scale of the Matrix4 object (default Vector3.ONE)
Copy the values of another Matrix4 into this one
The Matrix4 object to copy from
Decomposes the 4x4 transformation matrix into separate translation, rotation, and scale components such that the original matrix can be represented as a combination of transformations in the form T * R * S. The decomposition is straightforward (relatively efficient) if the matrix does not include a negative scale. If the matrix includes a negative scale factor, a slower polar decomposition must be used, and the caller must explicitly set the containsNegScale to true.
Set to true if the matrix includes a negative scale factor.
An array of three elements [translation: Vector3, rotation: Quaternion, scale: Vector3]
Computes the determinant of the Matrix4 object
The determinant of the Matrix4 object
Returns the element at the given row and column in this Matrix4.
The row of the element to return.
The column of the element to return.
The element at the given row and column.
Checks if every element of this Matrix4 is exactly equal to every element of the given Matrix4
The other Matrix3 to compare to
A boolean value indicating if the two matrices are equal
Checks if every element of this Matrix4 is exactly equal (within a small value of epsilon) to every element of the given Matrix4
The other Matrix3 to compare to
A small value of acceptable variance to account for numerical instability
A boolean value indicating if the two matrices are equal
Returns the first three elements of column i as a new Vector3.
The zero-based index of the column (0..3)
A new Vector3
Returns a new object that is the inverse of this Matrix4 object, leaves the original unchanged.
A Matrix4 object that is the inverse of the current Matrix4 object
Gets the rotation quaternion of this Matrix4 object
The Quaternion representing the rotation
Returns the first three elements of row i as a new Vector3.
The zero-based index of the row (0..3)
A new Vector3.
Gets the scale vector of this Matrix4 object
The Vector3 representing the scale vector
Gets the translation vector of this Matrix4 object
The Vector3 representing the translation vector
Transposes the Matrix4 object and returns a new Matrix4 object
A new Matrix4 object which is the transposed version of the current object
Inverts the matix and writes the result back into this matrix.
Sets the Matrix to a view matrix of a camera. The matrix will position the camera at eyePoint and orient it to look directly toward the targetPoint so that the camera's look vector will be (targetPoint - eyePoint). The camera's rotation around the look vector is controlled by the upVector, which only needs to point roughly in the Up direction, i.e., it does not need to be completely perpendicular to the look vector.
A new Matrix4 object for the view matrix of a camera
Multiplies this Matrix4 with another Matrix4 on the right hand side (i.e., this = this * rhs) and sets this Matrix4 to the result.
The Matrix4 to multiply with.
this.mat = this.mat * M1 * M2 * ... * M(n-1): Multiplies this matrix with one or more additional
4x4 matrices.
(Remember, matrix multiplication is not commutitive; so, the order of the matrices is important! The order that transformations are applied to points and vectors is right-to-left. To transform point p into p', as in the equation below, think of M(n-1) as being the first transformation to be applied to p and the current value of this.mat as being the last transformation to be applied in order to produce p'.)
p' = this.mat * M1 * M2 * ... * M(n-1) * p
Multiplies all elements of this Matrix4 object by a scalar
The scalar to multiply by
Multiplies the given Matrix4 with another Matrix4 on the left hand side (i.e., this = lhs * this) and sets this Matrix4 to the result.
The Matrix4 to multiply with.
Sets the element at the given row and column in this Matrix4.
The value to set at the given row and column.
The row of the element to set.
The column of the element to set.
Set the axis angle for this Matrix4 object
The Vector3 representing the axis
The angle to set the axis to
Sets the first three elements of column i using the x, y, z components of the supplied vector.
The zero-based index of the column (0..3)
A vector containing the new values for the column
Set the values of the Matrix4 in column-major order
Column 1, Row 1 value
Column 1, Row 2 value
Column 1, Row 3 value
Column 1, Row 4 value
Column 2, Row 1 value
Column 2, Row 2 value
Column 2, Row 3 value
Column 2, Row 4 value
Column 3, Row 1 value
Column 3, Row 2 value
Column 3, Row 3 value
Column 3, Row 4 value
Column 4, Row 1 value
Column 4, Row 2 value
Column 4, Row 3 value
Column 4, Row 4 value
Sets the matrix to a rotation matrix defined by Euler angles.
The x-axis euler angle
The y-axis euler angle
The z-axis euler angle
The order in which the euler angles should be applied
Sets a frustum projection matrix on this Matrix4 object
The leftmost coordinate
The rightmost coordinate
The bottom coordinate
The top coordinate
The near coordinate
The far coordinate
Sets this Matrix4 to the identity matrix.
Sets an orthographic projection matrix on this Matrix4 object
The leftmost coordinate
The rightmost coordinate
The bottom coordinate
The top coordinate
The near coordinate
The far coordinate
Sets a perspective projection matrix on this Matrix4 object
The field of view angle
The aspect ratio of the view
The near coordinate
The far coordinate
Sets this Matrix4 to a rotation matrix given a Quaternion.
The Quaternion to construct the rotation matrix with.
Sets this Matrix4 to a rotation matrix around the X axis with the given angle in radians.
The angle in radians.
Sets this Matrix4 to a rotation matrix around the Y axis with the given angle in radians.
The angle in radians.
Sets this Matrix4 to a rotation matrix around the Z axis with the given angle in radians.
The angle in radians.
Sets the first three elements of row i using the x, y, z components of the supplied vector.
The zero-based index of the row (0..3)
A vector containing the new values for the row
Set the values of the Matrix4 in row-major order
Column 1, Row 1 value
Column 1, Row 2 value
Column 1, Row 3 value
Column 1, Row 4 value
Column 2, Row 1 value
Column 2, Row 2 value
Column 2, Row 3 value
Column 2, Row 4 value
Column 3, Row 1 value
Column 3, Row 2 value
Column 3, Row 3 value
Column 3, Row 4 value
Column 4, Row 1 value
Column 4, Row 2 value
Column 4, Row 3 value
Column 4, Row 4 value
Set the scale of this Matrix4 object
The Vector3 representing the scale to set
Sets this Matrix4 to a translation matrix given a translation Vector3.
The translation Vector3.
Multiplies point p by this 4x4 transformation matrix and returns the result as a new point. This has the effect of transforming p from the matrix's local coordinate system to its parent coordinate system. The multiplication is done using homogeneous coordinates (p is treated as having a w=1 coordinate).
The original point
A new point transformed by m
Multiplies vector v by this 4x4 transformation matrix and returns the result as a new vector. This has the effect of transforming v from the matrix's local coordinate system to its parent coordinate system. The multiplication is done using homogeneous coordinates (v is treated as having a w=0 coordinate).
The original vector
A new vector transformed by m
StaticcloneStaticcomposeCreates a new Matrix4 object representing the combined transform of position, rotation and scale
The Vector3 object representing the position
The Quaternion object representing the rotation
The Vector3 object representing the scale
A new Matrix4 object representing the combined transform of position, rotation and scale
StaticequalsStaticfromCreates a new Matrix4 object from the given values in column-major order
Element [0,0] in the matrix
Element [1,0] in the matrix
Element [2,0] in the matrix
Element [3,0] in the matrix
Element [0,1] in the matrix
Element [1,1] in the matrix
Element [2,1] in the matrix
Element [3,1] in the matrix
Element [0,2] in the matrix
Element [1,2] in the matrix
Element [2,2] in the matrix
Element [3,2] in the matrix
Element [0,3] in the matrix
Element [1,3] in the matrix
Element [2,3] in the matrix
Element [3,3] in the matrix
A new Matrix4 object created from the given values
StaticfromCreates a new Matrix4 object from the given values in row-major order
Element [0,0] in the matrix
Element [0,1] in the matrix
Element [0,2] in the matrix
Element [0,3] in the matrix
Element [1,0] in the matrix
Element [1,1] in the matrix
Element [1,2] in the matrix
Element [1,3] in the matrix
Element [2,0] in the matrix
Element [2,1] in the matrix
Element [2,2] in the matrix
Element [2,3] in the matrix
Element [3,0] in the matrix
Element [3,1] in the matrix
Element [3,2] in the matrix
Element [3,3] in the matrix
A new Matrix4 object created from the given values
StaticfuzzyChecks if all elements of two Matrix4 objects are equal within a small value of epsilon.
A boolean value indicating if the two matrices are equal
StaticinverseStaticlookCreates a new Matrix4 object for the view matrix of a camera. The matrix will position the camera at eyePoint and orient it to look directly toward the targetPoint so that the camera's look vector will be (targetPoint - eyePoint). The camera's rotation around the look vector is controlled by the upVector, which only needs to point roughly in the Up direction, i.e., it does not need to be completely perpendicular to the look vector.
A new Matrix4 object for the view matrix of a camera
StaticmakeCreates a rotation matrix that will align a reference direction to some new direction. This is similar to a lookAt function but more flexible in that the reference direction does not need to be -Z. The routine can optionally include a second reference direction and new direction. This is interpreted similarly to the Up parameter in a typical lookAt function. (The rotation matrix will always align referenceDir with newDir and it will try to get referenceDir2 to align as closely as possible with newDir2.)
StaticmakeStaticmakeCreates a matrix that represents a right-handed X,Y,Z coordinate frame (an orthonormal basis) where: 1. the vector provided by the reference direction is aligned with the X axis, and optionally 2. the vector provided by a second reference direction is aligned as closely as possible (subject to the requirements of a right-handed, orthonormal basis) with the Y axis. This means the first column of the matrix will contain the normalized x, y, z values of the reference direction and the second and third columns can be interpreted as the directions of the Y and Z axes of the basis.
A 4x4 transformation matrix.
StaticmakeCreates a new Matrix4 object for rotation using Euler angles
The angle of rotation around the x axis
The angle of rotation around the y axis
The angle of rotation around the z axis
The order of the rotations (default is 'YZX')
A new Matrix4 object for rotation using Euler angles
StaticmakeCreate a frustum projection Matrix4
Left coordinate of the viewing volume
Right coordinate of the viewing volume
Bottom coordinate of the viewing volume
Top coordinate of the viewing volume
Near clipping plane of the viewing volume
Far clipping plane of the viewing volume
A Matrix4 representing a frustum projection
StaticmakeCreates a new Matrix4 object with the identity matrix
A new Matrix4 object with the identity matrix
StaticmakeCreate an orthographic projection Matrix4
Left coordinate of the viewing volume
Right coordinate of the viewing volume
Bottom coordinate of the viewing volume
Top coordinate of the viewing volume
Near clipping plane of the viewing volume
Far clipping plane of the viewing volume
A Matrix4 representing an orthographic projection
StaticmakeCreate a perspective projection Matrix4
Field of view of the projection in radians
Aspect ratio of the viewport (width / height)
Near clipping plane of the viewing volume
Far clipping plane of the viewing volume
A Matrix4 representing a perspective projection
StaticmakeCreates a new Matrix4 object for rotation
The Quaternion object representing the rotation vector
A new Matrix4 object for rotation
StaticmakeCreates a new Matrix4 object for rotation around the X axis
The angle of rotation around the X axis
A new Matrix4 object for rotation around the X axis
StaticmakeCreates a new Matrix4 object for rotation around the Y axis
The angle of rotation around the Y axis
A new Matrix4 object for rotation around the Y axis
StaticmakeCreates a new Matrix4 object for rotation around the Z axis
The angle of rotation around the Z axis
A new Matrix4 object for rotation around the Z axis
StaticmakeStaticmakeStaticmultiplyStaticmultiplyMn = M1 * M2 * M3 * ... * M(n-1): Composes (i.e., multiplies) two or more 4x4 matrices together and returns the result in a new matrix.
(Remember, matrix multiplication is not commutitive; so, the order of the matrices is important! The order that transformations are applied to points and vectors is right-to-left. To transform point p into p', as in the equation below, think of M(n-1) as being the first transformation to be applied to p and M1 as being the last transformation to be applied in order to produce p'.)
p' = M1 * M2 * M3 * ... * M(n-1) * p
A new Matrix4 object = m1 * m2 * ...
StatictransformMultiplies point p by a 4x4 transformation matrix and returns the result as a new point. This has the effect of transforming p from m's local coordinate system to m's parent coordinate system. The multiplication is done using homogeneous coordinates (p is treated as having a w=1 coordinate).
A new point transformed by m
StatictransformMultiplies vector v by a 4x4 transformation matrix and returns the result as a new vector. This has the effect of transforming v from m's local coordinate system to m's parent coordinate system. The multiplication is done using homogeneous coordinates (p is treated as having a w=0 coordinate).
A new vector transformed by m
Statictranspose
This class holds a 4x4 transformation matrix. It includes routines for using the matrix to transform points and vectors. It includes routines for constructing many common types of matrices (see make*), for inverting the matrix, and for accessing the underlying 16-elements by row, column.
Most of the functions in the class are defined both as member functions that can be called on a specific instance of Vector3 and as static functions. The static functions return a new result, leaving the original inputs unchanged, whereas, in general, member functions save the result in the matrix itself and return void: