Home Reference Source
import {Matrix4} from 'math-ds'
public class | source

Matrix4

A 4x4 matrix.

Constructor Summary

Public Constructor
public

Constructs a new matrix.

Member Summary

Public Members
public

The matrix elements.

Method Summary

Public Methods
public

Clones this matrix.

public

compose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4

Sets this matrix based on the given position, rotation and scale.

public

copy(matrix: Matrix4): Matrix4

Copies the values of a given matrix.

public

Copies the position values of a given matrix.

public

decompose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4

Decomposes this matrix into a position, rotation and scale vector.

public

Calculates the determinant of this matrix.

public

Checks if this matrix equals the given one.

public

extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4

Extracts the basis from this matrix.

public

Extracts the rotation from a given matrix.

public

fromArray(array: Number[], offset: Number): Matrix4

Copies the values of a given array.

public

Inverts the given matrix and stores the result in this matrix.

public

Returns the largest scale.

public

Sets this matrix to the identity matrix.

public

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

Creates a rotation that looks at the given target.

public

makeBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4

Sets the basis of this matrix.

public

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

Creates an orthographic matrix.

public

makePerspective(left: Number, right: Number, top: Number, bottom: Number, near: Number, far: Number): Matrix4

Creates a perspective matrix.

public

Makes this matrix a translation matrix with respect to a specific axis.

public

Sets the matrix rotation based on the given Euler angles.

public

Sets the matrix rotation based on the given quaternion.

public

Makes this matrix a rotation matrix.

public

Makes this matrix a rotation matrix with respect to the Y-axis.

public

Makes this matrix a rotation matrix with respect to the Z-axis.

public

Makes this matrix a scale matrix.

public

Makes this matrix a shear matrix.

public

Makes this matrix a translation matrix.

public

Multiplies this matrix with the given one.

public

Sets this matrix to the product of the given matrices.

public

Multiplies this matrix with a given scalar.

public

Multiplies a given matrix with this one.

public

scale(sx: Number, sy: Number, sz: Number): Matrix4

Scales this matrix.

public

set(n00: Number, n01: Number, n02: Number, n03: Number, n10: Number, n11: Number, n12: Number, n13: Number, n20: Number, n21: Number, n22: Number, n23: Number, n30: Number, n31: Number, n32: Number, n33: Number): Matrix4

Sets the values of this matrix.

public

Sets the position values of this matrix.

public

toArray(array: Number[], offset: Number): Number[]

Stores this matrix in an array.

public

Transposes this matrix.

Public Constructors

public constructor() source

Constructs a new matrix.

Public Members

public elements: Float32Array source

The matrix elements.

Public Methods

public clone(): Matrix4 source

Clones this matrix.

Return:

Matrix4

A clone of this matrix.

public compose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4 source

Sets this matrix based on the given position, rotation and scale.

Params:

NameTypeAttributeDescription
position Vector3

The position.

quaternion Quaternion

The rotation.

scale Vector3

The scale.

Return:

Matrix4

This matrix.

public copy(matrix: Matrix4): Matrix4 source

Copies the values of a given matrix.

Params:

NameTypeAttributeDescription
matrix Matrix4

A matrix.

Return:

Matrix4

This matrix.

public copyPosition(matrix: Matrix4): Matrix4 source

Copies the position values of a given matrix.

Params:

NameTypeAttributeDescription
matrix Matrix4

A matrix.

Return:

Matrix4

This matrix.

public decompose(position: Vector3, quaternion: Quaternion, scale: Vector3): Matrix4 source

Decomposes this matrix into a position, rotation and scale vector.

Params:

NameTypeAttributeDescription
position Vector3

The target position.

quaternion Quaternion

The target rotation.

scale Vector3

The target scale.

Return:

Matrix4

This matrix.

public determinant(): Number source

Calculates the determinant of this matrix.

For more details see: http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm

Return:

Number

The determinant.

public equals(m: Matrix4): Boolean source

Checks if this matrix equals the given one.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Boolean

Whether the matrix are equal.

public extractBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4 source

Extracts the basis from this matrix.

Params:

NameTypeAttributeDescription
xAxis Vector3

A vector to store the X-axis column in.

yAxis Vector3

A vector to store the Y-axis column in.

zAxis Vector3

A vector to store the Z-axis column in.

Return:

Matrix4

This matrix.

public extractRotation(m: Matrix4): Matrix4 source

Extracts the rotation from a given matrix.

This method does not support reflection matrices.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Matrix4

This matrix.

public fromArray(array: Number[], offset: Number): Matrix4 source

Copies the values of a given array.

Params:

NameTypeAttributeDescription
array Number[]

An array.

offset Number
  • optional
  • default: 0

An offset into the array.

Return:

Matrix4

This matrix.

public getInverse(matrix: Matrix4): Matrix4 source

Inverts the given matrix and stores the result in this matrix.

For details see: http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm

Params:

NameTypeAttributeDescription
matrix Matrix4

The matrix that should be inverted.

Return:

Matrix4

This matrix.

public getMaxScaleOnAxis(): Number source

Returns the largest scale.

Return:

Number

The largest scale of the three axes.

public identity(): Matrix4 source

Sets this matrix to the identity matrix.

Return:

Matrix4

This matrix.

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

Creates a rotation that looks at the given target.

Params:

NameTypeAttributeDescription
eye Vector3

The position of the eye.

target Vector3

The target to look at.

up Vector3

The up vector.

Return:

Matrix4

This matrix.

public makeBasis(xAxis: Vector3, yAxis: Vector3, zAxis: Vector3): Matrix4 source

Sets the basis of this matrix.

Params:

NameTypeAttributeDescription
xAxis Vector3

The X-axis.

yAxis Vector3

The Y-axis.

zAxis Vector3

The Z-axis.

Return:

Matrix4

This matrix.

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

Creates an orthographic matrix.

Params:

NameTypeAttributeDescription
left Number

The distance to the left plane.

right Number

The distance to the right plane.

top Number

The distance to the top plane.

bottom Number

The distance to the bottom plane.

near Number

The distance to the near plane.

far Number

The distance to the far plane.

Return:

Matrix4

This matrix.

public makePerspective(left: Number, right: Number, top: Number, bottom: Number, near: Number, far: Number): Matrix4 source

Creates a perspective matrix.

Params:

NameTypeAttributeDescription
left Number

The distance to the left plane.

right Number

The distance to the right plane.

top Number

The distance to the top plane.

bottom Number

The distance to the bottom plane.

near Number

The distance to the near plane.

far Number

The distance to the far plane.

Return:

Matrix4

This matrix.

public makeRotationAxis(axis: Vector3, angle: Number): Matrix4 source

Makes this matrix a translation matrix with respect to a specific axis.

For mor einformation see: http://www.gamedev.net/reference/articles/article1199.asp

Params:

NameTypeAttributeDescription
axis Vector3

The axis. Assumed to be normalized.

angle Number

The angle in radians.

Return:

Matrix4

This matrix.

public makeRotationFromEuler(euler: Euler): Matrix4 source

Sets the matrix rotation based on the given Euler angles.

Params:

NameTypeAttributeDescription
euler Euler

The euler angles.

Return:

Matrix4

This matrix.

public makeRotationFromQuaternion(q: Quaternion): Matrix4 source

Sets the matrix rotation based on the given quaternion.

Params:

NameTypeAttributeDescription
q Quaternion

The quaternion.

Return:

Matrix4

This matrix.

public makeRotationX(theta: Number): Matrix4 source

Makes this matrix a rotation matrix.

Params:

NameTypeAttributeDescription
theta Number

The angle in radians.

Return:

Matrix4

This matrix.

public makeRotationY(theta: Number): Matrix4 source

Makes this matrix a rotation matrix with respect to the Y-axis.

Params:

NameTypeAttributeDescription
theta Number

The angle in radians.

Return:

Matrix4

This matrix.

public makeRotationZ(theta: Number): Matrix4 source

Makes this matrix a rotation matrix with respect to the Z-axis.

Params:

NameTypeAttributeDescription
theta Number

The angle in radians.

Return:

Matrix4

This matrix.

public makeScale(x: Number, y: Number, z: Number): Matrix4 source

Makes this matrix a scale matrix.

Params:

NameTypeAttributeDescription
x Number

The X scale.

y Number

The Y scale.

z Number

The Z scale.

Return:

Matrix4

This matrix.

public makeShear(x: Number, y: Number, z: Number): Matrix4 source

Makes this matrix a shear matrix.

Params:

NameTypeAttributeDescription
x Number

The X shear value.

y Number

The Y shear value.

z Number

The Z shear value.

Return:

Matrix4

This matrix.

public makeTranslation(x: Number, y: Number, z: Number): Matrix4 source

Makes this matrix a translation matrix.

Params:

NameTypeAttributeDescription
x Number

The X offset.

y Number

The Y offset.

z Number

The Z offset.

Return:

Matrix4

This matrix.

public multiply(m: Matrix4): Matrix4 source

Multiplies this matrix with the given one.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Matrix4

This matrix.

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

Sets this matrix to the product of the given matrices.

Params:

NameTypeAttributeDescription
a Matrix4

A matrix.

b Matrix4

A matrix.

Return:

Matrix4

This matrix.

public multiplyScalar(s: Number): Matrix4 source

Multiplies this matrix with a given scalar.

Params:

NameTypeAttributeDescription
s Number

A scalar.

Return:

Matrix4

This matrix.

public premultiply(m: Matrix4): Matrix4 source

Multiplies a given matrix with this one.

Params:

NameTypeAttributeDescription
m Matrix4

A matrix.

Return:

Matrix4

This matrix.

public scale(sx: Number, sy: Number, sz: Number): Matrix4 source

Scales this matrix.

Params:

NameTypeAttributeDescription
sx Number

The X scale.

sy Number

The Y scale.

sz Number

The Z scale.

Return:

Matrix4

This matrix.

public set(n00: Number, n01: Number, n02: Number, n03: Number, n10: Number, n11: Number, n12: Number, n13: Number, n20: Number, n21: Number, n22: Number, n23: Number, n30: Number, n31: Number, n32: Number, n33: Number): Matrix4 source

Sets the values of this matrix.

Params:

NameTypeAttributeDescription
n00 Number

The value of the first row, first column.

n01 Number

The value of the first row, second column.

n02 Number

The value of the first row, third column.

n03 Number

The value of the first row, fourth column.

n10 Number

The value of the second row, first column.

n11 Number

The value of the second row, second column.

n12 Number

The value of the second row, third column.

n13 Number

The value of the second row, fourth column.

n20 Number

The value of the third row, first column.

n21 Number

The value of the third row, second column.

n22 Number

The value of the third row, third column.

n23 Number

The value of the third row, fourth column.

n30 Number

The value of the fourth row, first column.

n31 Number

The value of the fourth row, second column.

n32 Number

The value of the fourth row, third column.

n33 Number

The value of the fourth row, fourth column.

Return:

Matrix4

This matrix.

public setPosition(p: Vector3): Matrix4 source

Sets the position values of this matrix.

Params:

NameTypeAttributeDescription
p Vector3

A position.

Return:

Matrix4

This matrix.

public toArray(array: Number[], offset: Number): Number[] source

Stores this matrix in an array.

Params:

NameTypeAttributeDescription
array Number[]
  • optional

A target array.

offset Number
  • optional
  • default: 0

An offset into the array.

Return:

Number[]

The array.

public transpose(): Matrix4 source

Transposes this matrix.

Return:

Matrix4

This matrix.