# Mat4

The Mat4 class represents a 4×4 matrix. Mat4 contains several helpful static functions, which can be called like this: Mat4.createRotation(quat)

Property Description
arr

The array that represents the matrix.

Function Description
rotate(x, y, z, angle)

Post-multiplies this matrix by the matrix corresponding to the specified rotation about the specified axis.

scale(x, y, z)

Post-multiplies this matrix by the matrix corresponding to the specified scale transformation.

translate(x, y, z)

Post-multiplies this matrix by the matrix corresponding to the specified translation.

Static Function Description
createIdentity()

Creates and returns a 4×4 identity matrix.

createOrthographic(left, right, bottom, top, near, far)

Creates an orthographic projection transformation matrix. The parameters form a rectangular cuboid that defines the visible area of rendering.

createRotation(quat)

Creates a rotation matrix based on the given Quaternion.

createTranslation(x, y, z)

Creates a translation matrix based on the given x, y, z coordinates.

inverse(matrix)

Returns the inverse of the given matrix.

multiply(matrix1, matrix2)

Multipies the given matrices together.

transformPoint(matrix, vector)

Transforms the specified point by this matrix, and returns the result.

transformVector(matrix, vector)

Transforms the specified vector by this matrix by treating the fourth (w) coordinate as zero, and returns the result.

## arr

array – the array that represents the matrix

## rotate(x, y, z, angle)

Post-multiplies this matrix by the matrix corresponding to the specified rotation about the specified axis.

### Parameters

number x – the x-axis to rotate about
number y – the y-axis to rotate about
number z – the z-axis to rotate about
number angle – the angle of the rotation (radians)

## scale(x, y, z)

Post-multiplies this matrix by the matrix corresponding to the specified scale transformation.

### Parameters

number x – the amount to scale along the x-axis
number y – the amount to scale along the y-axis
number z – the amount to scale along the z-axis

## translate(x, y, z)

Post-multiplies this matrix by the matrix corresponding to the specified translation.

### Parameters

number x – the amount to translate along the x-axis
number y – the amount to translate along the y-axis
number z – the amount to translate along the z-axis

## createIdentity()

Creates and returns a 4×4 identity matrix.

### Returns

Mat4 matrix – A new identity matrix

## createOrthographic(left, right, bottom, top, near, far)

Creates an orthographic projection transformation matrix. The parameters form a rectangular cuboid that defines the visible area of rendering.

### Parameters

number left – farthest left on the x-axis
number right – farthest right on the x-axis
number bottom – farthest down on the y-axis
number top – farthest up on the y-axis
number near – closest on the z-axis
number far – furthest on the z-axis

### Returns

Mat4 – the resulting orthographic projection matrix

## createRotation(quat)

Creates a rotation matrix based on the given Quaternion.

### Parameters

Quaternion quat – the Quaternion representation of the rotation

### Returns

Mat4 – the resulting rotation matrix

## createTranslation(x, y, z)

Creates a translation matrix based on the given x, y, z coordinates.

### Parameters

number x – the translation on the x-axis
number y – the translation on the y-axis
number z – the translation on the z-axis

### Returns

Mat4 – the resulting translation matrix

## inverse(matrix)

Returns the inverse of the given matrix.

### Parameters

Mat4 matrix – the matrix to be inverted

### Returns

Mat4 – the inverted matrix

## multiply(matrix1, matrix2)

Multipies the given matrices together.

### Parameters

Mat4 matrix1 – the first matrix to multiply
Mat4 matrix2 – the second matrix to multiply

### Parameters

Mat4 – the resulting matrix

## transformPoint(matrix, point)

Transforms the specified point by this matrix, and returns the result.

### Parameters

Mat4 matrix – the transformation matrix
Vec3 point – the point to transform

### Returns

Vec3 – the transformed point

## transformVector(matrix, vector)

Transforms the specified vector by this matrix by treating the fourth (w) coordinate as zero, and returns the result.

### Parameters

Mat4 matrix – the transformation matrix
Vec3 vector – the vector to transform

### Returns

Vec3 – the transformed vector