matrix4_ptr.c file
Functions
- void mat4_identity_ptr(matrix4* res)
- Sets the matrix to the identity matrix.
-
auto mat4_mul_ptr_scalar(matrix4* res,
const matrix4* a,
const matrix4* b) -> VECMAT_
SCALAR_ API void - Multiplies two 4x4 matrices.
-
auto mat4_transpose_ptr_scalar(matrix4* res,
const matrix4* m) -> VECMAT_
SCALAR_ API void - Transposes the given 4x4 matrix.
- void mat4_mul_ptr(matrix4* res, const matrix4* a, const matrix4* b)
- Multiplies two 4x4 matrices (dispatched).
- void mat4_transpose_ptr(matrix4* res, const matrix4* m)
- Transposes a 4x4 matrix (dispatched).
- void mat4_inverse_ptr(matrix4* res, const matrix4* m)
- Computes the inverse of a 4x4 matrix.
- void mat4_translate_ptr(matrix4* res, const vector3* v)
- Sets the matrix to a translation matrix.
- void mat4_scale_ptr(matrix4* res, const vector3* v)
- Sets the matrix to a scaling matrix using the provided scale vector.
-
void mat4_rotation_ptr(matrix4* res,
const vector3* axis,
const vm_
float_ t radians) - Sets the matrix to a rotation matrix around the given axis.
-
void mat4_rotation_deg_ptr(matrix4* res,
const vector3* axis,
const vm_
float_ t degrees) - Sets the matrix to a rotation matrix using an axis and angle in degrees.
-
void mat4_rotation_x_ptr(matrix4* res,
const vm_
float_ t radians) - Builds a 4x4 rotation matrix around the X axis (radians).
-
void mat4_rotation_x_deg_ptr(matrix4* res,
const vm_
float_ t degrees) - Builds a 4x4 rotation matrix around the X axis (degrees).
-
void mat4_rotation_y_ptr(matrix4* res,
const vm_
float_ t radians) - Sets the matrix to a rotation matrix around the Y axis.
-
void mat4_rotation_y_deg_ptr(matrix4* res,
const vm_
float_ t degrees) - Builds a 4x4 rotation matrix around the Y axis (degrees).
-
void mat4_rotation_z_ptr(matrix4* res,
const vm_
float_ t radians) - Sets the matrix to a rotation around the Z axis.
-
void mat4_rotation_z_deg_ptr(matrix4* res,
const vm_
float_ t degrees) - Builds a 4x4 rotation matrix around the Z axis (degrees).
- void mat4_from_mat3_ptr(matrix4* res, const matrix3* m)
- Embeds a matrix3 into the upper-left of a matrix4.
- void mat4_trs_ptr(matrix4* res, const vector3* translation, const quaternion* rotation, const vector3* scale)
- Builds a 4x4 TRS matrix from translation, rotation, and scale.
- void mat4_extract_translation_ptr(vector3* res, const matrix4* m)
- Extracts the translation vector from a matrix4.
- void mat4_extract_scale_ptr(vector3* res, const matrix4* m)
- Extracts the scale vector from a matrix4.
- void mat4_extract_rotation_ptr(quaternion* res, const matrix4* m)
- Extracts the rotation quaternion from a matrix4.
-
void mat4_perspective_ptr(matrix4* res,
const vm_
float_ t fov, const vm_ float_ t aspect, const vm_ float_ t near, const vm_ float_ t far) - Creates a perspective projection matrix.
-
void mat4_perspective_deg_ptr(matrix4* res,
const vm_
float_ t fov_deg, const vm_ float_ t aspect, const vm_ float_ t near, const vm_ float_ t far) - Sets the matrix to a perspective projection matrix using field of view in degrees.
-
void mat4_ortho_ptr(matrix4* res,
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) - 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_perspective_fov_ptr(matrix4* res,
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) - Sets the matrix to a perspective projection matrix.
-
void mat4_perspective_fov_deg_ptr(matrix4* res,
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) - Sets the matrix to a perspective projection matrix using vertical field of view in degrees.
-
void mat4_perspective_infinite_ptr(matrix4* res,
vm_
float_ t const fov_y, vm_ float_ t const aspect, vm_ float_ t const n) - Sets the matrix to an infinite perspective projection matrix.
-
void mat4_perspective_infinite_deg_ptr(matrix4* res,
const vm_
float_ t fov_y_deg, const vm_ float_ t aspect, const vm_ float_ t n) - Sets the matrix to an infinite perspective projection matrix using vertical field of view in degrees.
-
auto mat4_mul_vec4_ptr_scalar(vector4* res,
const matrix4* m,
const vector4* v) -> VECMAT_
SCALAR_ API void - Multiplies a 4x4 matrix by a vector4.
- void mat4_mul_vec4_ptr(vector4* res, const matrix4* m, const vector4* v)
- Transforms a vector4 by a 4x4 matrix (dispatched).
-
auto mat4_mul_vec3_ptr_scalar(vector3* res,
const matrix4* m,
const vector3* v,
const vm_
float_ t w) -> VECMAT_ SCALAR_ API void - Transforms a vector3 by a 4x4 matrix using homogeneous w.
-
void mat4_mul_vec3_ptr(vector3* res,
const matrix4* m,
const vector3* v,
const vm_
float_ t w) - Transforms a vector3 by a 4x4 matrix using homogeneous w (dispatched).
-
void mat4_perspective_clip_ptr(matrix4* res,
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 perspective projection matrix with configurable clip space.
-
void mat4_perspective_clip_deg_ptr(matrix4* res,
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) - Sets a perspective projection matrix using vertical field of view in degrees.
-
void mat4_ortho_clip_ptr(matrix4* res,
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) - 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,
const vm_
clip_ t clip) - Constructs a look-at view matrix with support for different clip space conventions.
- void mat4_inverse_affine_ptr(matrix4* res, const matrix4* m)
- Inverse of an affine matrix
[R t; 0 1]. - void mat4_normal_ptr(matrix4* res, const matrix4* m)
- Inverse-transpose of the upper-left 3x3, embedded in a matrix4.
- 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,
const vm_
clip_ t clip) - Clip-aware look-from-direction view matrix.
-
void mat4_viewport_ptr(matrix4* res,
const vm_
float_ t x, const vm_ float_ t y, const vm_ float_ t width, const vm_ float_ t height) - Viewport matrix from origin
(x, y)and size(width, height). -
void mat4_viewport_depth_ptr(matrix4* res,
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 from origin, size, and depth range
[n, f]. -
void mat4_perspective_infinite_clip_ptr(matrix4* res,
const vm_
float_ t fov_y, const vm_ float_ t aspect, const vm_ float_ t n, const vm_ clip_ t clip) - Infinite perspective matrix for a chosen clip convention.
-
void mat4_perspective_infinite_clip_deg_ptr(matrix4* res,
const vm_
float_ t fov_y_deg, const vm_ float_ t aspect, const vm_ float_ t n, const vm_ clip_ t clip) - Infinite perspective matrix from FOV in degrees and clip space.
-
void mat4_infinite_reverse_z_ptr(matrix4* res,
const vm_
float_ t fov_y, const vm_ float_ t aspect, const vm_ float_ t n) - Infinite reverse-Z perspective matrix (RH, [0, 1] depth).
-
void mat4_infinite_reverse_z_clip_ptr(matrix4* res,
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 matrix for a chosen clip convention.
-
void mat4_infinite_reverse_z_deg_ptr(matrix4* res,
const vm_
float_ t fov_y_deg, const vm_ float_ t aspect, const 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,
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 matrix from FOV in degrees and clip space.
-
static auto vm_clip_is_zo(const vm_
clip_ t clip) -> int - Return true if clip uses a [0, 1] (ZO) depth range.
-
void vec3_world_to_window_clip_ptr(vector3* res,
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, viewport, and clip depth range.
- 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_clip_ptr(vector3* res,
const vector3* window,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
const vm_
clip_ t clip) - Un-projects a window-space point to world coordinates using model, projection, viewport, and clip depth range.
- 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.
Function documentation
void mat4_identity_ptr(matrix4* res)
Sets the matrix to the identity matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set to identity. |
The identity matrix is a 4x4 matrix with 1s on the main diagonal and 0s elsewhere.
VECMAT_ SCALAR_ API void mat4_mul_ptr_scalar(matrix4* res,
const matrix4* a,
const matrix4* b)
Multiplies two 4x4 matrices.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 where the result is stored. |
| a | Pointer to the first matrix4 operand. |
| b | Pointer to the second matrix4 operand. |
This function computes the product of two input matrices and stores the result in the provided matrix. The multiplication follows standard matrix multiplication rules.
VECMAT_ SCALAR_ API void mat4_transpose_ptr_scalar(matrix4* res,
const matrix4* m)
Transposes the given 4x4 matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 where the transposed result will be stored. |
| m | Pointer to the constant matrix4 to be transposed. |
This function computes the transpose of the input matrix, where the element at row i and column j becomes the element at row j and column i in the result matrix.
void mat4_mul_ptr(matrix4* res, const matrix4* a, const matrix4* b)
Multiplies two 4x4 matrices (dispatched).
| Parameters | |
|---|---|
| res | Result matrix. |
| a | Left matrix. |
| b | Right matrix. |
void mat4_transpose_ptr(matrix4* res, const matrix4* m)
Transposes a 4x4 matrix (dispatched).
| Parameters | |
|---|---|
| res | Result matrix. |
| m | Input matrix. |
void mat4_inverse_ptr(matrix4* res, const matrix4* m)
Computes the inverse of a 4x4 matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 where the inverse will be stored. |
| m | Pointer to the matrix4 to invert. |
This function calculates the inverse of the given 4x4 matrix using the adjugate matrix and determinant. If the matrix is singular (determinant is zero), the result is set to the identity matrix.
void mat4_translate_ptr(matrix4* res, const vector3* v)
Sets the matrix to a translation matrix.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set. |
| v | Pointer to the vector3 containing the translation values. |
This function initializes a 4x4 matrix to represent a translation transformation based on the provided vector, with the translation components placed in the last column and the rest forming an identity matrix.
void mat4_scale_ptr(matrix4* res, const vector3* v)
Sets the matrix to a scaling matrix using the provided scale vector.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to set as a scaling matrix. |
| v | Pointer to the vector3 containing the scale factors (x, y, z). |
This function constructs a 4x4 scaling matrix where the diagonal elements correspond to the x, y, and z scale factors from the input vector. The bottom-right element is set to 1.0f for homogeneous coordinates. All other elements are implicitly zero (not set, assuming the matrix is initialized).
void mat4_rotation_ptr(matrix4* res,
const vector3* axis,
const vm_ float_ t radians)
Sets the matrix to a rotation matrix around the given axis.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 that will receive the rotation matrix. |
| axis | Pointer to the vector3 representing the rotation axis. |
| radians | The rotation angle in radians. |
Constructs a 4x4 rotation matrix that rotates by the specified angle (in radians) around the provided axis. The axis vector is normalized internally.
void mat4_rotation_deg_ptr(matrix4* res,
const vector3* axis,
const vm_ float_ t degrees)
Sets the matrix to a rotation matrix using an axis and angle in degrees.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 that will receive the rotation matrix. |
| axis | Pointer to the vector3 defining the rotation axis. |
| degrees | The rotation angle in degrees. |
void mat4_rotation_x_ptr(matrix4* res,
const vm_ float_ t radians)
Builds a 4x4 rotation matrix around the X axis (radians).
| Parameters | |
|---|---|
| res | Result matrix. |
| radians | Rotation angle in radians. |
void mat4_rotation_x_deg_ptr(matrix4* res,
const vm_ float_ t degrees)
Builds a 4x4 rotation matrix around the X axis (degrees).
| Parameters | |
|---|---|
| res | Output value. |
| degrees | Rotation angle in degrees. |
void mat4_rotation_y_ptr(matrix4* res,
const vm_ float_ t radians)
Sets the matrix to a rotation matrix around the Y axis.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to store the result. |
| radians | Rotation angle in radians. |
void mat4_rotation_y_deg_ptr(matrix4* res,
const vm_ float_ t degrees)
Builds a 4x4 rotation matrix around the Y axis (degrees).
| Parameters | |
|---|---|
| res | Output value. |
| degrees | Rotation angle in degrees. |
void mat4_rotation_z_ptr(matrix4* res,
const vm_ float_ t radians)
Sets the matrix to a rotation around the Z axis.
| Parameters | |
|---|---|
| res | Pointer to the matrix4 to store the result. |
| radians | Rotation angle in radians. |
void mat4_rotation_z_deg_ptr(matrix4* res,
const vm_ float_ t degrees)
Builds a 4x4 rotation matrix around the Z axis (degrees).
| Parameters | |
|---|---|
| res | Output value. |
| degrees | Rotation angle in degrees. |
void mat4_from_mat3_ptr(matrix4* res, const matrix3* m)
Embeds a matrix3 into the upper-left of a matrix4.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void mat4_trs_ptr(matrix4* res, const vector3* translation, const quaternion* rotation, const vector3* scale)
Builds a 4x4 TRS matrix from translation, rotation, and scale.
| Parameters | |
|---|---|
| res | Output value. |
| translation | Translation vector. |
| rotation | Rotation quaternion. |
| scale | Scale vector. |
void mat4_extract_translation_ptr(vector3* res, const matrix4* m)
Extracts the translation vector from a matrix4.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void mat4_extract_scale_ptr(vector3* res, const matrix4* m)
Extracts the scale vector from a matrix4.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void mat4_extract_rotation_ptr(quaternion* res, const matrix4* m)
Extracts the rotation quaternion from a matrix4.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
void mat4_perspective_ptr(matrix4* res,
const vm_ float_ t fov,
const vm_ float_ t aspect,
const vm_ float_ t near,
const 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_deg_ptr(matrix4* res,
const vm_ float_ t fov_deg,
const vm_ float_ t aspect,
const vm_ float_ t near,
const 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_ortho_ptr(matrix4* res,
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)
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_perspective_fov_ptr(matrix4* res,
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)
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_fov_deg_ptr(matrix4* res,
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)
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_ptr(matrix4* res,
vm_ float_ t const fov_y,
vm_ float_ t const aspect,
vm_ float_ t const 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_deg_ptr(matrix4* res,
const vm_ float_ t fov_y_deg,
const vm_ float_ t aspect,
const 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. |
VECMAT_ SCALAR_ API void mat4_mul_vec4_ptr_scalar(vector4* res,
const matrix4* m,
const vector4* v)
Multiplies a 4x4 matrix by a vector4.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
| v | Input vector. |
void mat4_mul_vec4_ptr(vector4* res, const matrix4* m, const vector4* v)
Transforms a vector4 by a 4x4 matrix (dispatched).
| Parameters | |
|---|---|
| res | Result vector. |
| m | Input matrix. |
| v | Input vector. |
VECMAT_ SCALAR_ API void mat4_mul_vec3_ptr_scalar(vector3* res,
const matrix4* m,
const vector3* v,
const vm_ float_ t w)
Transforms a vector3 by a 4x4 matrix using homogeneous w.
| Parameters | |
|---|---|
| res | Output value. |
| m | Input matrix. |
| v | Input vector. |
| w | Homogeneous w component. |
void mat4_mul_vec3_ptr(vector3* res,
const matrix4* m,
const vector3* v,
const vm_ float_ t w)
Transforms a vector3 by a 4x4 matrix using homogeneous w (dispatched).
| Parameters | |
|---|---|
| res | Result vector. |
| m | Input matrix. |
| v | Input vector. |
| w | Homogeneous w component. |
void mat4_perspective_clip_ptr(matrix4* res,
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 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_clip_deg_ptr(matrix4* res,
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)
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,
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)
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,
const 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 mat4_inverse_affine_ptr(matrix4* res, const matrix4* m)
Inverse of an affine matrix [R t; 0 1].
| Parameters | |
|---|---|
| res | Output inverse matrix. |
| m | Affine 4×4 matrix. |
Inverts the upper-left 3×3 and corrects the translation. Last row is fixed as [0 0 0 1]. For a full 4×4 inverse, use mat4_. Singular 3×3 yields identity.
void mat4_normal_ptr(matrix4* res, const matrix4* m)
Inverse-transpose of the upper-left 3x3, embedded in a matrix4.
| Parameters | |
|---|---|
| res | Normal matrix as a matrix4. |
| m | Model matrix. |
Used to transform surface normals under a (possibly non-uniformly scaled) model matrix. Last row/column stay identity.
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,
const 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,
const vm_ float_ t x,
const vm_ float_ t y,
const vm_ float_ t width,
const 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,
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 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_infinite_clip_ptr(matrix4* res,
const vm_ float_ t fov_y,
const vm_ float_ t aspect,
const vm_ float_ t n,
const 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_perspective_infinite_clip_deg_ptr(matrix4* res,
const vm_ float_ t fov_y_deg,
const vm_ float_ t aspect,
const vm_ float_ t n,
const 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_ptr(matrix4* res,
const vm_ float_ t fov_y,
const vm_ float_ t aspect,
const 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,
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 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_infinite_reverse_z_deg_ptr(matrix4* res,
const vm_ float_ t fov_y_deg,
const vm_ float_ t aspect,
const 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,
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 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). |
static int vm_clip_is_zo(const vm_ clip_ t clip)
Return true if clip uses a [0, 1] (ZO) depth range.
| Parameters | |
|---|---|
| clip | Clip space convention. |
void vec3_world_to_window_clip_ptr(vector3* res,
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, 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_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_clip_ptr(vector3* res,
const vector3* window,
const matrix4* model,
const matrix4* projection,
const vector4* viewport,
const 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).
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).