Module mat4
double 4x4, 1-based, column major matrices
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. |
from_direction (direction, up) | Create a matrix from a direction/up pair. |
from_transform (trans, rot, scale) | Create a matrix from a transform. |
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, or, right) | 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 (Matrix, Matrix, 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
- 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
- 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, or, right)
-
Multiply N matrices.
Parameters:
- out mat4 Matrix to store the result
- or mat4 {mat4, ...} left hand operand(s)
- right mat4 hand operand if a is not table
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:
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 (Matrix, Matrix, position, normal)
-
Reflect a matrix across a plane.
Parameters:
- Matrix a to reflect
- Matrix a 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