src/matrix4.c file

Functions

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

Multiplies two 4x4 matrices (a * b).

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

matrix4 mat4_transpose(const matrix4 m)

Computes the transpose of a 4x4 matrix.

Parameters
m The input matrix.
Returns The transposed matrix4.

matrix4 mat4_inverse(const matrix4 m)

Computes the inverse of a 4x4 matrix.

Parameters
m The input matrix.
Returns The inverse matrix4.

matrix4 mat4_inverse_affine(const matrix4 m)

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

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

matrix4 mat4_translate(const 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(const 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(const vector3 axis, const 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(const vector3 axis, const 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(const vm_float_t fov, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_deg, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const 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(const vector3 position, const vector3 target, const 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(const vm_float_t fov, const vm_float_t w, const vm_float_t h, const vm_float_t n, const 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(const vm_float_t fov_deg, const vm_float_t w, const vm_float_t h, const vm_float_t n, const 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(const vm_float_t fov_y, const vm_float_t aspect, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const 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(const 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(const matrix4 m, const vector4 v)

Multiplies a 4x4 matrix by a vector4.

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

vector3 mat4_mul_vec3(const matrix4 m, const vector3 v, const 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(const 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(const 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(const 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(const 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(const 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(const 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(const vector3 translation, const quaternion rotation, const 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(const matrix3 m)

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

Parameters
m Input matrix.
Returns The resulting matrix4.

vector3 mat4_extract_translation(const matrix4 m)

Extracts the translation vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

vector3 mat4_extract_scale(const matrix4 m)

Extracts the scale vector from a matrix4.

Parameters
m Input matrix.
Returns The resulting vector3.

quaternion mat4_extract_rotation(const matrix4 m)

Extracts the rotation quaternion from a matrix4.

Parameters
m Input matrix.
Returns The resulting quaternion.

matrix4 mat4_perspective_clip(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t near, const vm_float_t far, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t near, const vm_float_t far, const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t near, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const vm_float_t far, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const 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(const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const 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(const vector3 position, const vector3 target, const vector3 up, const 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(const vector3 position, const vector3 target, const 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(const vector3 position, const vector3 target, const 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(const vector3 position, const vector3 direction, const 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(const vector3 position, const vector3 direction, const vector3 up, const 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(const vector3 position, const vector3 direction, const 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(const vector3 position, const vector3 direction, const 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(const vm_float_t x, const vm_float_t y, const vm_float_t width, const 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(const vm_float_t x, const vm_float_t y, const vm_float_t width, const vm_float_t height, const vm_float_t n, const 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(const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t n, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t n, const 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(const vm_float_t fov_y, const vm_float_t aspect, const 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(const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t n, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const 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(const vm_float_t fov_y_deg, const vm_float_t aspect, const vm_float_t n, const 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(const vector3 world, const matrix4 model, const matrix4 projection, const 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(const vector3 window, const matrix4 model, const matrix4 projection, const 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(const vector3 world, const matrix4 model, const matrix4 projection, const vector4 viewport, const 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(const vector3 window, const matrix4 model, const matrix4 projection, const vector4 viewport, const 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.