Taos API Reference
    Preparing search index...

    Class Mat4

    Column-major 4x4 matrix compatible with WebGPU/WGSL.

    Internal storage is a Float32Array of 16 elements where the element at column c, row r lives at data[c * 4 + r]. All instance methods are non-mutating (they return a new Mat4); the underlying data buffer is exposed as readonly.

    Index

    Constructors

    Properties

    Methods

    • Returns the element at the given column and row.

      Parameters

      • col: number
      • row: number

      Returns number

    • Writes a value at the given column and row.

      Parameters

      • col: number
      • row: number
      • v: number

      Returns void

    • Transforms a 3D point (w = 1), applying the full affine transform and performing perspective divide.

      Parameters

      Returns Vec3

    • Returns the inverse-transpose of the upper-left 3x3, embedded in a 4x4 matrix.

      Use this to transform normals when the model matrix contains non-uniform scale.

      Returns Mat4

    • Sets this matrix to the 4x4 identity.

      Returns this

    • Sets this matrix to a translation by (x, y, z).

      Parameters

      • x: number
      • y: number
      • z: number

      Returns this

    • Sets this matrix to a non-uniform scale with the given per-axis factors.

      Parameters

      • x: number
      • y: number
      • z: number

      Returns this

    • Sets this matrix to a rotation of rad radians around the X axis.

      Parameters

      • rad: number

      Returns this

    • Sets this matrix to a rotation of rad radians around the Y axis.

      Parameters

      • rad: number

      Returns this

    • Sets this matrix to a rotation of rad radians around the Z axis.

      Parameters

      • rad: number

      Returns this

    • Sets this matrix to the rotation defined by quaternion components (qx, qy, qz, qw).

      Parameters

      • qx: number
      • qy: number
      • qz: number
      • qw: number

      Returns this

    • Sets this matrix to a right-handed perspective projection with the WebGPU clip-space depth range [0, 1].

      Parameters

      • fovY: number
      • aspect: number
      • near: number
      • far: number

      Returns this

    • Sets this matrix to an orthographic projection with the WebGPU clip-space depth range [0, 1].

      Parameters

      • left: number
      • right: number
      • bottom: number
      • top: number
      • near: number
      • far: number

      Returns this

    • Sets this matrix to a right-handed view matrix placing the camera at eye looking at target, with up defining the camera's roll. View space uses -Z as forward.

      Parameters

      Returns this

    • In-place matrix product: this ← a * b. Alias-safe — this may equal a, b, or both. Computes into a class-private scratch buffer before writing back so the source data isn't trampled mid-multiply. Use in hot loops to avoid the per-call Float32Array allocation that multiply() does.

      Parameters

      Returns this

    • In-place: this ← inverse-transpose of the upper-left 3x3 of src, with the 4th row/column zeroed and [15] = 1 (the same shape as normalMatrix()). Alias-safe — src may equal this because we read every src entry into a local before writing the output. Use in hot loops.

      Parameters

      Returns this

    • Sets this matrix to Translate * Rotate * Scale.

      Parameters

      • t: Vec3
      • qx: number
      • qy: number
      • qz: number
      • qw: number
      • s: Vec3

      Returns this

    • Returns a translation matrix by (x, y, z).

      Parameters

      • x: number
      • y: number
      • z: number

      Returns Mat4

    • Returns a non-uniform scale matrix with the given per-axis factors.

      Parameters

      • x: number
      • y: number
      • z: number

      Returns Mat4

    • Returns a rotation matrix of rad radians around the X axis.

      Parameters

      • rad: number

      Returns Mat4

    • Returns a rotation matrix of rad radians around the Y axis.

      Parameters

      • rad: number

      Returns Mat4

    • Returns a rotation matrix of rad radians around the Z axis.

      Parameters

      • rad: number

      Returns Mat4

    • Builds a rotation matrix from quaternion components (qx, qy, qz, qw).

      Parameters

      • qx: number
      • qy: number
      • qz: number
      • qw: number

      Returns Mat4

    • Builds a right-handed perspective projection with the WebGPU clip-space depth range [0, 1].

      Parameters

      • fovY: number

        vertical field of view in radians

      • aspect: number

        viewport width / height

      • near: number

        near plane distance (positive)

      • far: number

        far plane distance (positive)

      Returns Mat4

    • Reversed-Z perspective (WebGPU clip-space depth [0,1], but mapping the NEAR plane to 1 and the FAR plane to 0). Paired with a float depth buffer and a greater/greater-equal depth test, this spreads depth precision near- uniformly across the frustum, so a very large far/near ratio no longer z-fights. Drop-in for perspective; its inverse is still a valid invViewProj, so shaders that reconstruct world position from the depth buffer work unchanged — only explicit far-plane tests (far is now 0) and hardcoded depth-linearization formulas need flipping.

      Parameters

      • fovY: number
      • aspect: number
      • near: number
      • far: number

      Returns Mat4

    • Builds an orthographic projection with the WebGPU clip-space depth range [0, 1].

      Parameters

      • left: number
      • right: number
      • bottom: number
      • top: number
      • near: number
      • far: number

      Returns Mat4

    • Builds a right-handed view matrix that places the camera at eye looking at target, with up defining the camera's roll. View space uses -Z as forward.

      Parameters

      Returns Mat4

    • Builds a Translate * Rotate * Scale matrix.

      Parameters

      • t: Vec3

        translation

      • qx: number

        quaternion x component

      • qy: number

        quaternion y component

      • qz: number

        quaternion z component

      • qw: number

        quaternion w (scalar) component

      • s: Vec3

        per-axis scale factors

      Returns Mat4