[Basic Type](../groups/Basic Type.Basic Type.md) / Matrix4x4
Matrix4x4 Class
Four-dimensional matrix
Precautions
Column matrix
Table of contents
Properties
m00: number |
---|
The element in column 0 and row 0 of the matrix. |
m01: number |
The element in column 0 and row 1 of the matrix. |
m02: number |
The elements in column 0 and row 2 of the matrix. |
m03: number |
The element in column 0 and row 3 of the matrix. |
m10: number |
The element in column 1, row 0 of the matrix. |
m11: number |
The elements in the first column and first row of the matrix. |
m12: number |
The elements in column 1 and row 2 of the matrix. |
m13: number |
The elements in the first column and third row of the matrix. |
m20: number |
The element in column 2, row 0 of the matrix. |
m21: number |
The elements in the second column and first row of the matrix. |
m22: number |
The elements in the second column and second row of the matrix. |
m23: number |
The elements in the second column and third row of the matrix. |
m30: number |
The element in column 3, row 0 of the matrix. |
m31: number |
The elements in the third column and first row of the matrix. |
m32: number |
The elements in the second row of the third column of the matrix. |
m33: number |
The elements in the third column and third row of the matrix. |
Accessors
identity(): void other |
---|
Set the current matrix as the identity matrix. |
Methods
add(mat : Matrix4x4 ): Matrix4x4 other |
---|
Matrix addition. Add the current matrix to the specified matrix and return the result to the current matrix. |
clone(a : Matrix4x4 ): Matrix4x4 other |
Obtain a copy of the specified matrix |
determinant(): number other |
Calculate the determinant of the current matrix. |
equals(other : Matrix4x4 , epsilon? : number ): boolean other |
Determine whether the current matrix is equal to the specified matrix within the error range. |
fromQuaternion(q : Quaternion ): Matrix4x4 other |
Reset the value of the current matrix to represent the rotation transformation represented by the specified quaternion. |
fromRTS(q : Quaternion , v : Vector , s : Vector ): Matrix4x4 other |
Reset the value of the current matrix to represent the specified combination of rotation, scaling, and displacement transformation. |
getRotation(outer? : Quaternion ): Quaternion other |
Calculate the part of the rotation transformation from the current matrix and assign it to the output quaternion in the form of a quaternion. |
getScale(outer? : Vector ): Vector other |
Calculate the part of scale transformation from the current matrix, and assign the value to the exit vector in the form of scale on each axis. |
getTranslation(outer? : Vector ): Vector other |
Calculate the displacement transformation part from the current matrix and assign it to the exit vector in the form of displacement on each axis. |
identity(): void other |
Set the current matrix as the identity matrix. |
invert(a : Matrix4x4 , outer? : Matrix4x4 ): Matrix4x4 other |
Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros. |
multiply |
:----- |
rotate(axis : Vector , rad : number , epsilon? : number ): Matrix4x4 other |
Assign the result of left multiplication of the current matrix by the rotation matrix to the current matrix. The rotation matrix is given by the rotation axis and rotation angle. |
scale(vec : Vector ): Matrix4x4 other |
Assign the result of the left multiplication scaling matrix of the current matrix to the current matrix, where the scaling matrix is given by the scaling of each axis. |
set(other : Matrix4x4 ): Matrix4x4 other |
Set the current matrix to be equal to the specified matrix. |
strictEquals(other : Matrix4x4 ): boolean other |
Determine whether the current matrix is equal to the specified matrix. |
subtract(mat : Matrix4x4 ): Matrix4x4 other |
Calculate matrix subtraction. Assign the result of subtracting the specified matrix from the current matrix to the current matrix. |
toString(): string other |
Returns the string representation of the current matrix. |
translate(vec : Vector ): Matrix4x4 other |
Assign the result of the left multiplication of the current matrix by the displacement matrix to the current matrix, and the displacement matrix is given by the displacement of each axis. |
transpose(a : Matrix4x4 , outer? : Matrix4x4 ): Matrix4x4 other |
Transpose matrix |
zero |
clone(a : Matrix4x4 ): Matrix4x4 other |
Obtain a copy of the specified matrix |
invert(a : Matrix4x4 , outer? : Matrix4x4 ): Matrix4x4 other |
Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros. |
transformAffine(m : Matrix4x4 , a : Vector , outer? : Vector ): Vector other |
Vector affine transformation |
transformAffine4(m : Matrix4x4 , a : Vector4 , outer? : Vector4 ): Vector4 other |
Four-dimensional vector affine transformation |
transformVector(m : Matrix4x4 , a : Vector , outer? : Vector ): Vector other |
Multiplying a vector with a four-dimensional matrix, the fourth bit of the vector is assumed to be 0. |
transformVector2(m : Matrix4x4 , a : Vector2 , outer? : Vector2 ): Vector2 other |
When multiplying a vector and a four-dimensional matrix, the third bit of the vector is 0 by default, and the fourth bit is 1. |
transformVector4(m : Matrix4x4 , a : Vector4 , outer? : Vector4 ): Vector4 other |
Four-dimensional vector and four-dimensional matrix multiplication |
transpose(a : Matrix4x4 , outer? : Matrix4x4 ): Matrix4x4 other |
Transpose matrix |
Build a new Matrix4x4 using the given other
Parameters
other Matrix4x4 | Usage: Given Matrix4x4 object |
---|
• new Matrix4x4(m00?
, m01?
, m02?
, m03?
, m10?
, m11?
, m12?
, m13?
, m20?
, m21?
, m22?
, m23?
, m30?
, m31?
, m32?
, m33?
)
Build a new Matrix4x4 using the given elements
Parameters
m00? number | Usage: element in column 0, line 0 default: 1 range: no restrictions type: floating point number |
---|---|
m01? number | Usage: Element in column 0, line 1 default: 0 range: No restrictions type: Floating point number |
m02? number | Usage: element in column 0, line 2 default: 0 range: no restrictions type: floating point number |
m03? number | Usage: element in column 0, line 3 default: 0 range: no restrictions type: floating point number |
m10? number | Usage: element in column 1, line 0 default: 0 range: no restrictions type: floating point number |
m11? number | Usage: element in column 1, line 1 default: 1 range: no restrictions type: floating point number |
m12? number | Usage: Element in column 1, line 2 default: 0 range: No restrictions type: Floating point number |
m13? number | Usage: element in column 1, line 3 default: 0 range: no restrictions type: floating point number |
m20? number | Usage: element in column 2, line 0 default: 0 range: no restrictions type: floating point number |
m21? number | Usage: Element in column 2, line 1 default: 0 range: No restrictions type: Floating point number |
m22? number | Usage: element in column 2, line 2 default: 1 range: no restrictions type: floating point number |
m23? number | Usage: Element in column 2, line 3 default: 0 range: No restrictions type: Floating point number |
m30? number | Usage: element in column 3, line 0 default: 0 range: no restrictions type: floating point number |
m31? number | Usage: Element in column 3, line 1 default: 0 range: No restrictions type: Floating point number |
m32? number | Usage: Element in column 3, line 2 default: 0 range: No restrictions type: Floating point number |
m33? number | Usage: element in column 3, line 3 default: 1 range: no restrictions type: floating point number |
Properties
m00
• m00: number
The element in column 0 and row 0 of the matrix.
m01
• m01: number
The element in column 0 and row 1 of the matrix.
m02
• m02: number
The elements in column 0 and row 2 of the matrix.
m03
• m03: number
The element in column 0 and row 3 of the matrix.
m10
• m10: number
The element in column 1, row 0 of the matrix.
m11
• m11: number
The elements in the first column and first row of the matrix.
m12
• m12: number
The elements in column 1 and row 2 of the matrix.
m13
• m13: number
The elements in the first column and third row of the matrix.
m20
• m20: number
The element in column 2, row 0 of the matrix.
m21
• m21: number
The elements in the second column and first row of the matrix.
m22
• m22: number
The elements in the second column and second row of the matrix.
m23
• m23: number
The elements in the second column and third row of the matrix.
m30
• m30: number
The element in column 3, row 0 of the matrix.
m31
• m31: number
The elements in the third column and first row of the matrix.
m32
• m32: number
The elements in the second row of the third column of the matrix.
m33
• m33: number
The elements in the third column and third row of the matrix.
Accessors
identity
• Static
get
identity(): Matrix4x4
Obtain a default matrix
Methods
add
• add(mat
): Matrix4x4
other
Matrix addition. Add the current matrix to the specified matrix and return the result to the current matrix.
Parameters
mat Matrix4x4 | Usage: additive matrix |
---|
Returns
Matrix4x4 | this |
---|
clone
• clone(): Matrix4x4
other
Clone the current matrix.
Parameters
a Matrix4x4 | Usage: Cloned four-dimensional matrix |
---|
Returns
Matrix4x4 | Return the cloned new matrix |
---|
determinant
• determinant(): number
other
Calculate the determinant of the current matrix.
Returns
number | The determinant of the current matrix. |
---|
equals
• equals(other
, epsilon?
): boolean
other
Determine whether the current matrix is equal to the specified matrix within the error range.
Parameters
other Matrix4x4 | Usage: Matrix for comparison |
---|---|
epsilon? number | Usage: Error value default: MathUtil.EPSILON range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
boolean | Return the result of matrix comparison |
---|
fromQuaternion
• fromQuaternion(q
): Matrix4x4
other
Reset the value of the current matrix to represent the rotation transformation represented by the specified quaternion.
Parameters
q Quaternion | Usage: Quaternions for rotating data |
---|
Returns
Matrix4x4 | this |
---|
fromRTS
• fromRTS(q
, v
, s
): Matrix4x4
other
Reset the value of the current matrix to represent the specified combination of rotation, scaling, and displacement transformation.
Parameters
q Quaternion | Usage: Quaternions for rotating data |
---|---|
v Vector | Usage: Vector of displacement data |
s Vector | Usage: scale data vector |
Returns
Matrix4x4 | this |
---|
getRotation
• getRotation(outer?
): Quaternion
other
Calculate the part of the rotation transformation from the current matrix and assign it to the output quaternion in the form of a quaternion.
Parameters
outer? Quaternion | Usage: Quaternion object that receives rotated data, default: null |
---|
Returns
Quaternion | Quaternion object for recording rotation data |
---|
Precautions
If the outer is not empty, return the outer, otherwise return a new Quaternion object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
getScale
• getScale(outer?
): Vector
other
Calculate the part of scale transformation from the current matrix, and assign the value to the exit vector in the form of scale on each axis.
Parameters
outer? Vector | Usage: Vector object receiving scale data default: null |
---|
Returns
Vector | Scale Data |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
getTranslation
• getTranslation(outer?
): Vector
other
Calculate the displacement transformation part from the current matrix and assign it to the exit vector in the form of displacement on each axis.
Parameters
outer? Vector | Usage: Vector object for receiving displacement data default: null |
---|
Returns
Vector | Displacement data |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
identity
• identity(): void
other
Set the current matrix as the identity matrix.
invert
• invert(): void
other
Transform the current matrix into an inverse matrix. Note that when the matrix is irreversible, a matrix with all zeros will be returned.
Parameters
a Matrix4x4 | Usage: Original matrix |
---|---|
outer? Matrix4x4 | Usage: Matrix4x4 object receiving results default: null |
Returns
Matrix4x4 | Inverse matrix |
---|
Matrix multiplication. Assign the result of left multiplication of the specified matrix to the current matrix.
Parameters
mat Matrix4x4 | Usage: Multiplying matrices |
---|
Returns
Matrix4x4 | this |
---|
• multiply(scalar
): Matrix4x4
other
Matrix multiplication. Assign the multiplication result of the current matrix and the specified scalar to the current matrix.
Parameters
scalar number | Usage: The number to scale the matrix as a whole. range: No restrictions. type: Floating point number |
---|
Returns
Matrix4x4 | this |
---|
rotate
• rotate(axis
, rad
, epsilon?
): Matrix4x4
other
Assign the result of left multiplication of the current matrix by the rotation matrix to the current matrix. The rotation matrix is given by the rotation axis and rotation angle.
Parameters
axis Vector | Usage: rotation axis around |
---|---|
rad number | Usage: Rotation radians range: Unlimited type: Floating point number |
epsilon? number | Usage: Minimum error count default: MathDefine EPSILON range: It is recommended to pass in a value less than 1. Type: Floating point number |
Returns
Matrix4x4 | this |
---|
scale
• scale(vec
): Matrix4x4
other
Assign the result of the left multiplication scaling matrix of the current matrix to the current matrix, where the scaling matrix is given by the scaling of each axis.
Parameters
vec Vector | Usage: Vector of scaling matrix |
---|
Returns
Matrix4x4 | this |
---|
set
• set(other
): Matrix4x4
other
Set the current matrix to be equal to the specified matrix.
Parameters
other Matrix4x4 | Usage: Matrix data |
---|
Returns
Matrix4x4 | this |
---|
• set(m00?
, m01?
, m02?
, m03?
, m10?
, m11?
, m12?
, m13?
, m20?
, m21?
, m22?
, m23?
, m30?
, m31?
, m32?
, m33?
): Matrix4x4
other
Set the current matrix to specify element values.
Parameters
m00? number | Usage: element in column 0, line 0 default: 1 range: no restrictions type: floating point number |
---|---|
m01? number | Usage: Element in column 0, line 1 default: 0 range: No restrictions type: Floating point number |
m02? number | Usage: element in column 0, line 2 default: 0 range: no restrictions type: floating point number |
m03? number | Usage: element in column 0, line 3 default: 0 range: no restrictions type: floating point number |
m10? number | Usage: element in column 1, line 0 default: 0 range: no restrictions type: floating point number |
m11? number | Usage: element in column 1, line 1 default: 1 range: no restrictions type: floating point number |
m12? number | Usage: Element in column 1, line 2 default: 0 range: No restrictions type: Floating point number |
m13? number | Usage: element in column 1, line 3 default: 0 range: no restrictions type: floating point number |
m20? number | Usage: element in column 2, line 0 default: 0 range: no restrictions type: floating point number |
m21? number | Usage: Element in column 2, line 1 default: 0 range: No restrictions type: Floating point number |
m22? number | Usage: element in column 2, line 2 default: 1 range: no restrictions type: floating point number |
m23? number | Usage: Element in column 2, line 3 default: 0 range: No restrictions type: Floating point number |
m30? number | Usage: element in column 3, line 0 default: 0 range: no restrictions type: floating point number |
m31? number | Usage: Element in column 3, line 1 default: 0 range: No restrictions type: Floating point number |
m32? number | Usage: Element in column 3, line 2 default: 0 range: No restrictions type: Floating point number |
m33? number | Usage: element in column 3, line 3 default: 1 range: no restrictions type: floating point number |
Returns
Matrix4x4 | this |
---|
strictEquals
• strictEquals(other
): boolean
other
Determine whether the current matrix is equal to the specified matrix.
Parameters
other Matrix4x4 | Usage: Matrix for comparison |
---|
Returns
boolean | Return the result of matrix comparison |
---|
subtract
• subtract(mat
): Matrix4x4
other
Calculate matrix subtraction. Assign the result of subtracting the specified matrix from the current matrix to the current matrix.
Parameters
mat Matrix4x4 | Usage: Subtraction matrix |
---|
Returns
Matrix4x4 | this |
---|
toString
• toString(): string
other
Returns the string representation of the current matrix.
Returns
string | The string representation of the current matrix. |
---|
translate
• translate(vec
): Matrix4x4
other
Assign the result of the left multiplication of the current matrix by the displacement matrix to the current matrix, and the displacement matrix is given by the displacement of each axis.
Parameters
vec Vector | Usage: transformed vector |
---|
Returns
Matrix4x4 | this |
---|
transpose
• transpose(): void
other
Transform the current matrix into a transposed matrix.
Parameters
a Matrix4x4 | Usage: transposed original matrix |
---|---|
outer? Matrix4x4 | Usage: Matrix4x4 object receiving results default: null |
Returns
Matrix4x4 | Transpose matrix |
---|
Set the current matrix to a 0 matrix.
clone
• Static
clone(a
): Matrix4x4
other
Obtain a copy of the specified matrix
Parameters
a Matrix4x4 | Usage: Cloned four-dimensional matrix |
---|
Returns
Matrix4x4 | Return the cloned new matrix |
---|
invert
• Static
invert(a
, outer?
): Matrix4x4
other
Inverse the matrix, note that when the matrix is irreversible, it will return a matrix with all zeros.
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Matrix4x4 object. It is recommended to pass in the outer to reduce the number of new objects, and the outer cannot be null/undefined
Parameters
a Matrix4x4 | Usage: Original matrix |
---|---|
outer? Matrix4x4 | Usage: Matrix4x4 object receiving results default: null |
Returns
Matrix4x4 | Inverse matrix |
---|
transformAffine
• Static
transformAffine(m
, a
, outer?
): Vector
other
Vector affine transformation
Parameters
m Matrix4x4 | Usage: Four dimensional matrix |
---|---|
a Vector | Usage: 3D vectors |
outer? Vector | Usage: Vector object for receiving results default: null |
Returns
Vector | The vector obtained after affine transformation |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
transformAffine4
• Static
transformAffine4(m
, a
, outer?
): Vector4
other
Four-dimensional vector affine transformation
Parameters
m Matrix4x4 | Usage: Four dimensional matrix |
---|---|
a Vector4 | Usage: Four dimensional vector |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The four-dimensional vector obtained after affine transformation |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector4 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
transformVector
• Static
transformVector(m
, a
, outer?
): Vector
other
Multiplying a vector with a four-dimensional matrix, the fourth bit of the vector is assumed to be 0.
Parameters
m Matrix4x4 | Usage: four-dimensional matrix being multiplied |
---|---|
a Vector | Usage: Multiplying a three-dimensional vector by a matrix |
outer? Vector | Usage: Vector object for receiving results default: null |
Returns
Vector | The vector obtained after conversion |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
transformVector2
• Static
transformVector2(m
, a
, outer?
): Vector2
other
When multiplying a vector and a four-dimensional matrix, the third bit of the vector is 0 by default, and the fourth bit is 1.
Parameters
m Matrix4x4 | Usage: four-dimensional matrix being multiplied |
---|---|
a Vector2 | Usage: Multiplying a two-dimensional vector by a matrix |
outer? Vector2 | Usage: Vector2 object for receiving results default: null |
Returns
Vector2 | Return the transformed new two-dimensional vector |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector2 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
transformVector4
• Static
transformVector4(m
, a
, outer?
): Vector4
other
Four-dimensional vector and four-dimensional matrix multiplication
Parameters
m Matrix4x4 | Usage: four-dimensional matrix being multiplied |
---|---|
a Vector4 | Usage: Multiplying the four-dimensional vector of a matrix |
outer? Vector4 | Usage: Vector4 object receiving results default: null |
Returns
Vector4 | The four-dimensional vector obtained after conversion |
---|
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Vector4 object. It is recommended to pass in the outer to reduce the new object and the outer cannot be null/undefined
transpose
• Static
transpose(a
, outer?
): Matrix4x4
other
Transpose matrix
Precautions
If the outer is not empty, return the outer. Otherwise, return a new Matrix4x4 object. It is recommended to pass in the outer to reduce the number of new objects, and the outer cannot be null/undefined
Parameters
a Matrix4x4 | Usage: transposed original matrix |
---|---|
outer? Matrix4x4 | Usage: Matrix4x4 object receiving results default: null |
Returns
Matrix4x4 | Transpose matrix |
---|