Matrix4

class Matrix4

Represents a 4x4 matrix.

The most common use of a 4x4 matrix in 3D computer graphics is as a transformation matrix: translation, rotation, shear, scale, reflection, or an orthographic or perspective projection. You apply it to a vector by multiplication.

Row-major and column-major ordering: set takes its arguments in row-major order, so a literal in source reads the way you would write the matrix on paper. The values are stored in elements in column-major order. There is no element constructor; use Matrix4().set(...).

Matrices are mutable and not thread-safe; confine an instance (and any object graph holding it) to a single thread, exactly as in three.js. Most methods mutate this and return it for chaining.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard

A column-major list of matrix values. Initialized to the 4x4 identity.

Functions

Link copied to clipboard
fun clone(): Matrix4

Returns a new matrix with copied values from this instance.

Link copied to clipboard
fun compose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4

Sets this matrix to the transformation composed of the given position, rotation (quaternion) and scale.

Link copied to clipboard

Copies the values of the given matrix m to this instance.

Link copied to clipboard

Copies the translation component of the given matrix m into this matrix's translation component.

Link copied to clipboard
fun decompose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4

Decomposes this matrix into its position, rotation (quaternion) and scale components and stores the result in the given objects.

Link copied to clipboard

Computes and returns the determinant of this matrix.

Link copied to clipboard

Computes and returns the determinant of this matrix assuming it is affine, saving some computations.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Structural equality: true when other is a Matrix4 whose elements are element-wise equal (via DoubleArray.contentEquals, so NaN != NaN).

Link copied to clipboard
fun extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4

Extracts the basis of this matrix into the three axis vectors provided.

Link copied to clipboard

Extracts the rotation component of the given matrix m into this matrix's rotation component.

Link copied to clipboard
fun fromArray(array: DoubleArray, offset: Int = 0): Matrix4

Sets the elements of the matrix from the given array (column-major order).

Link copied to clipboard

Returns the maximum scale value of the three axes.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Sets this matrix to the 4x4 identity matrix.

Link copied to clipboard

Inverts this matrix, using the analytic method. You can not invert a matrix with a determinant of zero; if you attempt this, the method produces a zero matrix instead.

Link copied to clipboard
fun lookAt(eye: Vector3, target: Vector3, up: Vector3): Matrix4

Sets the rotation component of the transformation matrix, looking from eye towards target, oriented by the up direction.

Link copied to clipboard
fun makeBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4

Sets the given basis vectors as the columns of this matrix.

Link copied to clipboard
fun makeOrthographic(left: Double, right: Double, top: Double, bottom: Double, near: Double, far: Double, coordinateSystem: CoordinateSystem = CoordinateSystem.WebGL, reversedDepth: Boolean = false): Matrix4

Creates an orthographic projection matrix. Used internally by OrthographicCamera.updateProjectionMatrix.

Link copied to clipboard
fun makePerspective(left: Double, right: Double, top: Double, bottom: Double, near: Double, far: Double, coordinateSystem: CoordinateSystem = CoordinateSystem.WebGL, reversedDepth: Boolean = false): Matrix4

Creates a perspective projection matrix. Used internally by PerspectiveCamera.updateProjectionMatrix.

Link copied to clipboard

Sets this matrix as a rotational transformation around the given axis by the given angle angle (in radians).

Link copied to clipboard

Sets the rotation component (the upper-left 3x3 matrix) of this matrix to the rotation specified by the given Euler angles euler. The rest of the matrix is set to the identity. Depending on the Euler.order, there are six possible outcomes.

Link copied to clipboard

Sets the rotation component of this matrix to the rotation specified by the given Quaternion q. The rest of the matrix is set to the identity.

Link copied to clipboard

Sets this matrix as a rotational transformation around the X axis by the given angle theta (in radians).

Link copied to clipboard

Sets this matrix as a rotational transformation around the Y axis by the given angle theta (in radians).

Link copied to clipboard

Sets this matrix as a rotational transformation around the Z axis by the given angle theta (in radians).

Link copied to clipboard

Sets this matrix as a scale transformation.

Link copied to clipboard
fun makeShear(xy: Double, xz: Double, yx: Double, yz: Double, zx: Double, zy: Double): Matrix4

Sets this matrix as a shear transformation.

Link copied to clipboard

Sets this matrix as a translation transform from the given vector v.

Sets this matrix as a translation transform.

Link copied to clipboard

Post-multiplies this matrix by the given 4x4 matrix m.

Link copied to clipboard

Multiplies the given 4x4 matrices a and b and stores the result in this matrix.

Link copied to clipboard

Multiplies every component of the matrix by the given scalar s.

Link copied to clipboard

Pre-multiplies this matrix by the given 4x4 matrix m.

Link copied to clipboard

Multiplies the columns of this matrix by the given scale vector v.

Link copied to clipboard
fun set(n11: Double, n12: Double, n13: Double, n14: Double, n21: Double, n22: Double, n23: Double, n24: Double, n31: Double, n32: Double, n33: Double, n34: Double, n41: Double, n42: Double, n43: Double, n44: Double): Matrix4

Sets the elements of the matrix. The arguments are supposed to be in row-major order.

Link copied to clipboard

Sets the upper 3x3 elements of this matrix to the values of the given 3x3 matrix m.

Link copied to clipboard

Sets the position component of this matrix from the given vector v, without affecting the rest of the matrix.

Sets the position component of this matrix from the given components, without affecting the rest of the matrix.

Link copied to clipboard
fun toArray(array: MutableList<Double> = mutableListOf(), offset: Int = 0): MutableList<Double>

Writes the elements of this matrix into array at offset (column-major order), growing the list as needed, and returns it.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Transposes this matrix in place.