Skip to main content

Matrix4

A matrix with 4 rows and 4 columns

warning

This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.

For this entire page assume:

local myMat = matrices.mat4()

Math

add()

Adds the other matrix to this one

Returns self for chaining

add(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix4--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:add(matrices.mat4():scale(2))

sub()

Subtracts the other matrix from this one

Returns self for chaining

sub(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix4--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:sub(matrices.mat4():scale(2))

det()

Calculates and returns the determinant of this matrix

det()

Returns:

TypeDescription
Number-

Example:

myMat:det()

invert()

Inverts this matrix, changing the values inside

Returns self for chaining

invert()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:invert()

inverted()

Returns a copy of this matrix, but inverted

inverted()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:inverted()

multiply()

Multiplies this matrix by the other matrix, with the other matrix on the left

Returns self for chaining

multiply(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix4--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:multiply(matrices.mat4():scale(2))

rightMultiply()

Multiplies this matrix by the other matrix, with the other matrix on the right

Returns self for chaining

rightMultiply(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix4--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:rightMultiply(matrices.mat4():scale(2))

Accessors

getColumn()

Gets the given column of this matrix, as a vector

Indexing starts at 1, as usual

getColumn(col)

Parameters:

NameTypeDescriptionDefault
colInteger--

Returns:

TypeDescription
Vector4-

Example:

myMat:getColumn(1)

getRow()

Gets the given row of this matrix, as a vector

Indexing starts at 1, as usual

getRow(row)

Parameters:

NameTypeDescriptionDefault
rowInteger--

Returns:

TypeDescription
Vector4-

Example:

myMat:getRow(1)

Transformation

apply()

Treats the given values as a vector, augments this vector with a 1, multiplies it against the matrix, and returns a deaugmented vector of the first values

apply(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Vector3-

Example:

myMat:apply()

applyDir()

Treats the given values as a vector, augments this vector with a 0, multiplies it against the matrix, and returns a deaugmented vector of the first values

applyDir(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Vector3-

Example:

myMat:applyDir()

rotate()

Rotates this matrix by the specified amount, changing the values inside

Angles are given in degrees

Returns self for chaining

rotate(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:rotate(90, 90, 90)

rotateX()

Rotates this matrix around the X axis by the specified number of degrees

Returns self for chaining

rotateX(degrees)

Parameters:

NameTypeDescriptionDefault
degreesNumber--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:rotateX(90)

rotateY()

Rotates this matrix around the Y axis by the specified number of degrees

Returns self for chaining

rotateY(degrees)

Parameters:

NameTypeDescriptionDefault
degreesNumber--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:rotateY(90)

rotateZ()

Rotates this matrix around the Z axis by the specified number of degrees

Returns self for chaining

rotateZ(degrees)

Parameters:

NameTypeDescriptionDefault
degreesNumber--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:rotateZ(90)

scale()

Scales this matrix by the specified amount, changing the values inside

Returns self for chaining

scale(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:scale(2, 2, 2)

translate()

Translates this matrix by the specified amount, changing the values inside

Returns self for chaining

translate(vec)

Parameters:

NameTypeDescriptionDefault
vecVector3--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:translate(2, 2, 2)

transpose()

Transposes this matrix, changing the values inside

Transposing means to swap the rows and the columns

Returns self for chaining

transpose()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:transpose()

transposed()

Returns a copy of this matrix, but transposed

Transposing means to swap the rows and the columns

transposed()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:transposed()

Utility

set()

Sets this matrix to have the same values as the matrix passed in

Returns self for chaining

set(other)

Parameters:

NameTypeDescriptionDefault
otherMatrix4--

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:set()

copy()

Creates and returns a new copy of this matrix

copy()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:copy()

deaugmented()

Deaugments this matrix, removing a row and column

deaugmented()

Returns:

TypeDescription
Matrix3-

Example:

myMat:deaugmented()

reset()

Resets this matrix back to the identity matrix

Returns self for chaining

reset()

Returns:

TypeDescription
Matrix4Returns self for chaining

Example:

myMat:reset()