clip.h file
Clip-space projections, look-at / look-from, viewport, and world ↔ window helpers.
Functions
-
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(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_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_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_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_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_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_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_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_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_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 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 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.
-
void mat4_ortho_ptr(matrix4* res,
vm_
float_ t left, vm_ float_ t right, vm_ float_ t bottom, vm_ float_ t top, vm_ float_ t near, vm_ float_ t far) - Sets the matrix to an orthographic projection matrix.
- void mat4_look_at_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up)
- Constructs a view matrix for a camera positioned at the given location, looking towards a target, with a specified up direction.
- void mat4_look_from_dir_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up)
- View matrix from eye position and a look direction (no target point).
-
void mat4_look_from_dir_clip_ptr(matrix4* res,
const vector3* position,
const vector3* direction,
const vector3* up,
vm_
clip_ t clip) - Clip-aware look-from-direction view matrix.
-
void mat4_viewport_ptr(matrix4* res,
vm_
float_ t x, vm_ float_ t y, vm_ float_ t width, vm_ float_ t height) - Viewport matrix from origin
(x, y)and size(width, height). -
void mat4_viewport_depth_ptr(matrix4* res,
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 from origin, size, and depth range
[n, f]. -
void mat4_perspective_ptr(matrix4* res,
vm_
float_ t fov, vm_ float_ t aspect, vm_ float_ t near, vm_ float_ t far) - Creates a perspective projection matrix.
-
void mat4_perspective_fov_ptr(matrix4* res,
vm_
float_ t fov, vm_ float_ t w, vm_ float_ t h, vm_ float_ t n, vm_ float_ t f) - Sets the matrix to a perspective projection matrix.
-
void mat4_perspective_infinite_ptr(matrix4* res,
vm_
float_ t fov_y, vm_ float_ t aspect, vm_ float_ t n) - Sets the matrix to an infinite perspective projection matrix.
-
void mat4_perspective_infinite_clip_ptr(matrix4* res,
vm_
float_ t fov_y, vm_ float_ t aspect, vm_ float_ t n, vm_ clip_ t clip) - Infinite perspective matrix for a chosen clip convention.
-
void mat4_infinite_reverse_z_ptr(matrix4* res,
vm_
float_ t fov_y, vm_ float_ t aspect, vm_ float_ t n) - Infinite reverse-Z perspective matrix (RH, [0, 1] depth).
-
void mat4_infinite_reverse_z_clip_ptr(matrix4* res,
vm_
float_ t fov_y, vm_ float_ t aspect, vm_ float_ t n, vm_ clip_ t clip) - Infinite reverse-Z perspective matrix for a chosen clip convention.
-
void mat4_perspective_clip_ptr(matrix4* res,
vm_
float_ t fov_y, vm_ float_ t aspect, vm_ float_ t near, vm_ float_ t far, vm_ clip_ t clip) - Constructs a perspective projection matrix with configurable clip space.
-
void mat4_perspective_deg_ptr(matrix4* res,
vm_
float_ t fov_deg, vm_ float_ t aspect, vm_ float_ t near, vm_ float_ t far) - Sets the matrix to a perspective projection matrix using field of view in degrees.
-
void mat4_perspective_fov_deg_ptr(matrix4* res,
vm_
float_ t fov_deg, vm_ float_ t w, vm_ float_ t h, vm_ float_ t n, vm_ float_ t f) - Sets the matrix to a perspective projection matrix using vertical field of view in degrees.
-
void mat4_perspective_infinite_deg_ptr(matrix4* res,
vm_
float_ t fov_y_deg, vm_ float_ t aspect, vm_ float_ t n) - Sets the matrix to an infinite perspective projection matrix using vertical field of view in degrees.
-
void mat4_perspective_infinite_clip_deg_ptr(matrix4* res,
vm_
float_ t fov_y_deg, vm_ float_ t aspect, vm_ float_ t n, vm_ clip_ t clip) - Infinite perspective matrix from FOV in degrees and clip space.
-
void mat4_infinite_reverse_z_deg_ptr(matrix4* res,
vm_
float_ t fov_y_deg, vm_ float_ t aspect, vm_ float_ t n) - Infinite reverse-Z perspective matrix from a vertical FOV in degrees.
-
void mat4_infinite_reverse_z_clip_deg_ptr(matrix4* res,
vm_
float_ t fov_y_deg, vm_ float_ t aspect, vm_ float_ t n, vm_ clip_ t clip) - Infinite reverse-Z perspective matrix from FOV in degrees and clip space.
-
void mat4_perspective_clip_deg_ptr(matrix4* res,
vm_
float_ t fov_y_deg, vm_ float_ t aspect, vm_ float_ t near, vm_ float_ t far, vm_ clip_ t clip) - Sets a perspective projection matrix using vertical field of view in degrees.
-
void mat4_ortho_clip_ptr(matrix4* res,
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) - Sets the matrix to an orthographic projection matrix.
-
void mat4_look_at_clip_ptr(matrix4* res,
const vector3* position,
const vector3* target,
const vector3* up,
vm_
clip_ t clip) - Constructs a look-at view matrix with support for different clip space conventions.
- void vec3_world_to_window_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport)
- Projects a world-space point to window coordinates (OpenGL clip).
- void vec3_window_to_world_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport)
- Un-projects a window-space point to world coordinates using model, projection, and viewport.
-
void vec3_world_to_window_clip_ptr(vector3* res,
const vector3* world,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
vm_
clip_ t clip) - Projects a world-space point into window coordinates using model, projection, viewport, and clip depth range.
-
void vec3_window_to_world_clip_ptr(vector3* res,
const vector3* window,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
vm_
clip_ t clip) - Un-projects a window-space point to world coordinates using model, projection, viewport, and clip depth range.
Function documentation
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_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_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_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_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_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_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_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_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. |
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_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. |
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_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. |
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. |
void mat4_ortho_ptr(matrix4* res,
vm_ float_ t left,
vm_ float_ t right,
vm_ float_ t bottom,
vm_ float_ t top,
vm_ float_ t near,
vm_ float_ t far)
Sets the matrix to an orthographic projection matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set to the orthographic projection matrix. |
| left | The left clipping plane coordinate. |
| right | The right clipping plane coordinate. |
| bottom | The bottom clipping plane coordinate. |
| top | The top clipping plane coordinate. |
| near | The near clipping plane coordinate. |
| far | The far clipping plane coordinate. |
void mat4_look_at_ptr(matrix4* res, const vector3* position, const vector3* target, const vector3* up)
Constructs a view matrix for a camera positioned at the given location, looking towards a target, with a specified up direction.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 where the result is stored. |
| position | Pointer to the vector3 representing the camera's position. |
| target | Pointer to the vector3 representing the point the camera is looking at. |
| up | Pointer to the vector3 representing the up direction for the camera. |
This function computes a 4x4 view matrix that orients the camera at the position vector, directing it towards the target vector, while aligning the up direction. The matrix is stored in column-major order.
void mat4_look_from_dir_ptr(matrix4* res, const vector3* position, const vector3* direction, const vector3* up)
View matrix from eye position and a look direction (no target point).
| Parameters | |
|---|---|
| res | View matrix. |
| position | Eye position. |
| direction | Look direction. |
| up | World up direction. |
Equivalent to mat4_ with a default forward if direction is near zero.
void mat4_look_from_dir_clip_ptr(matrix4* res,
const vector3* position,
const vector3* direction,
const vector3* up,
vm_ clip_ t clip)
Clip-aware look-from-direction view matrix.
| Parameters | |
|---|---|
| res | View matrix. |
| position | Eye position. |
| direction | World-space look direction (need not be unit). |
| up | World up hint. |
| clip | Handedness / depth convention. |
void mat4_viewport_ptr(matrix4* res,
vm_ float_ t x,
vm_ float_ t y,
vm_ float_ t width,
vm_ float_ t height)
Viewport matrix from origin (x, y) and size (width, height).
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| x | Viewport origin x. |
| y | Viewport origin y. |
| width | Viewport width. |
| height | Viewport height. |
Maps NDC to window coordinates with depth in [0, 1].
void mat4_viewport_depth_ptr(matrix4* res,
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 from origin, size, and depth range [n, f].
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| x | Viewport origin x. |
| y | Viewport origin y. |
| width | Viewport width. |
| height | Viewport height. |
| n | Near depth. |
| f | Far depth. |
Maps NDC to window coordinates with depth in [n, f].
void mat4_perspective_ptr(matrix4* res,
vm_ float_ t fov,
vm_ float_ t aspect,
vm_ float_ t near,
vm_ float_ t far)
Creates a perspective projection matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to store the perspective projection matrix. |
| fov | Field of view in radians. |
| aspect | Aspect ratio of the viewport (width divided by height). |
| near | Distance to the near clipping plane. |
| far | Distance to the far clipping plane. |
This function computes a right-handed perspective projection matrix based on the given field of view, aspect ratio, and near and far clipping planes. The matrix is stored in the provided result pointer.
void mat4_perspective_fov_ptr(matrix4* res,
vm_ float_ t fov,
vm_ float_ t w,
vm_ float_ t h,
vm_ float_ t n,
vm_ float_ t f)
Sets the matrix to a perspective projection matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set to the perspective projection matrix. |
| fov | Field of view angle in radians. |
| w | Viewport width. |
| h | Viewport height. |
| n | Near clipping plane distance. |
| f | Far clipping plane distance. |
This function constructs a right-handed perspective projection matrix using the specified field of view, viewport width and height, near clipping plane, and far clipping plane.
void mat4_perspective_infinite_ptr(matrix4* res,
vm_ float_ t fov_y,
vm_ float_ t aspect,
vm_ float_ t n)
Sets the matrix to an infinite perspective projection matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set to the infinite perspective projection. |
| fov_y | Vertical field of view in radians. |
| aspect | Aspect ratio of the viewport (width / height). |
| n | Distance to the near clipping plane. |
This function constructs a perspective projection matrix with an infinite far plane, which is useful for rendering scenes where depth precision is less critical beyond the near plane. The matrix is set such that the field of view and aspect ratio are applied, with the near plane at distance n.
void mat4_perspective_infinite_clip_ptr(matrix4* res,
vm_ float_ t fov_y,
vm_ float_ t aspect,
vm_ float_ t n,
vm_ clip_ t clip)
Infinite perspective matrix for a chosen clip convention.
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y | Vertical field of view in radians. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
| clip | Clip space convention (handedness and ZO/NO depth). |
No far plane. fov_y is in radians.
void mat4_infinite_reverse_z_ptr(matrix4* res,
vm_ float_ t fov_y,
vm_ float_ t aspect,
vm_ float_ t n)
Infinite reverse-Z perspective matrix (RH, [0, 1] depth).
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y | Vertical field of view in radians. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
void mat4_infinite_reverse_z_clip_ptr(matrix4* res,
vm_ float_ t fov_y,
vm_ float_ t aspect,
vm_ float_ t n,
vm_ clip_ t clip)
Infinite reverse-Z perspective matrix for a chosen clip convention.
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y | Vertical field of view in radians. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
| clip | Clip space convention (handedness and ZO/NO depth). |
No far plane; depth is reversed for better precision. fov_y is in radians.
void mat4_perspective_clip_ptr(matrix4* res,
vm_ float_ t fov_y,
vm_ float_ t aspect,
vm_ float_ t near,
vm_ float_ t far,
vm_ clip_ t clip)
Constructs a perspective projection matrix with configurable clip space.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to receive the computed projection matrix. |
| 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 to use (VM_CLIP_RH_NO, VM_CLIP_RH_ZO, VM_CLIP_LH_ZO or VM_CLIP_LH_NO). |
Computes a 4x4 perspective projection matrix based on vertical field of view, aspect ratio, near and far planes, and the desired clip space convention.
void mat4_perspective_deg_ptr(matrix4* res,
vm_ float_ t fov_deg,
vm_ float_ t aspect,
vm_ float_ t near,
vm_ float_ t far)
Sets the matrix to a perspective projection matrix using field of view in degrees.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to receive the perspective projection. |
| 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. |
void mat4_perspective_fov_deg_ptr(matrix4* res,
vm_ float_ t fov_deg,
vm_ float_ t w,
vm_ float_ t h,
vm_ float_ t n,
vm_ float_ t f)
Sets the matrix to a perspective projection matrix using vertical field of view in degrees.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to be set. |
| fov_deg | Vertical field of view angle 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. |
void mat4_perspective_infinite_deg_ptr(matrix4* res,
vm_ float_ t fov_y_deg,
vm_ float_ t aspect,
vm_ float_ t n)
Sets the matrix to an infinite perspective projection matrix using vertical field of view in degrees.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to store the resulting projection matrix. |
| fov_y_deg | Vertical field of view angle in degrees. |
| aspect | Aspect ratio (width / height). |
| n | Near clipping plane distance. |
void mat4_perspective_infinite_clip_deg_ptr(matrix4* res,
vm_ float_ t fov_y_deg,
vm_ float_ t aspect,
vm_ float_ t n,
vm_ clip_ t clip)
Infinite perspective matrix from FOV in degrees and clip space.
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y_deg | Vertical field of view in degrees. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
| clip | Clip space convention (handedness and ZO/NO depth). |
void mat4_infinite_reverse_z_deg_ptr(matrix4* res,
vm_ float_ t fov_y_deg,
vm_ float_ t aspect,
vm_ float_ t n)
Infinite reverse-Z perspective matrix from a vertical FOV in degrees.
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y_deg | Vertical field of view in degrees. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
void mat4_infinite_reverse_z_clip_deg_ptr(matrix4* res,
vm_ float_ t fov_y_deg,
vm_ float_ t aspect,
vm_ float_ t n,
vm_ clip_ t clip)
Infinite reverse-Z perspective matrix from FOV in degrees and clip space.
| Parameters | |
|---|---|
| res | Output 4×4 matrix. |
| fov_y_deg | Vertical field of view in degrees. |
| aspect | Aspect ratio (width / height). |
| n | Near plane distance. |
| clip | Clip space convention (handedness and ZO/NO depth). |
void mat4_perspective_clip_deg_ptr(matrix4* res,
vm_ float_ t fov_y_deg,
vm_ float_ t aspect,
vm_ float_ t near,
vm_ float_ t far,
vm_ clip_ t clip)
Sets a perspective projection matrix using vertical field of view in degrees.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 that will receive the computed projection matrix. |
| fov_y_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. |
| clip | Clip space convention to use. |
void mat4_ortho_clip_ptr(matrix4* res,
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)
Sets the matrix to an orthographic projection matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to store the result. |
| left | Left clipping plane. |
| right | Right clipping plane. |
| bottom | Bottom clipping plane. |
| top | Top clipping plane. |
| near | Near clipping plane. |
| far | Far clipping plane. |
| clip | Clip space convention to use (one of the VM_CLIP_* values). |
Constructs a 4x4 orthographic projection matrix based on the provided frustum bounds and the selected clip space convention.
void mat4_look_at_clip_ptr(matrix4* res,
const vector3* position,
const vector3* target,
const vector3* up,
vm_ clip_ t clip)
Constructs a look-at view matrix with support for different clip space conventions.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 that will receive the computed view matrix. |
| position | Camera position in world space. |
| target | Target point in world space the camera is looking at. |
| up | World up direction vector. |
| clip | Clip space convention that determines handedness and depth range. |
Computes a 4x4 view matrix that positions the camera at position looking towards target, with up defining the world up direction. The resulting matrix is affected by the selected clip space handedness and depth range via the clip parameter.
For right-handed clip conventions the function delegates to mat4_look_at_ptr. For left-handed conventions a dedicated basis is constructed where the camera forward direction points along positive Z.
void vec3_world_to_window_ptr(vector3* res, const vector3* world, const matrix4* model, const matrix4* projection, const vector4* viewport)
Projects a world-space point to window coordinates (OpenGL clip).
| Parameters | |
|---|---|
| res | Window-space point. |
| world | World-space position. |
| model | Model matrix. |
| projection | Projection matrix. |
| viewport | Viewport rectangle (x, y, width, height). |
void vec3_window_to_world_ptr(vector3* res, const vector3* window, const matrix4* model, const matrix4* projection, const vector4* viewport)
Un-projects a window-space point to world coordinates using model, projection, and viewport.
| Parameters | |
|---|---|
| res | Output world-space point. |
| window | Window-space point (x, y, depth). |
| model | Model matrix. |
| projection | Projection matrix. |
| viewport | Viewport rectangle (x, y, width, height). |
Convenience wrapper around vec3_ with VM_ (right-handed, [-1, 1] depth).
void vec3_world_to_window_clip_ptr(vector3* res,
const vector3* world,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
vm_ clip_ t clip)
Projects a world-space point into window coordinates using model, projection, viewport, and clip depth range.
| Parameters | |
|---|---|
| res | Output window-space point (x, y, depth). |
| world | World-space position. |
| model | Model matrix. |
| projection | Projection matrix. |
| viewport | Viewport rectangle (x, y, width, height). |
| clip | Clip depth range (ZO or NO). |
Applies MVP, perspective-divides to NDC, then maps x/y into the viewport. Depth (res->z) is stored in the selected clip convention (ZO or NO). If w is near zero, writes (0, 0, 0).
void vec3_window_to_world_clip_ptr(vector3* res,
const vector3* window,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
vm_ clip_ t clip)
Un-projects a window-space point to world coordinates using model, projection, viewport, and clip depth range.
| Parameters | |
|---|---|
| res | Output world-space point. |
| window | Window-space point (x, y, depth). |
| model | Model matrix. |
| projection | Projection matrix. |
| viewport | Viewport rectangle (x, y, width, height). |
| clip | Clip depth range (ZO or NO). |
Maps window x/y into NDC, converts depth with the selected clip convention (ZO or NO), then applies the inverse MVP and perspective-divides. If the viewport size or w is near zero, writes (0, 0, 0).