Matrices

Matrices

Matrix 2x2 00 01 10 11 Each column represents an axis in a rotation matrix.

Re-exports: Vectors

Types

Functions and constants

public constant ZERO22 = mat2(0, 0, 0, 0)
public constant IDENTITY22 = mat2( 1, 0,
public constant ZERO33 = mat3(0, 0, 0, 0, 0, 0, 0, 0, 0)
public constant IDENTITY33 = mat3( 1, 0, 0,
public constant ZERO44 = mat4( 0, 0, 0, 0,
public constant IDENTITY44 = mat4( 1, 0, 0, 0,
public function mat2.op_plus(mat2 m) returns mat2
public function mat2.op_minus(mat2 m) returns mat2
public function mat2.op_minus(real scalar) returns mat2
public function mat2.op_plus(real scalar) returns mat2
public function mat2.op_mult(real scalar) returns mat2
public function real.op_mult(mat2 m) returns mat2
public function mat2.op_mult(vec2 v) returns vec2

Matrix multiplication is not commutative that means matrix * vect is not the same as vec * matrix.

public function vec2.op_mult(mat2 m) returns vec2

Matrix multiplication is not commutative that means matrix * vect is not the same as vec * matrix.

public function mat2.op_mult(mat2 m) returns mat2
public function mat2.col(int index) returns vec2

Returns matrix’ column by index as a vector or raises an error if it doesn’t exist.

public function mat2.row(int index) returns vec2

Returns matrix’ row by index as a vector or raises an error if it doesn’t exist.

public function mat2.determinant() returns real
public function mat2.transpose() returns mat2

Flips the matrix over its main diagonal. Result of transposing for rotation matrix is its inverse matrix.

public function mat2.inverse() returns inverseresult22

Finds inverse matrix. Returns tuple inverseresult22(bool success, mat2 matrix) where ‘success’ is true if the inverse matrix exists and ‘matrix’ is the inverse matrix. If there’s no inverse matrix ‘success’ is false and ‘matrix’ is zero matrix.

public function mat2.toString() returns string
public function angle.toRotation() returns mat2

Creates rotation matrix from angle.

public function vec2.toScaling() returns mat2

Creates scaling 2x2 matrix from a vector.

public function mat3.op_plus(mat3 m) returns mat3
public function mat3.op_plus(real scalar) returns mat3
public function mat3.op_minus(mat3 m) returns mat3
public function mat3.op_minus(real scalar) returns mat3
public function mat3.op_mult(real scalar) returns mat3
public function real.op_mult(mat3 m) returns mat3
public function mat3.op_mult(vec3 v) returns vec3

Matrix multiplication is not commutative that means matrix * vect is not the same as vec * matrix.

public function vec3.op_mult(mat3 m) returns vec3
public function mat3.op_mult(mat3 m) returns mat3
public function mult(mat4 m) returns mat4

Due to parameter restriction you need to set tmp_mat as one matrix before multiplying. *

public function mat3.col(int index) returns vec3

Returns matrix’ column by index as a vector or raises an error if it doesn’t exist.

public function mat3.row(int index) returns vec3

Returns matrix’ row by index as a vector or raises an error if it doesn’t exist.

public function mat3.trace() returns real

The sum of the main diagonal terms.

public function mat3.determinant() returns real
public function mat3.transpose() returns mat3

Flips the matrix over its main diagonal. Result of transposing for rotation matrix is its inverse matrix.

public function mat3.inverse() returns inverseresult33

Finds inverse matrix. Returns tuple inverseresult33(bool success, mat3 matrix) where ‘success’ is true if the inverse matrix exists and ‘matrix’ is the inverse matrix. If there’s no inverse matrix ‘success’ is false and ‘matrix’ is zero matrix.

public function mat3.toEuler() returns vec3

Extracts Euler-angles (Tait-Bryan) in radians from a rotation matrix. Order of the result is Z-Y-X (Yaw-Pitch-Roll).

public function mat3.toString() returns string
public function vec3.toRotation(angle angl) returns mat3

Creates 3x3 rotation matrix from axis and angle.

public function angle.toRotation(vec3 axis) returns mat3

Creates 3x3 rotation matrix from axis and angle.

public function angle.toRotationX() returns mat3

Creates 3x3 rotation matrix around X-axis from angle.

public function angle.toRotationY() returns mat3

Creates 3x3 rotation matrix around Y-axis from angle.

public function angle.toRotationZ() returns mat3

Creates 3x3 rotation matrix around Z-axis from angle.

public function vec3.toScaling() returns mat3

Creates 3x3 scaling matrix from a vector.

public function vec2.toTranslation() returns mat3

Creates translation 3x3 matrix from a vector that represents an offset. Use it with vec3 that represents 2D point.

public function vec3.project(mat4 matrix) returns vec3

Multiplies this vector by the given matrix dividing by w, assuming the fourth (w) component of the vector is 1. This is * mostly used to project/unproject vectors via a perspective projection matrix. *

public function getProjection(real near, real far, real fovy, real aspectRatio) returns mat4

Sets the matrix to a projection matrix with a near- and far plane, a field of view in degrees and an aspect ratio. Note that

  • the field of view specified is the angle in degrees for the height, the field of view for the width will be calculated
  • according to the aspect ratio.
public function setToTranslation(real x, real y, real z) returns mat4

Sets this matrix to a translation matrix, overwriting it first by an identity matrix and then setting the 4th column to the * translation vector.

public function setToLookAt(vec3 position, vec3 target, vec3 up) returns mat4

Sets this matrix to a look at matrix with the given position, target and up vector.

public function setToLookAt(vec3 direction, vec3 up) returns mat4

Sets the matrix to a look at matrix with a direction and an up vector. Multiply with a translation matrix to get a camera * model view matrix.

public function mat4.determinant() returns real
public function mat4.inverse() returns inverseresult44

Finds inverse matrix. Returns tuple inverseresult44(bool success, mat4 matrix) where ‘success’ is true if the inverse matrix exists and ‘matrix’ is the inverse matrix. If there’s no inverse matrix ‘success’ is false and ‘matrix’ is zero matrix.

public function mat4.toString() returns string
public function mat2.assertEquals(mat2 expected)
public function mat3.assertEquals(mat3 expected)