Class Matrix4

A 4x4 Matrix.

example

// Simple rig for rotating around 3 axes var m = new THREE.Matrix4(); var m1 = new THREE.Matrix4(); var m2 = new THREE.Matrix4(); var m3 = new THREE.Matrix4(); var alpha = 0; var beta = Math.PI; var gamma = Math.PI/2; m1.makeRotationX( alpha ); m2.makeRotationY( beta ); m3.makeRotationZ( gamma ); m.multiplyMatrices( m1, m2 ); m.multiply( m3 );

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): Matrix4

Creates an identity matrix.

Returns

Matrix4

constructor(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

Initialises the matrix with the supplied n11..n44 values.

Parameters

  • 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

Returns

Matrix4

Properties

public elements: Float32Array

Float32Array with matrix values.

Methods

public applyToVector3Array(array: Array<number>, offset?: number, length?: number): Array<number>

Parameters

  • array: Array<number>
  • offset?: number optional
  • length?: number optional

Returns

Array<number>

public clone(): Matrix4

Clones this matrix.

Returns

Matrix4

public compose(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4

Sets this matrix to the transformation composed of translation, rotation and scale.

Parameters

Returns

Matrix4

public copy(m: Matrix4): Matrix4

Copies a matrix m into this matrix.

Parameters

Returns

Matrix4

public copyPosition(m: Matrix4): Matrix4

Parameters

Returns

Matrix4

public decompose(translation?: Vector3, rotation?: Quaternion, scale?: Vector3): Array<Object>

Decomposes this matrix into the translation, rotation and scale components. If parameters are not passed, new instances will be created.

Parameters

Returns

Array<Object>

public determinant(): number

Computes determinant of this matrix. Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm

Returns

number

public extractRotation(m: Matrix4): Matrix4

Copies the rotation component of the supplied matrix m into this matrix rotation component.

Parameters

Returns

Matrix4

public flattenToArrayOffset(array: Array<number>, offset: number): Array<number>

Flattens this matrix into supplied flat array starting from offset position in the array.

Parameters

  • array: Array<number>
  • offset: number

Returns

Array<number>

public getInverse(m: Matrix4, throwOnInvertible?: boolean): Matrix4

Sets this matrix to the inverse of matrix m. Based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm.

Parameters

  • m: Matrix4
  • throwOnInvertible?: boolean optional

Returns

Matrix4

public getMaxScaleOnAxis(): number

Returns

number

public identity(): Matrix4

Resets this matrix to identity.

Returns

Matrix4

public lookAt(eye: Vector3, target: Vector3, up: Vector3): Matrix4

Constructs a rotation matrix, looking from eye towards center with defined up vector.

Parameters

Returns

Matrix4

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

Creates a frustum matrix.

Parameters

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

Returns

Matrix4

public makeOrthographic(left: number, right: number, top: number, bottom: number, near: number, far: number): Matrix4

Creates an orthographic projection matrix.

Parameters

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

Returns

Matrix4

public makePerspective(fov: number, aspect: number, near: number, far: number): Matrix4

Creates a perspective projection matrix.

Parameters

  • fov: number
  • aspect: number
  • near: number
  • far: number

Returns

Matrix4

public makeRotationAxis(axis: Vector3, angle: number): Matrix4

Sets this matrix as rotation transform around axis by angle radians. Based on http://www.gamedev.net/reference/articles/article1199.asp.

Parameters

  • axis: Vector3

    Rotation axis.

  • angle: number

Returns

Matrix4

public makeRotationFromEuler(euler: Euler): Matrix4

Parameters

Returns

Matrix4

public makeRotationFromQuaternion(q: Quaternion): Matrix4

Parameters

Returns

Matrix4

public makeRotationX(theta: number): Matrix4

Sets this matrix as rotation transform around x axis by theta radians.

Parameters

  • theta: number

    Rotation angle in radians.

Returns

Matrix4

public makeRotationY(theta: number): Matrix4

Sets this matrix as rotation transform around y axis by theta radians.

Parameters

  • theta: number

    Rotation angle in radians.

Returns

Matrix4

public makeRotationZ(theta: number): Matrix4

Sets this matrix as rotation transform around z axis by theta radians.

Parameters

  • theta: number

    Rotation angle in radians.

Returns

Matrix4

public makeScale(x: number, y: number, z: number): Matrix4

Sets this matrix as scale transform.

Parameters

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

Returns

Matrix4

public makeTranslation(x: number, y: number, z: number): Matrix4

Sets this matrix as translation transform.

Parameters

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

Returns

Matrix4

public multiply(m: Matrix4): Matrix4

Multiplies this matrix by m.

Parameters

Returns

Matrix4

public multiplyMatrices(a: Matrix4, b: Matrix4): Matrix4

Sets this matrix to a x b.

Parameters

Returns

Matrix4

public multiplyScalar(s: number): Matrix4

Multiplies this matrix by s.

Parameters

  • s: number

Returns

Matrix4

public multiplyToArray(a: Matrix4, b: Matrix4, r: Array<number>): Matrix4

Sets this matrix to a x b and stores the result into the flat array r. r can be either a regular Array or a TypedArray.

Parameters

Returns

Matrix4

public multiplyVector3Array(a: Array<number>): Array<number>

Parameters

  • a: Array<number>

Returns

Array<number>

public scale(v: Vector3): Matrix4

Multiplies the columns of this matrix by vector v.

Parameters

Returns

Matrix4

public 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 all fields of this matrix.

Parameters

  • 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

Returns

Matrix4

public setPosition(v: Vector3): Vector3

Sets the position component for this matrix from vector v.

Parameters

Returns

Vector3

public transpose(): Matrix4

Transposes this matrix.

Returns

Matrix4