src/matrix4.c file

Functions

auto mat4_identity(void) -> matrix4
Constructs the 4x4 identity matrix.
auto mat4_mul(matrix4 a, matrix4 b) -> matrix4
Multiplies two 4x4 matrices (a * b).
auto mat4_transpose(matrix4 m) -> matrix4
Computes the transpose of a 4x4 matrix.
auto mat4_inverse(matrix4 m) -> matrix4
Computes the inverse of a 4x4 matrix.
auto mat4_inverse_affine(matrix4 m) -> matrix4
Inverse of an affine matrix [R t; 0 1].
auto mat4_translate(vector3 v) -> matrix4
Constructs a translation matrix from the given vector.
auto mat4_scale(vector3 v) -> matrix4
Constructs a scaling matrix from the given scale vector.
auto mat4_rotation(vector3 axis, vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix.
auto mat4_rotation_deg(vector3 axis, vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix from an axis and angle in degrees.
auto mat4_perspective(vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Constructs a perspective projection matrix.
auto mat4_perspective_deg(vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.
auto mat4_ortho(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Constructs an orthographic projection matrix.
auto mat4_look_at(vector3 position, vector3 target, vector3 up) -> matrix4
Constructs a view matrix from eye position, target, and up vector.
auto mat4_perspective_fov(vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f) -> matrix4
Constructs a perspective projection matrix using FOV, width, and height.
auto mat4_perspective_fov_deg(vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f) -> matrix4
Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.
auto mat4_perspective_infinite(vm_float_t fov_y, vm_float_t aspect, vm_float_t n) -> matrix4
Constructs an infinite far-plane perspective projection matrix.
auto mat4_perspective_infinite_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n) -> matrix4
Constructs a 4x4 infinite perspective projection matrix using vertical field of view in degrees.
auto mat4_determinant(matrix4 m) -> vm_float_t
Calculates the determinant of the given 4x4 matrix.
auto mat4_mul_vec4(matrix4 m, vector4 v) -> vector4
Multiplies a 4x4 matrix by a vector4.
auto mat4_mul_vec3(matrix4 m, vector3 v, vm_float_t w) -> vector3
Transforms a vector3 by a 4x4 matrix using homogeneous w.
auto mat4_rotation_x(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the X axis.
auto mat4_rotation_x_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the X axis.
auto mat4_rotation_y(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the Y axis.
auto mat4_rotation_y_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the Y axis.
auto mat4_rotation_z(vm_float_t radians) -> matrix4
Constructs a 4x4 rotation matrix around the Z axis.
auto mat4_rotation_z_deg(vm_float_t degrees) -> matrix4
Constructs a 4x4 rotation matrix around the Z axis from an angle in degrees.
auto mat4_trs(vector3 translation, quaternion rotation, vector3 scale) -> matrix4
Builds a 4x4 TRS matrix from translation, rotation, and scale.
auto mat4_from_mat3(matrix3 m) -> matrix4
Embeds a matrix3 into the upper-left of a matrix4.
auto mat4_extract_translation(matrix4 m) -> vector3
Extracts the translation vector from a matrix4.
auto mat4_extract_scale(matrix4 m) -> vector3
Extracts the scale vector from a matrix4.
auto mat4_extract_rotation(matrix4 m) -> quaternion
Extracts the rotation quaternion from a matrix4.
auto mat4_perspective_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Constructs a 4x4 perspective projection matrix.
auto mat4_perspective_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Perspective projection from a vertical FOV in degrees.
auto mat4_perspective_rh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH perspective, clip z in [-1, 1].
auto mat4_perspective_rh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH perspective, clip z in [0, 1].
auto mat4_perspective_lh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH perspective, clip z in [0, 1].
auto mat4_perspective_lh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Left-handed perspective, clip z in [-1, 1].
auto mat4_perspective_rh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH perspective from a FOV in degrees.
auto mat4_perspective_rh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH perspective from a FOV in degrees.
auto mat4_perspective_lh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH perspective from a FOV in degrees.
auto mat4_perspective_lh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far) -> matrix4
Left-handed NO perspective from a FOV in degrees.
auto mat4_ortho_clip(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip) -> matrix4
Orthographic projection with an explicit clip convention.
auto mat4_ortho_rh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
OpenGL-style RH orthographic projection.
auto mat4_ortho_rh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Vulkan-style RH orthographic projection.
auto mat4_ortho_lh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Direct3D-style LH orthographic projection.
auto mat4_ortho_lh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far) -> matrix4
Left-handed NO orthographic projection.
auto mat4_look_at_clip(vector3 position, vector3 target, vector3 up, vm_clip_t clip) -> matrix4
Look-at view matrix with an explicit clip convention.
auto mat4_look_at_rh(vector3 position, vector3 target, vector3 up) -> matrix4
Right-handed look-at view matrix.
auto mat4_look_at_lh(vector3 position, vector3 target, vector3 up) -> matrix4
Left-handed look-at view matrix.
auto mat4_look_from_dir(vector3 position, vector3 direction, vector3 up) -> matrix4
View matrix from eye position and a look direction.
auto mat4_look_from_dir_clip(vector3 position, vector3 direction, vector3 up, vm_clip_t clip) -> matrix4
Look-from-direction view matrix with an explicit clip convention.
auto mat4_look_from_dir_rh(vector3 position, vector3 direction, vector3 up) -> matrix4
Right-handed look-from-direction view matrix.
auto mat4_look_from_dir_lh(vector3 position, vector3 direction, vector3 up) -> matrix4
Left-handed look-from-direction view matrix.
auto mat4_viewport(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height) -> matrix4
Pixel-box viewport matrix (NDC xy/z [-1,1] to window + depth [0,1]).
auto mat4_viewport_depth(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f) -> matrix4
Viewport matrix with an explicit depth range.
auto mat4_normal(matrix4 m) -> matrix4
Inverse-transpose of the upper 3x3, embedded in a matrix4.
auto mat4_perspective_infinite_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite-far perspective with an explicit clip convention.
auto mat4_perspective_infinite_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite-far perspective from a FOV in degrees.
auto mat4_infinite_reverse_z(vm_float_t fov_y, vm_float_t aspect, vm_float_t n) -> matrix4
Infinite reverse-Z perspective (RH + ZO by default).
auto mat4_infinite_reverse_z_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite reverse-Z perspective with an explicit clip convention.
auto mat4_infinite_reverse_z_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n) -> matrix4
Infinite reverse-Z perspective from a FOV in degrees.
auto mat4_infinite_reverse_z_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip) -> matrix4
Infinite reverse-Z perspective (degrees + clip convention).
auto vec3_world_to_window(vector3 world, matrix4 model, matrix4 projection, vector4 viewport) -> vector3
Projects a world space point to window coordinates.
auto vec3_window_to_world(vector3 window, matrix4 model, matrix4 projection, vector4 viewport) -> vector3
Un-projects a window coordinate back to world space.
auto vec3_world_to_window_clip(vector3 world, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip) -> vector3
Projects a world-space point into window coordinates using model, projection and viewport.
auto vec3_window_to_world_clip(vector3 window, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip) -> vector3
Un-projects a window coordinate using model, projection, viewport and clip space.

Function documentation

matrix4 mat4_identity(void)

Constructs the 4x4 identity matrix.

Returns The identity matrix4.

matrix4 mat4_mul(matrix4 a, matrix4 b)

Multiplies two 4x4 matrices (a * b).

Parameters
a The first matrix.
b The second matrix.
Returns The resulting product matrix4.

Column-major product AB so (AB)v == A(Bv) (column vector on the right).

matrix4 mat4_transpose(matrix4 m)

Computes the transpose of a 4x4 matrix.

Parameters
m The input matrix.
Returns The transposed matrix4.

matrix4 mat4_inverse(matrix4 m)

Computes the inverse of a 4x4 matrix.

Parameters
m The input matrix.
Returns The inverse matrix4.

matrix4 mat4_inverse_affine(matrix4 m)

Inverse of an affine matrix [R t; 0 1].

Parameters
m Affine 4×4 matrix.
Returns Inverse matrix.

Inverts an [A t; 0 1] affine transform without the full 4x4 adjugate.

matrix4 mat4_translate(vector3 v)

Constructs a translation matrix from the given vector.

Parameters
v The translation vector (x, y, z).
Returns The translation matrix4.

matrix4 mat4_scale(vector3 v)

Constructs a scaling matrix from the given scale vector.

Parameters
v The scale vector (x, y, z factors).
Returns The resulting scaling matrix4.

matrix4 mat4_rotation(vector3 axis, vm_float_t radians)

Constructs a 4x4 rotation matrix.

Parameters
axis The rotation axis.
radians The rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_deg(vector3 axis, vm_float_t degrees)

Constructs a 4x4 rotation matrix from an axis and angle in degrees.

Parameters
axis The rotation axis.
degrees The rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_perspective(vm_float_t fov, vm_float_t aspect, vm_float_t near, vm_float_t far)

Constructs a perspective projection matrix.

Parameters
fov Field of view (radians).
aspect Aspect ratio (width/height).
near Near plane distance.
far Far plane distance.
Returns The perspective matrix4.

matrix4 mat4_perspective_deg(vm_float_t fov_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.

Parameters
fov_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
Returns The perspective projection matrix.

matrix4 mat4_ortho(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Constructs an orthographic projection matrix.

Parameters
left Left clipping plane.
right Right clipping plane.
bottom Bottom clipping plane.
top Top clipping plane.
near Near plane distance.
far Far plane distance.
Returns The orthographic matrix4.

matrix4 mat4_look_at(vector3 position, vector3 target, vector3 up)

Constructs a view matrix from eye position, target, and up vector.

Parameters
position Eye position.
target Target position.
up Up vector.
Returns The view matrix4.

matrix4 mat4_perspective_fov(vm_float_t fov, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Constructs a perspective projection matrix using FOV, width, and height.

Parameters
fov Vertical field of view (radians).
w Viewport width.
h Viewport height.
n Near plane.
f Far plane.
Returns The perspective matrix4.

matrix4 mat4_perspective_fov_deg(vm_float_t fov_deg, vm_float_t w, vm_float_t h, vm_float_t n, vm_float_t f)

Constructs a 4x4 perspective projection matrix from vertical field of view in degrees.

Parameters
fov_deg Vertical field of view in degrees.
w Width of the viewport.
h Height of the viewport.
n Distance to the near clipping plane.
f Distance to the far clipping plane.
Returns The perspective matrix4.

matrix4 mat4_perspective_infinite(vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Constructs an infinite far-plane perspective projection matrix.

Parameters
fov_y Vertical field of view (radians).
aspect Aspect ratio.
n Near plane distance.
Returns The perspective matrix4.

matrix4 mat4_perspective_infinite_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Constructs a 4x4 infinite perspective projection matrix using vertical field of view in degrees.

Parameters
fov_y_deg Vertical field of view angle in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns The infinite perspective matrix4.

vm_float_t mat4_determinant(matrix4 m)

Calculates the determinant of the given 4x4 matrix.

Parameters
m The matrix.
Returns The determinant value as a vm_float_t.

Uses cofactor expansion for computation.

vector4 mat4_mul_vec4(matrix4 m, vector4 v)

Multiplies a 4x4 matrix by a vector4.

Parameters
m Input matrix.
v Input vector.
Returns The resulting vector4.

vector3 mat4_mul_vec3(matrix4 m, vector3 v, vm_float_t w)

Transforms a vector3 by a 4x4 matrix using homogeneous w.

Parameters
m Input matrix.
v Input vector.
w Homogeneous w component.
Returns The resulting vector3.

matrix4 mat4_rotation_x(vm_float_t radians)

Constructs a 4x4 rotation matrix around the X axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_x_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the X axis.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix4.

The angle is specified in degrees and internally converted to radians.

matrix4 mat4_rotation_y(vm_float_t radians)

Constructs a 4x4 rotation matrix around the Y axis.

Parameters
radians The rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_y_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the Y axis.

Parameters
degrees Rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_rotation_z(vm_float_t radians)

Constructs a 4x4 rotation matrix around the Z axis.

Parameters
radians Rotation angle in radians.
Returns The rotation matrix4.

matrix4 mat4_rotation_z_deg(vm_float_t degrees)

Constructs a 4x4 rotation matrix around the Z axis from an angle in degrees.

Parameters
degrees The rotation angle in degrees.
Returns The rotation matrix4.

matrix4 mat4_trs(vector3 translation, quaternion rotation, vector3 scale)

Builds a 4x4 TRS matrix from translation, rotation, and scale.

Parameters
translation Translation vector.
rotation Rotation quaternion.
scale Scale vector.
Returns The resulting matrix4.

matrix4 mat4_from_mat3(matrix3 m)

Embeds a matrix3 into the upper-left of a matrix4.

Parameters
m Input matrix.
Returns The resulting matrix4.

vector3 mat4_extract_translation(matrix4 m)

Extracts the translation vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

vector3 mat4_extract_scale(matrix4 m)

Extracts the scale vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

quaternion mat4_extract_rotation(matrix4 m)

Extracts the rotation quaternion from a matrix4.

Parameters
m Input matrix.
Returns The resulting quaternion.

matrix4 mat4_perspective_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Constructs a 4x4 perspective projection matrix.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Distance to the near clipping plane.
far Distance to the far clipping plane.
clip Clip space convention.
Returns The perspective matrix4.

matrix4 mat4_perspective_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far, vm_clip_t clip)

Perspective projection from a vertical FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

OpenGL-style RH perspective, clip z in [-1, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Vulkan-style RH perspective, clip z in [0, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_zo(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Direct3D-style LH perspective, clip z in [0, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_no(vm_float_t fov_y, vm_float_t aspect, vm_float_t near, vm_float_t far)

Left-handed perspective, clip z in [-1, 1].

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

OpenGL-style RH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_rh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Vulkan-style RH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_zo_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Direct3D-style LH perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_perspective_lh_no_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t near, vm_float_t far)

Left-handed NO perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
near Near plane distance.
far Far plane distance.
Returns Perspective matrix4.

matrix4 mat4_ortho_clip(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far, vm_clip_t clip)

Orthographic projection with an explicit clip convention.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
clip Clip-space convention.
Returns Orthographic matrix4.

matrix4 mat4_ortho_rh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

OpenGL-style RH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_rh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Vulkan-style RH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_lh_zo(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Direct3D-style LH orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_ortho_lh_no(vm_float_t left, vm_float_t right, vm_float_t bottom, vm_float_t top, vm_float_t near, vm_float_t far)

Left-handed NO orthographic projection.

Parameters
left Left plane.
right Right plane.
bottom Bottom plane.
top Top plane.
near Near plane.
far Far plane.
Returns Orthographic matrix4.

matrix4 mat4_look_at_clip(vector3 position, vector3 target, vector3 up, vm_clip_t clip)

Look-at view matrix with an explicit clip convention.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
clip Clip-space convention.
Returns View matrix4.

matrix4 mat4_look_at_rh(vector3 position, vector3 target, vector3 up)

Right-handed look-at view matrix.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_at_lh(vector3 position, vector3 target, vector3 up)

Left-handed look-at view matrix.

Parameters
position Eye position.
target Point the camera looks at.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir(vector3 position, vector3 direction, vector3 up)

View matrix from eye position and a look direction.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir_clip(vector3 position, vector3 direction, vector3 up, vm_clip_t clip)

Look-from-direction view matrix with an explicit clip convention.

Parameters
position Eye position.
direction Look direction.
up World up direction.
clip Clip-space convention.
Returns View matrix4.

matrix4 mat4_look_from_dir_rh(vector3 position, vector3 direction, vector3 up)

Right-handed look-from-direction view matrix.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_look_from_dir_lh(vector3 position, vector3 direction, vector3 up)

Left-handed look-from-direction view matrix.

Parameters
position Eye position.
direction Look direction.
up World up direction.
Returns View matrix4.

matrix4 mat4_viewport(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height)

Pixel-box viewport matrix (NDC xy/z [-1,1] to window + depth [0,1]).

Parameters
x Viewport origin X.
y Viewport origin Y.
width Viewport width.
height Viewport height.
Returns Viewport matrix4.

matrix4 mat4_viewport_depth(vm_float_t x, vm_float_t y, vm_float_t width, vm_float_t height, vm_float_t n, vm_float_t f)

Viewport matrix with an explicit depth range.

Parameters
x Viewport origin X.
y Viewport origin Y.
width Viewport width.
height Viewport height.
n Near depth mapped from clip z.
f Far depth mapped from clip z.
Returns Viewport matrix4.

matrix4 mat4_normal(matrix4 m)

Inverse-transpose of the upper 3x3, embedded in a matrix4.

Parameters
m Model matrix.
Returns Normal matrix as a matrix4.

matrix4 mat4_perspective_infinite_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite-far perspective with an explicit clip convention.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_perspective_infinite_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite-far perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z(vm_float_t fov_y, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective (RH + ZO by default).

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_clip(vm_float_t fov_y, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective with an explicit clip convention.

Parameters
fov_y Vertical field of view in radians.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n)

Infinite reverse-Z perspective from a FOV in degrees.

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
Returns Perspective matrix4.

matrix4 mat4_infinite_reverse_z_clip_deg(vm_float_t fov_y_deg, vm_float_t aspect, vm_float_t n, vm_clip_t clip)

Infinite reverse-Z perspective (degrees + clip convention).

Parameters
fov_y_deg Vertical field of view in degrees.
aspect Aspect ratio (width / height).
n Near plane distance.
clip Clip-space convention.
Returns Perspective matrix4.

vector3 vec3_world_to_window(vector3 world, matrix4 model, matrix4 projection, vector4 viewport)

Projects a world space point to window coordinates.

Parameters
world World space position to project.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
Returns The projected window space vector3.

vector3 vec3_window_to_world(vector3 window, matrix4 model, matrix4 projection, vector4 viewport)

Un-projects a window coordinate back to world space.

Parameters
window The window coordinate to un-project.
model The model matrix.
projection The projection matrix.
viewport The viewport (x, y, width, height).
Returns The unprojected world space vector3.

vector3 vec3_world_to_window_clip(vector3 world, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip)

Projects a world-space point into window coordinates using model, projection and viewport.

Parameters
world World-space position to project.
model Model matrix.
projection Projection matrix.
viewport Viewport rectangle (x, y, width, height).
clip Clip-space convention to use.
Returns The projected window-space coordinates.

vector3 vec3_window_to_world_clip(vector3 window, matrix4 model, matrix4 projection, vector4 viewport, vm_clip_t clip)

Un-projects a window coordinate using model, projection, viewport and clip space.

Parameters
window The window coordinate to un-project.
model The model matrix.
projection The projection matrix.
viewport The viewport (x, y, width, height).
clip The clip space convention.
Returns The unprojected vector3.