Module math.mat4

double 4x4, 1-based, column major matrices.

this is apart of the LEEF-math module

Functions

new (a) The public constructor.
identity (a) Create an identity matrix.
from_angle_axis (angle, axis) Create a matrix from an angle/axis pair.
from_quaternion (q) Create a matrix from a quaternion.
set_rot_from_quaternion (m, q) set the rotation of a matrix from a quaternion.
from_direction (direction, up) Create a matrix from a direction/up pair.
from_transform (trans, rot, scale) Create a matrix from a transform.
rotate_Y (m, r, use_identity) rotates a matrix on the ZX matrix (otherwise known as yaw in coordinate systems where Y is up)
set_rot_zxy (m, pitch, yaw, roll) set the rotation of a given matrix in euler in the ZXY application order.
set_rot_luanti_entity (m, pitch, yaw, roll) alias of set_rot_zxy.
get_rot_zxy (m) get the ZXY euler rotation of the given matrix.
get_rot_luanti_entity (m) Alias of get_rot_zxy.
set_rot_xyz (m, pitch, yaw, roll) set the rotation of a given matrix in euler in the XYZ application order.
set_rot_irrlicht_bone (m, pitch, yaw, roll) alias of set_rot_xyz.
get_rot_xyz (m) Get the XYZ euler rotation of the given matrix.
get_rot_irrlicht_bone (m) Alias of get_rot_zxy.
normalize_columns (m) Normalize the columns of a matrix.
from_ortho (left, right, top, bottom, near, far) Create matrix from orthogonal.
from_perspective (fovy, aspect, near, far) Create matrix from perspective.
clone (a) Clone a matrix.
mul (out, a, b) Multiply N matrices.
multiply (out, a, b) Multiply N matrices.
mul_vec3_perspective (out, a, b) Multiply a matrix and a vec3, with perspective division.
mul_vec4 (out, a, b) Multiply a matrix and a vec4.
invert (out, a) Invert a matrix.
scale (out, a, s) Scale a matrix.
rotate (out, a, angle, axis) Rotate a matrix.
translate (out, a, t) Translate a matrix.
shear (out, a, yx, zx, xy, zy, xz, yz) Shear a matrix.
reflect (out, a, position, normal) Reflect a matrix across a plane.
look_at (out, eye, center, up) Transform matrix to look at a point.
target (out, eye, center, up) Transform matrix to target a point.
transpose (out, a) Transpose a matrix.
project (obj, mvp, viewport) Project a point into screen space
unproject (win, mvp, viewport) Unproject a point from screen space to world space.
is_mat4 (a) Return a boolean showing if a table is or is not a mat4.
vec2.has_nan (a) Return whether any component is NaN
to_string (a) Return a formatted string.
to_vec4s (a) Convert a matrix to row vec4s.
to_vec4s_cols (a) Convert a matrix to col vec4s.


Functions

new (a)
The public constructor.

Parameters:

  • a Can be of four types:
    table Length 16 (4x4 matrix) table Length 9 (3x3 matrix) table Length 4 (4 vec4s) nil

Returns:

    mat4 out
identity (a)
Create an identity matrix.

Parameters:

  • a mat4 Matrix to overwrite

Returns:

    mat4 out
from_angle_axis (angle, axis)
Create a matrix from an angle/axis pair.

Parameters:

  • angle number Angle of rotation
  • axis vec3 Axis of rotation

Returns:

    mat4 out
from_quaternion (q)
Create a matrix from a quaternion.

Parameters:

  • q quat Rotation quaternion

Returns:

    mat4 out
set_rot_from_quaternion (m, q)
set the rotation of a matrix from a quaternion.

Parameters:

  • m mat4 out
  • q quat rotation quaternion. only supports normal quaternion rotation (will normalize)
from_direction (direction, up)
Create a matrix from a direction/up pair.

Parameters:

  • direction vec3 Vector direction
  • up vec3 Up direction

Returns:

    mat4 out
from_transform (trans, rot, scale)
Create a matrix from a transform.

Parameters:

  • trans vec3 Translation vector
  • rot quat Rotation quaternion
  • scale vec3 Scale vector

Returns:

    mat4 out
rotate_Y (m, r, use_identity)
rotates a matrix on the ZX matrix (otherwise known as yaw in coordinate systems where Y is up)

Parameters:

  • m
  • r
  • use_identity
set_rot_zxy (m, pitch, yaw, roll)
set the rotation of a given matrix in euler in the ZXY application order. This is the order that minetest entities are rotated in.

Parameters:

  • m mat4 matrix to set the rotation of
  • pitch float the clockwise pitch in radians
  • yaw float the clockwise yaw in radians
  • roll float the clockwise yaw in roll

Returns:

    matrix
set_rot_luanti_entity (m, pitch, yaw, roll)
alias of set_rot_zxy. Sets the rotation of a given matrix in euler in the ZXY application order. This is the order that minetest entities are rotated in.

Parameters:

  • m mat4 matrix to set the rotation of
  • pitch float the clockwise pitch in radians
  • yaw float the clockwise yaw in radians
  • roll float the clockwise yaw in roll

Returns:

    matrix
get_rot_zxy (m)
get the ZXY euler rotation of the given matrix. This is the order that minetest entities are rotated in.

Parameters:

  • m mat4 the matrix to get the rotation of

Returns:

  1. float pitch
  2. float yaw
  3. float roll
get_rot_luanti_entity (m)
Alias of get_rot_zxy. Gets the ZXY euler rotation of the given matrix. This is the order that minetest entities are rotated in.

Parameters:

  • m mat4 the matrix to get the rotation of

Returns:

  1. float pitch
  2. float yaw
  3. float roll
set_rot_xyz (m, pitch, yaw, roll)
set the rotation of a given matrix in euler in the XYZ application order. This is the rotation order irrlicht uses (i.e. for bones in Luanti)

Parameters:

  • m mat4 matrix to set the rotation of
  • pitch float the clockwise pitch in radians
  • yaw float the clockwise yaw in radians
  • roll float the clockwise yaw in roll

Returns:

    matrix
set_rot_irrlicht_bone (m, pitch, yaw, roll)
alias of set_rot_xyz. Sets the rotation of a given matrix in euler in the XYZ application order. This is the rotation order irrlicht uses (i.e. for bones in Luanti)

Parameters:

  • m mat4 matrix to set the rotation of
  • pitch float the clockwise pitch in radians
  • yaw float the clockwise yaw in radians
  • roll float the clockwise yaw in roll

Returns:

    matrix
get_rot_xyz (m)
Get the XYZ euler rotation of the given matrix. This is the rotation order irrlicht uses (i.e. for bones in Luanti)

Parameters:

  • m mat4 the matrix to get the rotation of

Returns:

  1. float pitch
  2. float yaw
  3. float roll
get_rot_irrlicht_bone (m)
Alias of get_rot_zxy. Gets the XYZ euler rotation of the given matrix. This is the rotation order irrlicht uses (i.e. for bones in Luanti).

Parameters:

  • m mat4 the matrix to get the rotation of

Returns:

  1. float pitch
  2. float yaw
  3. float roll
normalize_columns (m)
Normalize the columns of a matrix. Use this to help with rounding errors.

Parameters:

  • m mat4
from_ortho (left, right, top, bottom, near, far)
Create matrix from orthogonal.

Parameters:

  • left number
  • right number
  • top number
  • bottom number
  • near number
  • far number

Returns:

    mat4 out
from_perspective (fovy, aspect, near, far)
Create matrix from perspective.

Parameters:

  • fovy number Field of view
  • aspect number Aspect ratio
  • near number Near plane
  • far number Far plane

Returns:

    mat4 out
clone (a)
Clone a matrix.

Parameters:

  • a mat4 Matrix to clone

Returns:

    mat4 out
mul (out, a, b)
Multiply N matrices.

Parameters:

  • out mat4 Matrix to store the result
  • a table a mat4 or a list of mat4s
  • b mat4 right operand used if param a is a mat4

Returns:

    mat4 out multiplied matrix result
multiply (out, a, b)
Multiply N matrices.

Parameters:

  • out mat4 Matrix to store the result
  • a table a mat4 or a list of mat4s
  • b mat4 right operand used if param a is a mat4

Returns:

    mat4 out multiplied matrix result
mul_vec3_perspective (out, a, b)
Multiply a matrix and a vec3, with perspective division. This function uses an implicit 1 for the fourth component.

Parameters:

  • out vec3 vec3 to store the result
  • a mat4 Left hand operand
  • b vec3 Right hand operand

Returns:

    vec3 out
mul_vec4 (out, a, b)
Multiply a matrix and a vec4.

Parameters:

  • out table table to store the result
  • a mat4 Left hand operand
  • b table Right hand operand

Returns:

    vec4 out
invert (out, a)
Invert a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to invert

Returns:

    mat4 out
scale (out, a, s)
Scale a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to scale
  • s vec3 Scalar

Returns:

    mat4 out
rotate (out, a, angle, axis)
Rotate a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to rotate
  • angle number Angle to rotate by (in radians)
  • axis vec3 Axis to rotate on

Returns:

    mat4 out
translate (out, a, t)
Translate a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to translate
  • t vec3 Translation vector

Returns:

    mat4 out
shear (out, a, yx, zx, xy, zy, xz, yz)
Shear a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to translate
  • yx number
  • zx number
  • xy number
  • zy number
  • xz number
  • yz number

Returns:

    mat4 out
reflect (out, a, position, normal)
Reflect a matrix across a plane.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to reflect
  • position vec3 A point on the plane
  • normal vec3 The (normalized!) normal vector of the plane
look_at (out, eye, center, up)
Transform matrix to look at a point.

Parameters:

  • out mat4 Matrix to store result
  • eye vec3 Location of viewer's view plane
  • center vec3 Location of object to view
  • up vec3 Up direction

Returns:

    mat4 out
target (out, eye, center, up)
Transform matrix to target a point.

Parameters:

  • out mat4 Matrix to store result
  • eye vec3 Location of viewer's view plane
  • center vec3 Location of object to view
  • up vec3 Up direction

Returns:

    mat4 out
transpose (out, a)
Transpose a matrix.

Parameters:

  • out mat4 Matrix to store the result
  • a mat4 Matrix to transpose

Returns:

    mat4 out
project (obj, mvp, viewport)
Project a point into screen space

Parameters:

  • obj vec3 Object position in world space
  • mvp mat4 Projection matrix
  • viewport table XYWH of viewport

Returns:

    vec3 win
unproject (win, mvp, viewport)
Unproject a point from screen space to world space.

Parameters:

  • win vec3 Object position in screen space
  • mvp mat4 Projection matrix
  • viewport table XYWH of viewport

Returns:

    vec3 obj
is_mat4 (a)
Return a boolean showing if a table is or is not a mat4.

Parameters:

  • a mat4 Matrix to be tested

Returns:

    boolean is_mat4
vec2.has_nan (a)
Return whether any component is NaN

Parameters:

  • a mat4 Matrix to be tested

Returns:

    boolean if any component is NaN
to_string (a)
Return a formatted string.

Parameters:

  • a mat4 Matrix to be turned into a string

Returns:

    string formatted
to_vec4s (a)
Convert a matrix to row vec4s.

Parameters:

  • a mat4 Matrix to be converted

Returns:

    table vec4s
to_vec4s_cols (a)
Convert a matrix to col vec4s.

Parameters:

  • a mat4 Matrix to be converted

Returns:

    table vec4s
generated by LDoc 1.5.0 Last updated 2025-06-22 02:49:31