# B.Math.Matrix4()

Represents a column-major 4x4 matrix.

make / set: representation: array accessor:
m00, m01, m02, m03 axisX.x, axisY.x, axisZ.x, position.x m[0], m[4], m[08], m[12]
m10, m11, m12, m13 = axisX.y, axisY.y, axisZ.y, position.y = m[1], m[5], m[09], m[13]
m20, m21, m22, m23 axisX.z, axisY.z, axisZ.z, position.z m[2], m[6], m[10], m[14]
m30, m31, m32, m33 0, 0, 0, 1 m[3], m[7], m[11], m[15]

To create the object use B.Math.makeMatrix4().

Note: the order of transformations coincides with the order in which the matrices are multiplied (from left to right).

## CONSTANTS:

ZERO = [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0]

Zero matrix.

IDENTITY = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]

Identity matrix.

## PROPERTIES:

{Array.<number>} m

Matrix element array.

## METHODS:

clone()

Clones this matrix to a new matrix.

### RETURNS:

this

copy(matrix)

Copies a given matrix into this matrix.

matrix

### RETURNS:

this

set(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33)

Sets all elements of this matrix.

{number} m00

{number} m01

{number} m02

{number} m03

{number} m10

{number} m11

{number} m12

{number} m13

{number} m20

{number} m21

{number} m22

{number} m23

{number} m30

{number} m31

{number} m32

{number} m33

### RETURNS:

this

get(row, column)

Gets an element by its row and column indices.

{number} row

index [0, 3]

{number} column

index [0, 3]

{number}

### THROWS:

{Error}

if the index is out of range.

setMatrix3(matrix)

Sets 3x3 top left part of this matrix.

matrix

### RETURNS:

this

getMatrix3(result)

Returns 3x3 top left part of this matrix.

### PARAMETERS:

[result]

omit if you want to return newly created matrix

### RETURNS:

setAxisX(axis)

Sets the X-axis vector.

axis

### RETURNS:

this

getAxisX(result)

Returns the X-axis vector.

### PARAMETERS:

[result]

omit if you want to return newly created vector

### RETURNS:

setAxisY(axis)

Sets the Y-axis vector.

axis

### RETURNS:

this

getAxisY(result)

Returns the Y-axis vector.

### PARAMETERS:

[result]

omit if you want to return newly created vector

### RETURNS:

setAxisZ(axis)

Sets the Z-axis vector.

axis

### RETURNS:

this

getAxisZ(result)

Returns the Z-axis vector.

### PARAMETERS:

[result]

omit if you want to return newly created vector

### RETURNS:

setPosition(position)

Sets the position vector.

position

### RETURNS:

this

getPosition(result)

Returns the position vector.

### PARAMETERS:

[result]

omit if you want to return newly created vector

### RETURNS:

extractScale(result)

Extracts scale factors.

### PARAMETERS:

[result]

omit if you want to return newly created vector

### RETURNS:

fromArray(array, offset)

Sets this matrix elements from a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

toArray(array, offset)

Sets this matrix elements to a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

fromAngles(angles)

Sets this matrix from Euler angles.

angles

### RETURNS:

this

fromQuaternion(q)

Sets this matrix from a quaternion.

### RETURNS:

this

identity()

Sets this matrix to the identity.

### RETURNS:

this

translation(x, y, z)

Sets this matrix to translation transform.

{number} x

{number} y

{number} z

### RETURNS:

this

rotationX(angle)

Sets this matrix to X-axis rotation transform.

{number} angle

### RETURNS:

this

rotationY(angle)

Sets this matrix to Y-axis rotation transform.

{number} angle

### RETURNS:

this

rotationZ(angle)

Sets this matrix to Z-axis rotation transform.

{number} angle

### RETURNS:

this

rotationAxis(axis, angle)

Sets this matrix to arbitrary axis rotation transform.

axis

{number} angle

### RETURNS:

this

scale(x, y, z)

Sets this matrix to scale transform.

{number} x

{number} y

{number} z

### RETURNS:

this

lookAt(eye, target, up)

Sets this matrix to right-handed view transform.

eye

target

up

### RETURNS:

this

orthographic(width, height, zNear, zFar)

Sets this matrix to orthographic projection transform.

{number} width

{number} height

{number} zNear

{number} zFar

### RETURNS:

this

perspective(fov, aspect, zNear, zFar)

Sets this matrix to perspective projection transform.

### PARAMETERS:

{number} fov

field of view angle

{number} aspect

output surface width to height ratio

{number} zNear

{number} zFar

### RETURNS:

this

Adds a matrix to this matrix.

matrix

### RETURNS:

this

mulScalar(scalar)

Multiplies this matrix by a given scalar.

{number} scalar

### RETURNS:

this

mulMatrices(a, b)

Multiplies two given matrices and sets the result to this.

### RETURNS:

this

mul(value)

Multiplies this matrix by a given matrix or a scalar.

### PARAMETERS:

{number | B.Math.Matrix4} value

### RETURNS:

this

determinant()

Calculates the determinant of this matrix.

### RETURNS:

{number}

transpose()

Transposes this matrix.

### RETURNS:

this

invert()

Inverts this matrix.

this

### THROWS:

{Error}

if determinant is zero.

equal(matrix)

Checks for strict equality of this matrix and another matrix.

matrix

{boolean}