Represents a 4x4 matrix stored in column-major order (OpenGL/WebGL style). This class provides immutable matrix operations and is used for 3D transformations including translation, rotation, and scaling.

const identity = Matrix44.identity();
const translation = Matrix44.translate(Vector3.fromCopyArray([1, 2, 3]));
const result = Matrix44.multiply(identity, translation);

Hierarchy (view full)

Implements

Constructors

Properties

_v: Float32Array = ...

Internal Float32Array storage for matrix elements

Accessors

  • get glslStrAsFloat(): string
  • Converts the matrix to a GLSL mat4 string representation with float precision.

    Returns string

    A GLSL-compatible string representation of the matrix

  • get glslStrAsInt(): string
  • Converts the matrix to a GLSL mat4 string representation with integer values.

    Returns string

    A GLSL-compatible string representation of the matrix with integer values

  • get isIdentityMatrixClass(): boolean
  • Indicates whether this matrix is an identity matrix class.

    This property should be overridden in derived classes that represent identity matrices to return true.

    Returns boolean

    False for the base AbstractMatrix class

  • get wgslStrAsFloat(): string
  • Converts the matrix to a WGSL mat4x4f string representation with float precision.

    Returns string

    A WGSL-compatible string representation of the matrix

  • get wgslStrAsInt(): string
  • Converts the matrix to a WGSL mat4x4i string representation with integer values.

    Returns string

    A WGSL-compatible string representation of the matrix with integer values

  • get compositionType(): CompositionTypeClass<"MAT4">
  • Gets the composition type for this matrix class.

    Returns CompositionTypeClass<"MAT4">

    The composition type enum value

Methods

  • Gets a matrix element at the specified row and column.

    Parameters

    • row_i: number

      The row index (0-3)

    • column_i: number

      The column index (0-3)

    Returns number

    The matrix element at the given position

  • Checks if this matrix is approximately equal to another matrix.

    Parameters

    • mat: IMatrix44

      The matrix to compare with

    • delta: number = Number.EPSILON

      The tolerance for floating-point comparison (default: Number.EPSILON)

    Returns boolean

    true if matrices are approximately equal within the given tolerance

  • Checks if this matrix is exactly equal to another matrix. Uses strict equality comparison for all elements.

    Parameters

    Returns boolean

    true if matrices are exactly equal, false otherwise

  • Checks if the matrix's internal storage shares the same ArrayBuffer as the provided one.

    This method is useful for determining if two matrices share the same underlying memory, which can be important for performance optimizations and avoiding unnecessary data copying.

    Parameters

    • arrayBuffer: ArrayBuffer

      The ArrayBuffer to compare against

    Returns boolean

    True if the internal storage uses the same ArrayBuffer, false otherwise

  • Gets the matrix element at the specified flat index.

    This provides direct access to the underlying Float32Array storage using a single index rather than row/column coordinates.

    Parameters

    • i: number

      The zero-based flat index into the matrix storage

    Returns number

    The matrix element value at the specified index

  • Creates a matrix from 16 individual values in column-major order. This matches the internal storage format used by WebGL.

    Parameters

    • m00: number

      Element at row 0, column 0

    • m10: number

      Element at row 1, column 0

    • m20: number

      Element at row 2, column 0

    • m30: number

      Element at row 3, column 0

    • m01: number

      Element at row 0, column 1

    • m11: number

      Element at row 1, column 1

    • m21: number

      Element at row 2, column 1

    • m31: number

      Element at row 3, column 1

    • m02: number

      Element at row 0, column 2

    • m12: number

      Element at row 1, column 2

    • m22: number

      Element at row 2, column 2

    • m32: number

      Element at row 3, column 2

    • m03: number

      Element at row 0, column 3

    • m13: number

      Element at row 1, column 3

    • m23: number

      Element at row 2, column 3

    • m33: number

      Element at row 3, column 3

    Returns Matrix44

    A new Matrix44 instance

  • Creates a matrix from 16 individual values in row-major order. This is the most intuitive way to specify matrix values, as you can write them in the same 4x4 layout as they appear visually. Note that internally, WebGL uses column-major storage.

    Parameters

    • m00: number

      Element at row 0, column 0

    • m01: number

      Element at row 0, column 1

    • m02: number

      Element at row 0, column 2

    • m03: number

      Element at row 0, column 3

    • m10: number

      Element at row 1, column 0

    • m11: number

      Element at row 1, column 1

    • m12: number

      Element at row 1, column 2

    • m13: number

      Element at row 1, column 3

    • m20: number

      Element at row 2, column 0

    • m21: number

      Element at row 2, column 1

    • m22: number

      Element at row 2, column 2

    • m23: number

      Element at row 2, column 3

    • m30: number

      Element at row 3, column 0

    • m31: number

      Element at row 3, column 1

    • m32: number

      Element at row 3, column 2

    • m33: number

      Element at row 3, column 3

    Returns Matrix44

    A new Matrix44 instance

  • Creates a matrix from a fixed-size array (Array16) in column-major order.

    Parameters

    • array: Array16<number>

      An Array16 containing exactly 16 matrix elements

    Returns Matrix44

    A new Matrix44 instance with copied values

  • Creates a matrix from a fixed-size array (Array16) in row-major order. The input array is converted from row-major to column-major order.

    Parameters

    • array: Array16<number>

      An Array16 containing exactly 16 matrix elements in row-major order

    Returns Matrix44

    A new Matrix44 instance with converted values

  • Creates a matrix from a variable-length array in column-major order.

    Parameters

    • array: number[]

      An array containing at least 16 matrix elements

    Returns Matrix44

    A new Matrix44 instance with copied values

  • Creates a matrix from a variable-length array in row-major order. The input array is converted from row-major to column-major order.

    Parameters

    • array: number[]

      An array containing at least 16 matrix elements in row-major order

    Returns Matrix44

    A new Matrix44 instance with converted values

  • Creates a matrix from a Float32Array in column-major order with copying.

    Parameters

    • float32Array: Float32Array

      A Float32Array containing 16 matrix elements

    Returns Matrix44

    A new Matrix44 instance with copied values

  • Creates a matrix from a Float32Array in row-major order with copying. The input array is assumed to be in row-major order and will be converted to column-major order for internal storage.

    Parameters

    • array: Float32Array

      A Float32Array containing 16 matrix elements in row-major order

    Returns Matrix44

    A new Matrix44 instance with converted values

  • Creates a 4x4 matrix from a 3x3 matrix by embedding it in the upper-left corner. The resulting matrix has the 3x3 matrix in the upper-left, with the bottom-right element set to 1 and other elements set to 0.

    Parameters

    Returns Matrix44

    A new Matrix44 instance

  • Creates a matrix directly from a Float32Array in column-major order. The array is used directly without copying (shares the same memory).

    Parameters

    • float32Array: Float32Array

      A Float32Array containing 16 matrix elements

    Returns Matrix44

    A new Matrix44 instance using the provided array

  • Creates an inverse matrix from the given matrix. Uses optimized computation for 4x4 matrix inversion.

    Parameters

    Returns IMatrix44

    A new Matrix44 instance representing the inverted matrix

    Logs an error if the matrix is not invertible (determinant is 0)

  • Computes the inverse of a matrix and stores the result in an output matrix. This is the mutable version of the invert method for performance optimization.

    Parameters

    Returns MutableMatrix44

    The output matrix containing the inverted matrix

    Logs an error if the matrix is not invertible (determinant is 0)

  • Multiplies two 4x4 matrices and returns the result. Optimized to handle identity matrices efficiently.

    Parameters

    • l_mat: IMatrix44

      The left matrix in the multiplication

    • r_mat: IMatrix44

      The right matrix in the multiplication

    Returns IMatrix44

    A new Matrix44 instance representing the matrix product (l_mat * r_mat)

  • Multiplies two 4x4 matrices and stores the result in an output matrix. This is the mutable version of the multiply method for performance optimization.

    Parameters

    • l_mat: IMatrix44

      The left matrix in the multiplication

    • r_mat: IMatrix44

      The right matrix in the multiplication

    • outMat: MutableMatrix44

      The output matrix to store the result

    Returns MutableMatrix44

    The output matrix containing the multiplication result

  • Multiplies a matrix with data from a typed array and stores the result. This method is optimized for working with raw array data.

    Parameters

    • l_mat: IMatrix44

      The left matrix in the multiplication

    • r_array: ArrayType

      The right operand as a typed array

    • outMat: MutableMatrix44

      The output matrix to store the result

    • offsetAsComposition: number

      The offset in the array for composition data

    Returns MutableMatrix44

    The output matrix containing the multiplication result

  • Creates a rotation matrix from a 3D vector containing Euler angles.

    Parameters

    • vec: IVector3

      A vector containing rotation angles [x, y, z] in radians

    Returns Matrix44

    A new Matrix44 instance representing the rotation

  • Creates a rotation matrix around the X-axis.

    Parameters

    • radian: number

      The rotation angle in radians

    Returns Matrix44

    A new Matrix44 instance representing the X-axis rotation

  • Creates a rotation matrix from Euler angles (XYZ order). Applies rotations in the order: X, then Y, then Z.

    Parameters

    • x: number

      Rotation around X-axis in radians

    • y: number

      Rotation around Y-axis in radians

    • z: number

      Rotation around Z-axis in radians

    Returns Matrix44

    A new Matrix44 instance representing the combined rotation

  • Creates a rotation matrix around the Y-axis.

    Parameters

    • radian: number

      The rotation angle in radians

    Returns Matrix44

    A new Matrix44 instance representing the Y-axis rotation

  • Creates a rotation matrix around the Z-axis.

    Parameters

    • radian: number

      The rotation angle in radians

    Returns Matrix44

    A new Matrix44 instance representing the Z-axis rotation