Matrix4
class Matrix4
An immutable 4x4 matrix that represents translation, scale, and rotation. The matrix is column major and right handed. The indexes of dataToCopy represent the following matrix layout:
[0, 4, 8, 12]
[1, 5, 9, 13]
[2, 6, 10, 14]
[3, 7, 11, 15]
Summary
Public companion functions |
|
|---|---|
Matrix4 |
Returns a new rigid transformation matrix. |
Matrix4 |
fromQuaternion(quaternion: Quaternion)Returns a new rotation matrix. |
Matrix4 |
Returns a new uniform scale matrix. |
Matrix4 |
Returns a new scale matrix. |
Matrix4 |
fromTranslation(translation: Vector3)Returns a new translation matrix. |
Matrix4 |
fromTrs(translation: Vector3, rotation: Quaternion, scale: Vector3)Returns a new transformation matrix. |
Public constructors |
|---|
Matrix4(dataToCopy: FloatArray) |
|
Creates a new matrix with a deep copy of the data from the |
Public functions |
|
|---|---|
Matrix4 |
copy(data: FloatArray)Returns a copy of the matrix. |
open operator Boolean |
Returns true if this matrix is equal to |
open Int |
hashCode()Standard hash code calculation using constructor values |
operator Matrix4 |
Returns a new matrix with the matrix multiplication product of this matrix and the |
Pose |
toPose()Converts this matrix to a |
open String |
toString()Standard toString() implementation |
Matrix4 |
unscaled()Returns a normalized transformation matrix. |
Public properties |
|
|---|---|
FloatArray |
Returns an array of the components of this matrix. |
Matrix4 |
Returns a matrix that performs the opposite transformation. |
Boolean |
Returns true if this matrix is a valid transformation matrix that can be decomposed into translation, rotation and scale using determinant properties. |
Quaternion |
Returns the rotation component of this matrix. |
Vector3 |
Returns the scale component of this matrix. |
Vector3 |
Returns the translation component of this matrix. |
Matrix4 |
Returns a matrix that is the transpose of this matrix. |
Public companion functions
fromPose
fun fromPose(pose: Pose): Matrix4
Returns a new rigid transformation matrix. The returned matrix is such that it first rotates objects, and then translates them.
| Parameters | |
|---|---|
pose: Pose |
the pose to convert |
fromQuaternion
fun fromQuaternion(quaternion: Quaternion): Matrix4
Returns a new rotation matrix.
| Parameters | |
|---|---|
quaternion: Quaternion |
the rotation quaternion |
fromScale
fun fromScale(scale: Float): Matrix4
Returns a new uniform scale matrix.
| Parameters | |
|---|---|
scale: Float |
the uniform scale factor |
fromScale
fun fromScale(scale: Vector3): Matrix4
Returns a new scale matrix.
| Parameters | |
|---|---|
scale: Vector3 |
the scale vector |
fromTranslation
fun fromTranslation(translation: Vector3): Matrix4
Returns a new translation matrix.
| Parameters | |
|---|---|
translation: Vector3 |
the translation vector |
fromTrs
fun fromTrs(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4
Returns a new transformation matrix. The returned matrix is such that it first scales objects, then rotates them, and finally translates them.
| Parameters | |
|---|---|
translation: Vector3 |
the translation component |
rotation: Quaternion |
the rotation component |
scale: Vector3 |
the scale component |
Public companion properties
Public constructors
Matrix4
Matrix4(dataToCopy: FloatArray)
| Parameters | |
|---|---|
dataToCopy: FloatArray |
the array with 16 elements that will be copied over |
Matrix4
Matrix4(other: Matrix4)
Creates a new matrix with a deep copy of the data from the other.
Public functions
copy
fun copy(data: FloatArray = this.data): Matrix4
Returns a copy of the matrix.
| Parameters | |
|---|---|
data: FloatArray = this.data |
the new data for the copied matrix |
equals
open operator fun equals(other: Any?): Boolean
Returns true if this matrix is equal to other.
times
operator fun times(other: Matrix4): Matrix4
Returns a new matrix with the matrix multiplication product of this matrix and the other matrix.
unscaled
fun unscaled(): Matrix4
Returns a normalized transformation matrix.
This method removes the scaling factors from this matrix, as determined by scale, while preserving its core rotational and translational components. The resulting matrix is therefore ideal for accurate normal vector transformations and pure orientation extraction.
Public properties
inverse
val inverse: Matrix4
Returns a matrix that performs the opposite transformation.
isTrs
val isTrs: Boolean
Returns true if this matrix is a valid transformation matrix that can be decomposed into translation, rotation and scale using determinant properties.
rotation
val rotation: Quaternion
Returns the rotation component of this matrix.
translation
val translation: Vector3
Returns the translation component of this matrix.
transpose
val transpose: Matrix4
Returns a matrix that is the transpose of this matrix.