dot big bang

Developer API
Menu

Class Matrix4

All
  • Public
  • Public/Protected
  • All

Hierarchy

  • Matrix4

Index

Constructors

constructor

Properties

elements

elements: Float32Array

The column-major list of matrix values.

Methods

clone

  • Creates a new Matrix4 with identical elements to this one.

    Returns Matrix4

compose

  • Sets this matrix to the transform composed of position, quaternion (for the rotation component) and scale.

    Parameters

    • position: Vector3

      The position component of the transform in this matrix.

    • quaternion: Quaternion

      The rotation component of the transform in this matrix.

    • scale: Vector3

      The scale component of the transform in this matrix.

    Returns Matrix4

copy

  • Copies the elements of matrix m into this matrix.

    Parameters

    • m: Matrix4

      The other matrix to copy the elements from.

    Returns Matrix4

copyPosition

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

    Parameters

    • m: Matrix4

      The other matrix to copy the elements from.

    Returns Matrix4

decompose

  • Decomposes this matrix into its position, rotation (expressed as a quaternion) and scale components.

    Parameters

    • position: Vector3

      The vector to receive the position component of this matrix.

    • quaternion: Quaternion

      The quaternion to receive the rotation component of this matrix.

    • scale: Vector3

      The vector to receive the scale component of this matrix.

    Returns Matrix4

determinant

  • determinant(): number
  • Computes and returns the determinant of this matrix. Based on the method outlined here.

    Returns number

equals

  • Returns true if this matrix and the other matrix m have identical elements.

    Parameters

    • m: Matrix4

      The matrix that this one will be compared to.

    Returns boolean

extractBasis

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

    Parameters

    • xAxis: Vector3

      The vector to receive the X axis.

    • yAxis: Vector3

      The vector to receive the Y axis.

    • zAxis: Vector3

      The vector to receive the Z axis.

    Returns Matrix4

extractRotation

  • Extracts the rotation component of the supplied matrix m as a pure rotation matrix (i.e. without scale and translation) and copies it into this matrix's rotation component. This resets this matrix's scale, but doesn't affect its translation.

    Parameters

    • m: Matrix4

      The matrix to get the rotation component from.

    Returns Matrix4

fromArray

  • fromArray(array: number[], offset?: number): Matrix4
  • Sets the elements of this matrix based on an array in colum-major format.

    Parameters

    • array: number[]

      The array to read the elements from.

    • Optional offset: number

      The offset in the array from which to read the elements. Defaults to 0.

    Returns Matrix4

getInverse

  • Sets this matrix to the inverse of the matrix m. You cannot invert a matrix with a determinant of zero. If you attempt this, the method will warn you in the console and return the identity matrix or it will throw an error if throwOnDegenerate is true. Based on the method outlined here.

    Parameters

    • m: Matrix4

      The matrix to inverse and store into this one.

    • throwOnDegenerate: boolean

      If true, throw an error if the matrix is degenerate (not invertible).

    Returns Matrix4

getMaxScaleOnAxis

  • getMaxScaleOnAxis(): number
  • Gets the maximum scale value of the 3 axes.

    Returns number

identity

lookAt

  • Calculates a rotation matrix looking from the eye point towards the target point, considering up as the general up direction, then sets it as the rotation component of this matrix. The translation component of this matrix is unaffected.

    Parameters

    • eye: Vector3

      The point used with target to calculate the forward axis of this matrix.

    • target: Vector3

      The point used with eye to calculate the forward axis of this matrix.

    • up: Vector3

      A vector representing the general up direction. It is used to calculate the final up and left axes of this matrix.

    Returns Matrix4

makeBasis

  • Sets this matrix to the basis consisting of the three provided vectors. This method affects the rotation/scale component of the matrix and resets the translation component.

    Parameters

    • xAxis: Vector3

      The X axis of the basis to set into this matrix.

    • yAxis: Vector3

      The Y axis of the basis to set into this matrix.

    • zAxis: Vector3

      The Z axis of the basis to set into this matrix.

    Returns Matrix4

makeFrustum

  • makeFrustum(left: number, right: number, bottom: number, top: number, near: number, far: number): Matrix4
  • Parameters

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

    Returns Matrix4

makeOrthographic

  • makeOrthographic(left: number, right: number, top: number, bottom: number, near: number, far: number): Matrix4
  • Makes this matrix an orthographic projection matrix.

    Parameters

    • left: number

      The camera frustum left plane.

    • right: number

      The camera frustum right plane.

    • top: number

      The camera frustum top plane.

    • bottom: number

      The camera frustum bottom plane.

    • near: number

      The camera frustum near plane.

    • far: number

      The camera frustum far plane.

    Returns Matrix4

makePerspective

  • makePerspective(fov: number, aspect: number, near: number, far: number): Matrix4
  • Makes this matrix a perspective projection matrix.

    Parameters

    • fov: number

      The camera frustum vertical field of view in degrees.

    • aspect: number

      The camera frustum aspect ratiow (i.e. the width/height ratio).

    • near: number

      The camera frustum near plane.

    • far: number

      The camera frustum far plane.

    Returns Matrix4

makeRotationAxis

  • Sets this matrix as a rotation transform around the axis by theta radians. This is a somewhat controversial but mathematically sound alternative to rotating via Quaternions. See the discussion here.

    Parameters

    • axis: Vector3

      A normalized rotation axis.

    • angle: number

      The rotation angle in radians.

    Returns Matrix4

makeRotationFromEuler

  • Sets the rotation component (the upper left 3x3 matrix) of this matrix to the rotation specified by the given euler transform. The rest of the matrix is set to the identity. Depending on the order of the euler, there are six possible outcomes. See this page for a complete list.

    Parameters

    • euler: Euler

      The euler transform to get the rotation from.

    Returns Matrix4

makeRotationFromQuaternion

  • Sets the rotation component of this matrix to the rotation specified by the quaternion q, as outlined here. The rest of the matrix is set to the identity.

    Parameters

    • q: Quaternion

      The quaternion to set this matrix rotation component from.

    Returns Matrix4

makeRotationX

  • makeRotationX(theta: number): Matrix4
  • Sets this matrix as a rotation transform around the X axis by theta radians.

    Parameters

    • theta: number

      The rotation angle in radians.

    Returns Matrix4

makeRotationY

  • makeRotationY(theta: number): Matrix4
  • Sets this matrix as a rotation transform around the Y axis by theta radians.

    Parameters

    • theta: number

      The rotation angle in radians.

    Returns Matrix4

makeRotationZ

  • makeRotationZ(theta: number): Matrix4
  • Sets this matrix as a rotation transform around the Z axis by theta radians.

    Parameters

    • theta: number

      The rotation angle in radians.

    Returns Matrix4

makeScale

  • makeScale(x: number, y: number, z: number): Matrix4
  • Sets this matrix as a scale transform.

    Parameters

    • x: number

      The scale x component.

    • y: number

      The scale y component.

    • z: number

      The scale z component.

    Returns Matrix4

makeTranslation

  • makeTranslation(x: number, y: number, z: number): Matrix4
  • Sets this matrix as a translation transform.

    Parameters

    • x: number

      The x component of the translation vector.

    • y: number

      The y component of the translation vector.

    • z: number

      The z component of the translation vector.

    Returns Matrix4

multiply

  • Post-multiplies this matrix by m.

    Parameters

    • m: Matrix4

      The matrix to post-multiply this matrix with.

    Returns Matrix4

multiplyMatrices

  • Sets this matrix to a x b.

    Parameters

    • a: Matrix4

      First matrix to multiply.

    • b: Matrix4

      Second matrix to multiply.

    Returns Matrix4

multiplyScalar

  • multiplyScalar(s: number): Matrix4
  • Multiplies every component of this matrix by the scalar value s.

    Parameters

    • s: number

      The number to multiply each component of the matrix with.

    Returns Matrix4

premultiply

  • Pre-multiplies this matrix by m.

    Parameters

    • m: Matrix4

      The matrix to pre-multiply this matrix with.

    Returns Matrix4

scale

  • Multiplies the columns of this matrix by vector v.

    Parameters

    • v: Vector3

      The vector to multiply the columns of this matrix with.

    Returns Matrix4

set

  • set(n11: number, n12: number, n13: number, n14: number, n21: number, n22: number, n23: number, n24: number, n31: number, n32: number, n33: number, n34: number, n41: number, n42: number, n43: number, n44: number): Matrix4
  • Sets the 4x4 matrix values to the given row-major sequence of values.

    Parameters

    • n11: number

      value to put in row 1, col 1.

    • n12: number

      value to put in row 1, col 2.

    • n13: number

      value to put in row 1, col 3.

    • n14: number

      value to put in row 1, col 4.

    • n21: number

      value to put in row 2, col 1.

    • n22: number

      value to put in row 2, col 2.

    • n23: number

      value to put in row 2, col 3.

    • n24: number

      value to put in row 2, col 4.

    • n31: number

      value to put in row 3, col 1.

    • n32: number

      value to put in row 3, col 2.

    • n33: number

      value to put in row 3, col 3.

    • n34: number

      value to put in row 3, col 4.

    • n41: number

      value to put in row 4, col 1.

    • n42: number

      value to put in row 4, col 2.

    • n43: number

      value to put in row 4, col 3.

    • n44: number

      value to put in row 4, col 4.

    Returns Matrix4

setPosition

  • Sets the position component of this matrix to vector v, without affecting the rest of the matrix.

    Parameters

    • v: Vector3

      The vector to set as the position component of this matrix.

    Returns Matrix4

toArray

  • toArray(array?: number[], offset?: number): number[]
  • Writes the elements of this matrix to an array in column-major format.

    Parameters

    • Optional array: number[]

      The array to store the resulting vector in. If not given a new array will be created.

    • Optional offset: number

      The offset in the array at which to put the result.

    Returns number[]

transpose