Basic 4x4 matrix class used for matrix calculations.

Note that like three.js, the constructor and set method take arguments in row-major order, while internally they are stored in the elements array in column-major order.

Constructors

  • Mat4 constructor

    Parameters

    • elements: Float32Array = ...

      initial array to use, default to identity matrix

    Returns Mat4

Properties

type: string

The type of the Mat4

elements: Float32Array

Our matrix array

Methods

  • Sets the matrix from 16 numbers

    Parameters

    • n11: number

      number

    • n12: number

      number

    • n13: number

      number

    • n14: number

      number

    • n21: number

      number

    • n22: number

      number

    • n23: number

      number

    • n24: number

      number

    • n31: number

      number

    • n32: number

      number

    • n33: number

      number

    • n34: number

      number

    • n41: number

      number

    • n42: number

      number

    • n43: number

      number

    • n44: number

      number

    Returns Mat4

    • this Mat4 after being set
  • Sets the Mat4 values from an array

    Parameters

    • array: number[] | Float32Array = ...

      array to use

    Returns Mat4

    • this Mat4 after being set
  • Get the maximum scale of the Mat4 on all axes

    Returns number

    • maximum scale of the Mat4
  • Compute a view Mat4 matrix.

    This is a view matrix which transforms all other objects to be in the space of the view defined by the parameters.

    Equivalent to matrix.lookAt(eye, target, up).invert() but faster.

    Parameters

    • eye: Vec3 = ...

      the position of the object.

    • target: Vec3 = ...

      the position meant to be aimed at.

    • up: Vec3 = ...

      a vector pointing up.

    Returns Mat4

    • the view Mat4 matrix.
  • Create an orthographic Mat4 matrix based on the parameters. Transforms from

    • the given the left, right, bottom, and top dimensions to -1 +1 in x, and y
    • and 0 to +1 in z.

    Parameters

    Returns Mat4

    • the camera orthographic Mat4 matrix.
  • Create a perspective Mat4 matrix based on the parameters.

    Note, The matrix generated sends the viewing frustum to the unit box. We assume a unit box extending from -1 to 1 in the x and y dimensions and from -1 to 1 in the z dimension, as three.js and more generally WebGL handles it.

    Parameters

    Returns Mat4

    • the camera perspective Mat4 matrix.