matrix

class guerilla.matrix

Bases: object

A 4x4 transformation matrix

asarray()

Converts the matrix as an array table of 16 numbers

Returns:The corresponding array of numbers
Return type:{number}
compose(other)

Returns the composition of the two matrices

self will be applied first, then other.

Parameters:other (matrix) –
Return type:matrix
copy(source)

Copy the source matrix into this matrix

Parameters:source (matrix) – The matrix to copy
static createcomposite(sx, sy, sz, rx, ry, rz, tx, ty, tz)

Create the composite matrix using scale, rotation and translation. The scale factors are first applied, then x rotation, y rotation and z rotation, and the the translation is applied.

Parameters:
  • sx (number) – The x scale
  • sy (number) – The y scale
  • sz (number) – The z scale
  • rx (number) – The x rotation angle in radian
  • ry (number) – The y rotation angle in radian
  • rz (number) – The z rotation angle in radian
  • tx (number) – The x translation
  • ty (number) – The y translation
  • tz (number) – The z translation
Return type:

matrix

static createfromarray(array)

Create a new matrix object from a array table of numbers

Parameters:array ({number}) – The source array table of numbers
Returns:The new matrix object
Return type:matrix
static createlookat(pos, target, roll, up, direction)

Compute a lookat matrix. pos and target must be specified. rool OR up can be specified.

Parameters:
  • pos (point3) – The position
  • target (point3) – The position to aim
  • roll (float) – The roll angle in radian or nil
  • up (point3) – The up vector or nil
  • direction (str) – The lookup direction. Can be nil, “z” or “-z”. Default is “z”.
Returns:

The lookup matrix

Return type:

matrix

decompose()

Decompose the matrix into scale, rotation and translation components.

Returns:The decomposed matrix components
Return type:number
equals(other)

Compares this matrix to other matrix.

Parameters:other (matrix) –
Returns:True if all values of the matrices are equal
Return type:bool
static fromarray(array)

Create a new matrix object from a array table of numbers

Parameters:array ({number}) – The source array table of numbers
Returns:The new matrix object
Return type:matrix
geti()

Return the i direction of the matrix.

Return type:point3
getinverted()

Return the inverted matrix.

Return type:matrix
getj()

Return the j direction of the matrix.

Return type:point3
getk()

Return the k direction of the matrix.

Return type:point3
gettranslation()

Return the translation of the matrix.

Return type:point3
gettransposed()

Return the transposed matrix.

Return type:matrix
lookat(position, target, up)

Set the matrix to look from position to target with up as roll.

Parameters:
  • position (point3) – The viewing position
  • target (point3) – The target position
  • up (point3) – The up vectory
normalize()

Normalize the line components of the matrix.

pivot(axis, angle, pivot)

Rotate this matrix around around a pivot, an axis and an angle in radian

Parameters:
  • axis (point3) – The rotation axis
  • angle (number) – The rotation angle in radian
  • pivot (point3) – The rotation pivot
rotate(axis, angle)

Rotate the matrix around an axis with an angle in radian

Parameters:
  • axis (point3) – The rotation axis
  • angle (number) – The rotation angle
rotatex(angle)

Rotate the matrix around the x axis.

Parameters:angle (number) – The rotation angle in radians
rotatey(angle)

Rotate the matrix around the y axis.

Parameters:angle (number) – The rotation angle in radians
rotatez(angle)

Rotate the matrix around the z axis.

Parameters:angle (number) – The rotation angle in radians
scale(scalex, scaley, scalez)

Scale the matrix on all axises.

Parameters:
  • scalex (number) – The scale factor on x axis
  • scaley (number) – The scale factor on y axis
  • scalez (number) – The scale factor on z axis
serialstring()

Returns a Lua evaluable string to create this object

seti(newi)

Set the i direction of the matrix.

Parameters:newi (point3) –
setidentity()

Set the matrix to identity.

setj(newj)

Set the j direction of the matrix.

Parameters:newj (point3) –
setk(newk)

Set the k direction of the matrix.

Parameters:newk (point3) –
settranslation(newt)

Set the translation of the matrix.

Parameters:newt (point3) –
toboots()

Returns the boots code for this matrix.

Return type:str
transform(p)

Return the transform of the point p by the matrix. (p * self)

Parameters:p (point3) –
Return type:point3
translate(translation)

Translate the matrix.

Parameters:translation (point3) – The translation vector
vtransform(v)

Return the transform of the vector p by the matrix. (v * self)

Parameters:v (point3) –
Return type:point3