Open Source Cross-Platform Game Programming

Matricies

Library for performing operations on matrices.

class Matrix[link]

Represents an n by m matrix of floats.

new Matrix(rows, cols)[link]

Creates a new matrix

Arguments

NameTypeDescription
rows integer

Number of rows

cols integer

Number of columns

function addMatrix(other, output)[link]

Adds another matrix to this matrix and writes it to the optional output matrix

Arguments

NameTypeOptionalDescription
other Matrix

The matrix to add to this matrix.

output Matrix Optional

The matrix to write the result to. If this is not provided, the new values will be written to the original Matrix.

Return Value

TypeDescription
Matrix

Returns a reference to the original matrix so that chaining can be used.

function copyFrom(other)[link]

Copies the values of one matrix into another.

Arguments

NameTypeDescription
other Matrix

The matrix to copy values from. Must be the same size.

Return Value

TypeDescription
Matrix

Returns a reference to the original matrix so that chaining can be used.

function getValue(row, col)[link]

Gets the value at the given column and row

Arguments

NameTypeDescription
row integer

row

col integer

column

Return Value

TypeDescription
float

Float located at that coordinate

function multiplyByMatrix(other, output)[link]

Multiplies another matrix to this matrix and writes it to the optional output matrix. Dimensions must be correct.

Arguments

NameTypeOptionalDescription
other Matrix

The matrix to multiply this matrix by.

output Matrix Optional

The matrix to write the result to. If this is not provided, the new values will be written to the original Matrix ONLY if the matrix is square. Otherwise, an error will be thrown.

Return Value

TypeDescription
Matrix

Returns a reference to the original matrix so that chaining can be used.

function multiplyByScalar(value)[link]

Multiplies all values in the matrix by a scalar

Arguments

NameTypeDescription
value float

The scalar value to multiply by.

Return Value

TypeDescription
Matrix

Returns a reference to the original matrix so that chaining can be used.

function newIdentityMatrix(n)[link]

Generates a new n by n identity matrix.

Arguments

NameTypeDescription
n integer

The size of the matrix (it's a square).

Return Value

TypeDescription
Matrix

A new identity matrix instance

function setValue(row, col, value)[link]

Sets a value at the given column and row

Arguments

NameTypeDescription
row integer

row

col integer

column

value float

The value to set

Return Value

TypeDescription
Matrix

Returns a reference to the original matrix so that chaining can be used.

function toVector(output)[link]

Flattens the matrix into a single dimensional list. Values are written starting from the top left corner and go left-to-right first, then row-by-row down.

Arguments

NameTypeDescription
output List of floats

A list to write to. Values are written starting from position 0. If the list is not long enough, values will be added. If the list is longer than the number of elements in the matrix, the remaining values are left alone.

Return Value

TypeDescription
List of floats

Returns the list.