A 4x4 Matrix.

Such a matrix contains a translation and a rotation/scale part. The matrix contains an array of 16 floats, which memory layout is the following.

If you consider the vector (V) matrix (M) multiplication in line : V' = V x M then the memory layout of the matrix is the following, with the translation part [T0,T1,T2] on the bottom :

array[0]array[1]array[2]0 (array[3])
array[4]array[5]array[6]0 (array[7])
array[8]array[9]array[10]0 (array[11])
T0 : array[12]T1 : array[13]T2 : array[14]1 (array[15])

If on the contrary you consider the vector (V) matrix (M) multiplication in column : V' = M x V then the memory layout of the matrix is the following, with the translation part [T0,T1,T2] on the right :
array[0]array[4]array[8]T0 : array[12]
array[1]array[5]array[9]T1 : array[13]
array[2]array[6]array[10]T2 : array[14]
0 (array[3])0 (array[7])0 (array[11])1 (array[15])

The multiplication in column is the convention adopted in the Matrix4 class, when a matrix M2 is multiplied on the left of M1, then any point P transformed by the resulting transformation (P') will be first transformed by M1 and then M2 :
P' = M2 x M1 x P.
Maths

Constructors

  • Builds a new Matrix4 from the following memory layout.

    If you consider the matrix vector multiplication in line (V' = V x M), then the following matrix is built (translation [T0,T1,T2] on the bottom) :

    abc0 (d)
    efg0 (h)
    ijk0 (l)
    T0 : mT1 : nT2 : o1 (p)

    If you consider the matrix vector multiplication in column (V' = M x V), then the following matrix is built (translation [T0,T1,T2] on the right) :
    aeiT0 : m
    bfjT1 : n
    cgkT2 : o
    0 (d)0 (h)0 (l)1 (p)

    Returns the newly constructed matrix.

    Parameters

    • Optional a: number
      in
      Rotation/scale part.
    • Optional b: number
      in
      Rotation/scale part.
    • Optional c: number
      in
      Rotation/scale part.
    • Optional d: number
      in
      Should be 0.
    • Optional e: number
      in
      Rotation/scale part.
    • Optional f: number
      in
      Rotation/scale part.
    • Optional g: number
      in
      Rotation/scale part.
    • Optional h: number
      in
      Should be 0.
    • Optional i: number
      in
      Rotation/scale part.
    • Optional j: number
      in
      Rotation/scale part.
    • Optional k: number
      in
      Rotation/scale part.
    • Optional l: number
      in
      Should be 0.
    • Optional m: number
      in
      Translation upon x.
    • Optional n: number
      in
      Translation upon y.
    • Optional o: number
      in
      Translation upon z.
    • Optional p: number
      in
      Should be 1.

    Returns Matrix4

    The newly created Matrix4.

Properties

array: Float32Array

A 16 float array that contains the values of the matrix.

Methods

  • Copies this to pOther matrix.

    If pOther is not supplied, a new Matrix4 is allocated.

    Parameters

    • Optional pOut: Matrix4
      out
      The Matrix4 to copy to.

    Returns Matrix4

    The copied matrix.

  • Computes the matrix determinant.

    Returns number

    The determinant of the matrix.

  • Tells if the two matrices are strictly identical.

    Parameters

    • pOtherMatrix: Matrix4
      in
      The other matrix to compare to.

    Returns boolean

    true if the two matrices are strictly identical.

  • Sets the content of the Matrix4 from a former call to toJSON.

    Parameters

    • pMatrixData: string | Object
      in
      Internal Matrix4 data to set.

    Returns boolean

    true if the data is set.

  • Gets the pColum th "column" of the matrix.

    This function actually takes the column if the Matrix vector multiplication is in column : V' = M x V .

    If you consider the matrix vector multiplication in column (V' = M x V, translation [T0,T1,T2] on the right) :

    aeiT0 : m
    bfjT1 : n
    cgkT2 : o
    0 (d)0 (h)0 (l)1 (p)

    Then getColumn(0) returns (a,b,c).

    If you consider the matrix vector multiplication in line (V' = V x M, translation [T0,T1,T2] on the bottom) :

    abc0 (d)
    efg0 (h)
    ijk0 (l)
    T0 : mT1 : nT2 : o1 (p)

    Then getColumn(0) returns (a,b,c).

    No check is done to ensure pColumn is in the range [0-3].

    Parameters

    • pColumn: number
      in
      The column to get in the range [0-3].
    • pOut: Vector3
      out
      The resulting "column" of the matrix.

    Returns Vector3

    pOut.

  • Inverts the transformation and stores the result to pOut.

    If the matrix this is non-invertible, then pOut stores a copy of this.

    If pOut is omitted, the result is stored in this.

    Returns pOut.

    Parameters

    • Optional pOut: Matrix4
      out
      The inverted matrix result.

    Returns Matrix4

    pOut.

  • Tells if the matrix is the identity.

    There is no tolerance on the check, any value other than 0 or 1 in the matrix will make this function return false.

    Returns boolean

    true if the matrix is identity (strictly).

  • Sets this matrix to the identity.

    Returns this

    this.

  • Computes the composition of this and the matrix represented by the values Mval and stores the result in pOut.

    Any point P transformed by the resulting transformation will first be multiplied by this, and then Mval.
    Be P' the transformed point of P :
    Depending on your convention : P' = Mval x this x P (hence multiply left)
    or P' = P x this x Mval.

    If pOut is omitted, the result is stored in this.

    If you consider the matrix vector multiplication in line (V' = V x Mval), then Mval is set to (translation [T0,T1,T2] on the bottom) :

    abc0 (d)
    efg0 (h)
    ijk0 (l)
    T0 : mT1 : nT2 : o1 (p)

    If you consider the matrix vector multiplication in column (V' = Mval x V), then Mval is set (translation [T0,T1,T2] on the right) :
    aeiT0 : m
    bfjT1 : n
    cgkT2 : o
    0 (d)0 (h)0 (l)1 (p)


    Then when using Matrices :
    this.multiplyMatrixLeft(pSecondTransform, pOut);
    

    is equivalent to :
    this.multiplyLeft(
    pSecondTransform.array[0], pSecondTransform.array[1], pSecondTransform.array[2], pSecondTransform.array[3],
    pSecondTransform.array[4], pSecondTransform.array[5], pSecondTransform.array[6], pSecondTransform.array[7],
    pSecondTransform.array[8], pSecondTransform.array[9], pSecondTransform.array[10], pSecondTransform.array[11],
    pSecondTransform.array[12], pSecondTransform.array[13], pSecondTransform.array[14], pSecondTransform.array[15],
    pOut
    );

    Please refer to some matrices courses to get more information.

    Parameters

    • a: number
      in
      Rotation/scale part.
    • b: number
      in
      Rotation/scale part.
    • c: number
      in
      Rotation/scale part.
    • d: number
      in
      Should be 0.
    • e: number
      in
      Rotation/scale part.
    • f: number
      in
      Rotation/scale part.
    • g: number
      in
      Rotation/scale part.
    • h: number
      in
      Should be 0.
    • i: number
      in
      Rotation/scale part.
    • j: number
      in
      Rotation/scale part.
    • k: number
      in
      Rotation/scale part.
    • l: number
      in
      Should be 0.
    • m: number
      in
      Translation upon x.
    • n: number
      in
      Translation upon y.
    • o: number
      in
      Translation upon z.
    • p: number
      in
      Should be 1.
    • Optional pOut: Matrix4
      out
      The result of the composition of the matrices.

    Returns Matrix4

    pOut.

  • Computes the composition of this and pSecondTransform and stores the result in pOut.

    Any point P transformed by the resulting transformation will first be multiplied by this, and then pSecondTransform.
    Be P' the transformed point of P :
    Depending on your convention : P' = pSecondTransform x this x P (hence multiply left)
    or P' = P x this x pSecondTransform.


    If pOut is omitted, the result is stored in this.

    Parameters

    • pSecondTransform: Matrix4
      in
      The transform to apply after this when transforming points.
    • Optional pOut: Matrix4
      out
      The result of the composition of the matrices.

    Returns Matrix4

    pOut.

  • Computes the composition of pFirstTransform and this and stores the result in pOut.

    Any point P transformed by the resulting transformation will first be multiplied by pFirstTransform, and then this.
    Be P' the transformed point of P :
    Depending on your convention : P' = this x pFirstTransform x P (hence multiply right)
    or P' = P x pFirstTransform x this.


    If pOut is omitted, the result is stored in this.

    Parameters

    • pFirstTransform: Matrix4
      in
      The transform to apply first when transforming points.
    • Optional pOut: Matrix4
      out
      The result of the composition of the matrices.

    Returns Matrix4

    pOut.

  • Computes the composition of the matrix represented by the values Mval and this and stores the result in pOut.

    Any point P transformed by the resulting transformation will first be multiplied by Mval, and then this.
    Be P' the transformed point of P :
    Depending on your convention : P' = this x Mval x P (hence multiply right)
    or P' = P x Mval x this.

    If pOut is omitted, the result is stored in this.

    If you consider the matrix vector multiplication in line (V' = V x Mval), then Mval is set to (translation [T0,T1,T2] on the bottom) :

    abc0 (d)
    efg0 (h)
    ijk0 (l)
    T0 : mT1 : nT2 : o1 (p)

    If you consider the matrix vector multiplication in column (V' = Mval x V), then Mval is set (translation [T0,T1,T2] on the right) :
    aeiT0 : m
    bfjT1 : n
    cgkT2 : o
    0 (d)0 (h)0 (l)1 (p)


    Then when using Matrices :
    this.multiplyMatrixRight(pFirstTransform, pOut);
    

    is equivalent to :
    this.multiplyRight(
    pFirstTransform.array[0], pFirstTransform.array[1], pFirstTransform.array[2], pFirstTransform.array[3],
    pFirstTransform.array[4], pFirstTransform.array[5], pFirstTransform.array[6], pFirstTransform.array[7],
    pFirstTransform.array[8], pFirstTransform.array[9], pFirstTransform.array[10], pFirstTransform.array[11],
    pFirstTransform.array[12], pFirstTransform.array[13], pFirstTransform.array[14], pFirstTransform.array[15],
    pOut
    );

    Please refer to some matrices courses to get more information.

    Parameters

    • a: number
      in
      Rotation/scale part.
    • b: number
      in
      Rotation/scale part.
    • c: number
      in
      Rotation/scale part.
    • d: number
      in
      Should be 0.
    • e: number
      in
      Rotation/scale part.
    • f: number
      in
      Rotation/scale part.
    • g: number
      in
      Rotation/scale part.
    • h: number
      in
      Should be 0.
    • i: number
      in
      Rotation/scale part.
    • j: number
      in
      Rotation/scale part.
    • k: number
      in
      Rotation/scale part.
    • l: number
      in
      Should be 0.
    • m: number
      in
      Translation upon x.
    • n: number
      in
      Translation upon y.
    • o: number
      in
      Translation upon z.
    • p: number
      in
      Should be 1.
    • Optional pOut: Matrix4
      out
      The result of the composition of the matrices.

    Returns Matrix4

    pOut.

  • Computes the transformation of the vector pDirection by this matrix, and stores the result in pOut.

    pDirection is considered a direction and thus, this is equivalent to using multiplyVector4XYZW(pPoint[0],pPoint[1],pPoint[2],0).

    If pOut is omitted, then pDirection is changed in place.

    Returns pOut.

    Parameters

    • pDirection: Vector3
      in
      the vector3 to transform.
    • Optional pOut: Vector3
      out
      the resulting transformed vector.

    Returns Vector3

    pOut.

  • Computes the transformation of the vector (pX,pY,pZ) by this matrix, and stores the result in pOut.

    (pX,pY,pZ) is considered a direction and thus, this is equivalent to using multiplyVector4XYZW(pX,pY,pZ,0).

    Returns pOut.

    Parameters

    • pX: number
      in
      x coordinate of the vector3 to transform.
    • pY: number
      in
      y coordinate of the vector3 to transform.
    • pZ: number
      in
      z coordinate of the vector3 to transform.
    • pOut: Vector3
      out
      the resulting transformed vector.

    Returns Vector3

    pOut.

  • Computes the transformation of the vector pPoint by this matrix, and stores the result in pOut.

    pPoint is considered a point and thus, this is equivalent to using multiplyVector4XYZW(pPoint[0],pPoint[1],pPoint[2],1), and computing the homogeneous coordinates of the resulting Vector4 (i.e. dividing all coordinates by the w coordinate of the vector4).

    If pOut is omitted, then pPoint is changed in place.

    Returns pOut.

    Parameters

    • pPoint: Vector3
      in
      The vector3 to transform.
    • Optional pOut: Vector3
      out
      The resulting transformed vector.

    Returns Vector3

    pOut.

  • Computes the transformation of the vector (pX,pY,pZ) by this matrix, and stores the result in pOut.

    The vector (pX,pY,pZ) is considered a point and thus, this is equivalent to using multiplyVector4XYZW(pX,pY,pZ,1), and computing the homogeneous coordinates of the resulting Vector4 (i.e. dividing all coordinates by the w coordinate of the vector4).

    Returns pOut.

    Parameters

    • pX: number
      in
      x coordinate of the vector3 to transform.
    • pY: number
      in
      y coordinate of the vector3 to transform.
    • pZ: number
      in
      z coordinate of the vector3 to transform.
    • pOut: Vector3
      out
      the resulting transformed vector.

    Returns Vector3

    pOut.

  • Computes the transformation of pVector by this matrix, and stores the result in pOut.

    If pOut is omitted, then pVector is changed in place.

    Returns pOut.

    Parameters

    • pVector: Vector4
      in
      The vector4 to transform.
    • Optional pOut: Vector4
      out
      The resulting transformed vector.

    Returns Vector4

    pOut.

  • Computes the transformation of the vector (pX,pY,pZ,pW) by this matrix, and stores the result in pOut.

    Returns pOut.

    Parameters

    • pX: number
      in
      x coordinate of the vector4 to transform.
    • pY: number
      in
      y coordinate of the vector4 to transform.
    • pZ: number
      in
      z coordinate of the vector4 to transform.
    • pW: number
      in
      w coordinate of the vector4 to transform.
    • pOut: Vector4
      out
      The resulting transformed vector.

    Returns Vector4

    pOut.

  • Resets the matrix to be a scale (pX,pY,pZ).

    Parameters

    • pX: number
      in
      x component of the scale to set.
    • pY: number
      in
      y component of the scale to set.
    • pZ: number
      in
      z component of the scale to set.

    Returns this

    this.

  • Computes the rotation of this around the X axis and stores the result in pOut.

    This computes the composition of this and the rotation of pAngle around X.
    Any point P transformed by the resulting transformation will first be multiplied by this, and then the rotation around X.
    Be P' the transformed point of P, and Rx the rotation around X :
    Depending on your convention : P' = Rx x this x P
    or P' = P x this x Rx.

    If pOut is omitted, the result is stored in this.

    Parameters

    • pAngle: number
      in
      The angle in radian for the rotation around X.
    • Optional pOut: Matrix4
      out
      The result of the rotation of the matrix.

    Returns Matrix4

    pOut.

  • Computes the rotation of this around the Y axis and stores the result in pOut.

    This computes the composition of this and the rotation of pAngle around Y.
    Any point P transformed by the resulting transformation will first be multiplied by this, and then the rotation around Y.
    Be P' the transformed point of P, and Ry the rotation around Y :
    Depending on your convention : P' = Ry x this x P
    or P' = P x this x Ry.

    If pOut is omitted, the result is stored in this.

    Parameters

    • pAngle: number
      in
      The angle in radian for the rotation around Y.
    • Optional pOut: Matrix4
      out
      The result of the rotation of the matrix.

    Returns Matrix4

    pOut.

  • Computes the rotation of this around the Z axis and stores the result in pOut.

    This computes the composition of this and the rotation of pAngle around Z.
    Any point P transformed by the resulting transformation will first be multiplied by this, and then the rotation around Z.
    Be P' the transformed point of P, and Rz the rotation around Z :
    Depending on your convention : P' = Rz x this x P
    or P' = P x this x Rz.

    If pOut is omitted, the result is stored in this.

    Parameters

    • pAngle: number
      in
      The angle in radian for the rotation around Z.
    • Optional pOut: Matrix4
      out
      The result of the rotation of the matrix.

    Returns Matrix4

    pOut.

  • Sets values for the matrix.

    If you consider the matrix vector multiplication in line (V' = V x M), then the following matrix is set (translation [T0,T1,T2] on the bottom) :

    abc0 (d)
    efg0 (h)
    ijk0 (l)
    T0 : mT1 : nT2 : o1 (p)

    If you consider the matrix vector multiplication in column (V' = M x V), then the following matrix is set (translation [T0,T1,T2] on the right) :
    aeiT0 : m
    bfjT1 : n
    cgkT2 : o
    0 (d)0 (h)0 (l)1 (p)

    Returns `this`.

    Parameters

    • Optional a: number
      in
      Rotation/scale part.
    • Optional b: number
      in
      Rotation/scale part.
    • Optional c: number
      in
      Rotation/scale part.
    • Optional d: number
      in
      Should be 0.
    • Optional e: number
      in
      Rotation/scale part.
    • Optional f: number
      in
      Rotation/scale part.
    • Optional g: number
      in
      Rotation/scale part.
    • Optional h: number
      in
      Should be 0.
    • Optional i: number
      in
      Rotation/scale part.
    • Optional j: number
      in
      Rotation/scale part.
    • Optional k: number
      in
      Rotation/scale part.
    • Optional l: number
      in
      Should be 0.
    • Optional m: number
      in
      Translation upon x.
    • Optional n: number
      in
      Translation upon y.
    • Optional o: number
      in
      Translation upon z.
    • Optional p: number
      in
      Should be 1.

    Returns this

    this.

  • Sets the matrix to be the rotation from the given quaternion values [pX,pY,pZ,pW].

    The translation is reset to (0,0,0).

    Parameters

    • pX: number
      in
      x component of the quaternion.
    • pY: number
      in
      y component of the quaternion.
    • pZ: number
      in
      z component of the quaternion.
    • pW: number
      in
      w component of the quaternion.

    Returns this

    this.

  • Sets the matrix to be the rotation from the given quaternion values [pX,pY,pZ,pW].

    The translation is left unchanged.

    Parameters

    • pX: number
      in
      x component of the quaternion.
    • pY: number
      in
      y component of the quaternion.
    • pZ: number
      in
      z component of the quaternion.
    • pW: number
      in
      w component of the quaternion.

    Returns this

    this.

  • Sets the matrix to be the rotation from the given values.

    The translation is left unchanged.

    See set to get information on the memory layout.

    Returns this.

    Parameters

    • a: number
      in
      Rotation/scale part.
    • b: number
      in
      Rotation/scale part.
    • c: number
      in
      Rotation/scale part.
    • e: number
      in
      Rotation/scale part.
    • f: number
      in
      Rotation/scale part.
    • g: number
      in
      Rotation/scale part.
    • i: number
      in
      Rotation/scale part.
    • j: number
      in
      Rotation/scale part.
    • k: number
      in
      Rotation/scale part.

    Returns this

    this.

  • Sets the matrix to be the rotation from the given matrix.

    The translation is left unchanged.

    Parameters

    • pMatrix: Matrix4
      in
      The matrix to copy data from.

    Returns this

    this.

  • Resets the matrix to be a translation.

    The rotation/scale part is reset to the identity.

    Parameters

    • pX: number
      in
      x component of the translation.
    • pY: number
      in
      y component of the translation.
    • pZ: number
      in
      z component of the translation.

    Returns this

    this.

  • Sets the translation part of the matrix.

    The rotation/scale part is left unchanged.

    Parameters

    • pX: number
      in
      x component of the translation.
    • pY: number
      in
      y component of the translation.
    • pZ: number
      in
      z component of the translation.

    Returns this

    this.

  • Copies the translation part of the matrix.

    The rotation/scale part is left unchanged.

    Parameters

    • pMatrix: Matrix4
      in
      The matrix to copy.

    Returns this

    this.

  • Serializes the given Matrix4 to JSON.

    Parameters

    • Optional pKey: any
      in
      Unused.

    Returns Object

    The JSON representation of the object.

  • Computes the transpose of the rotation part. This is useful for inverting a rotation matrix.

    The translation is left unchanged (no copy of translation).

    Parameters

    • Optional pOutMatrix: Matrix4
      out
      The matrix that will receive the transpose (the translation part is left unchanged).

    Returns Matrix4

    pOutMatrix.