SH4ZAM! 0.1.0
Fast math library for the Sega Dreamcast's SH4 CPU
Loading...
Searching...
No Matches
shz_matrix.h File Reference
#include "shz_vector.h"
#include "shz_quat.h"
#include "shz_xmtrx.h"
#include "inline/shz_matrix.inl.h"
Include dependency graph for shz_matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  shz_mat4x4_t
 

Typedefs

typedef shz_mat4x4_t shz_mat4x4
 

Functions

Initialization

Routines for fully initializing a matrix.

void shz_mat4x4_init_identity (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_identity_safe (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_zero (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_one (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_fill (shz_mat4x4_t *mat, float value) SHZ_NOEXCEPT
 
void shz_mat4x4_init_translation (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_init_scale (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_x (shz_mat4x4_t *mat, float xAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_y (shz_mat4x4_t *mat, float yAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_z (shz_mat4x4_t *mat, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_xyz (shz_mat4x4_t *mat, float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_zyx (shz_mat4x4_t *mat, float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_zxy (shz_mat4x4_t *mat, float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_yxz (shz_mat4x4_t *mat, float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation (shz_mat4x4_t *mat, float radians, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
 
void shz_mat4x4_init_rotation_quat (shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
 
void shz_mat4x4_init_diagonal (shz_mat4x4_t *mat, float x, float y, float z, float w) SHZ_NOEXCEPT
 
void shz_mat4x4_init_upper_triangular (shz_mat4x4_t *mat, float col1, shz_vec2_t col2, shz_vec3_t col3, shz_vec4_t col4) SHZ_NOEXCEPT
 
void shz_mat4x4_init_lower_triangular (shz_mat4x4_t *mat, shz_vec4_t col1, shz_vec3_t col2, shz_vec2_t col3, float col4) SHZ_NOEXCEPT
 
void shz_mat4x4_init_symmetric_skew (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_init_outer_product (shz_mat4x4_t *mat, shz_vec4_t v1, shz_vec4_t v2) SHZ_NOEXCEPT
 
void shz_mat4x4_init_permutation_wxyz (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_permutation_yzwx (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_init_screen (shz_mat4x4_t *mat, float width, float height) SHZ_NOEXCEPT
 
void shz_mat4x4_init_lookat (shz_mat4x4_t *mat, shz_vec3_t eye, shz_vec3_t center, shz_vec3_t up) SHZ_NOEXCEPT
 
void shz_mat4x4_init_ortho (shz_mat4x4_t *mat, float left, float right, float bottom, float top, float near, float far) SHZ_NOEXCEPT
 
void shz_mat4x4_init_frustum (shz_mat4x4_t *mat, float left, float right, float bottom, float top, float near, float far) SHZ_NOEXCEPT
 
void shz_mat4x4_init_perspective (shz_mat4x4_t *mat, float fov, float aspect, float near_z) SHZ_NOEXCEPT
 
Decomposition

Routines for decomposing a matrix into its constituent transforms.

void shz_mat4x4_decompose (const shz_mat4x4_t *mat, shz_vec3_t *translation, shz_quat_t *rotation, shz_vec3_t *scale) SHZ_NOEXCEPT
 
Getting

Routines for getting specific values within a matrix.

shz_vec4_t shz_mat4x4_row (const shz_mat4x4_t *mat, size_t row) SHZ_NOEXCEPT
 
shz_vec4_t shz_mat4x4_col (const shz_mat4x4_t *mat, size_t col) SHZ_NOEXCEPT
 
float shz_mat4x4_determinant (const shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
float shz_mat4x4_trace (const shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_3x3 (const shz_mat4x4_t *mat4, shz_mat3x3_t *mat3) SHZ_NOEXCEPT
 
void shz_mat4x4_3x3_inverse_unscaled (const shz_mat4x4_t *mat4, shz_mat3x3_t *invmat3) SHZ_NOEXCEPT
 
void shz_mat4x4_3x3_inverse (const shz_mat4x4_t *mat4, shz_mat3x3_t *invmat3) SHZ_NOEXCEPT
 
float shz_mat4x4_3x3_determinant (const shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
Setting

Routines for setting specific values within a matrix

void shz_mat4x4_set_row (shz_mat4x4_t *mat, size_t row, shz_vec4_t vec) SHZ_NOEXCEPT
 
void shz_mat4x4_set_col (shz_mat4x4_t *mat, size_t col, shz_vec4_t vec) SHZ_NOEXCEPT
 
void shz_mat4x4_swap_rows (shz_mat4x4_t *mat, size_t row1, size_t row2) SHZ_NOEXCEPT
 
void shz_mat4x4_swap_cols (shz_mat4x4_t *mat, size_t col1, size_t col2) SHZ_NOEXCEPT
 
void shz_mat4x4_set_translation (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_set_scale (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_set_rotation_quat (shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
 
void shz_mat4x4_set_diagonal (shz_mat4x4_t *mat, float x, float y, float z, float w) SHZ_NOEXCEPT
 
Applying

Routines for multiplying and accumulating onto the given matrix.

void shz_mat4x4_apply (shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_unaligned (shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_transpose (shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_transpose_unaligned (shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_translation (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_scale (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_x (shz_mat4x4_t *mat, float xAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_y (shz_mat4x4_t *mat, float yAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_z (shz_mat4x4_t *mat, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_xyz (shz_mat4x4_t *mat, float xAngle, float yAngle, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_zyx (shz_mat4x4_t *mat, float zAngle, float yAngle, float xAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_zxy (shz_mat4x4_t *mat, float zAngle, float xAngle, float yAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_yxz (shz_mat4x4_t *mat, float yAngle, float xAngle, float zAngle) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation (shz_mat4x4_t *mat, float angle, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_rotation_quat (shz_mat4x4_t *m, shz_quat_t q) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_lookat (shz_mat4x4_t *m, shz_vec3_t pos, shz_vec3_t target, shz_vec3_t up) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_perspective (shz_mat4x4_t *m, float fov, float aspect, float near_z) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_screen (shz_mat4x4_t *m, float width, float height) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_symmetric_skew (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_permutation_wxyz (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_permutation_yzwx (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_apply_self (shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
GL Transformations

OpenGL-style 4x4 matrix transforms.

void shz_mat4x4_translate (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_scale (shz_mat4x4_t *mat, float x, float y, float z) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_x (shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_y (shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_z (shz_mat4x4_t *mat, float radians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_xyz (shz_mat4x4_t *mat, float xRadians, float yRadians, float zRadians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_zyx (shz_mat4x4_t *mat, float zRadians, float yRadians, float xRadians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_zxy (shz_mat4x4_t *mat, float zRadians, float xRadians, float yRadians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate_yxz (shz_mat4x4_t *mat, float yRadians, float xRadians, float zRadians) SHZ_NOEXCEPT
 
void shz_mat4x4_rotate (shz_mat4x4_t *mat, float radians, float xAxis, float yAxis, float zAxis) SHZ_NOEXCEPT
 
Transforming

Routines for transforming vectors and points by a matrix.

void shz_mat4x4_mult (shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const shz_mat4x4_t *rhs) SHZ_NOEXCEPT
 
void shz_mat4x4_mult_unaligned (shz_mat4x4_t *mat, const shz_mat4x4_t *lhs, const float rhs[16]) SHZ_NOEXCEPT
 
shz_vec2_t shz_mat4x4_transform_vec2 (const shz_mat4x4_t *m, shz_vec2_t v) SHZ_NOEXCEPT
 
shz_vec3_t shz_mat4x4_transform_vec3 (const shz_mat4x4_t *m, shz_vec3_t v) SHZ_NOEXCEPT
 
shz_vec4_t shz_mat4x4_transform_vec4 (const shz_mat4x4_t *mat, shz_vec4_t in) SHZ_NOEXCEPT
 
shz_vec2_t shz_mat4x4_transform_vec2_transpose (const shz_mat4x4_t *m, shz_vec2_t v) SHZ_NOEXCEPT
 
shz_vec3_t shz_mat4x4_transform_vec3_transpose (const shz_mat4x4_t *m, shz_vec3_t v) SHZ_NOEXCEPT
 
shz_vec4_t shz_mat4x4_transform_vec4_transpose (const shz_mat4x4_t *m, shz_vec4_t v) SHZ_NOEXCEPT
 
shz_vec2_t shz_mat4x4_transform_point2 (const shz_mat4x4_t *mat, shz_vec2_t pt) SHZ_NOEXCEPT
 
shz_vec3_t shz_mat4x4_transform_point3 (const shz_mat4x4_t *mat, shz_vec3_t pt) SHZ_NOEXCEPT
 
shz_vec2_t shz_mat4x4_transform_point2_transpose (const shz_mat4x4_t *mat, shz_vec2_t pt) SHZ_NOEXCEPT
 
shz_vec3_t shz_mat4x4_transform_point3_transpose (const shz_mat4x4_t *mat, shz_vec3_t pt) SHZ_NOEXCEPT
 
Miscellaneous

Other matrix-related operations and routines

shz_quat_t shz_mat4x4_to_quat (const shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_transpose (const shz_mat4x4_t *mat, shz_mat4x4_t *out) SHZ_NOEXCEPT
 
void shz_mat4x4_inverse (const shz_mat4x4_t *SHZ_RESTRICT mtrx, shz_mat4x4_t *SHZ_RESTRICT out) SHZ_NOEXCEPT
 
void shz_mat4x4_inverse_block_triangular (const shz_mat4x4_t *mtx, shz_mat4x4_t *out) SHZ_NOEXCEPT
 
bool shz_mat4x4_equal (const shz_mat4x4_t *SHZ_RESTRICT mat1, const shz_mat4x4_t *mat2) SHZ_NOEXCEPT
 
bool shz_mat4x4_is_block_triangular (const shz_mat4x4_t *mat) SHZ_NOEXCEPT
 
void shz_mat4x4_copy (shz_mat4x4_t *dst, const shz_mat4x4_t *src) SHZ_NOEXCEPT
 
void shz_mat4x4_copy_unaligned (shz_mat4x4_t *dst, const float src[16]) SHZ_NOEXCEPT
 

Detailed Description

API for operating on MxN matrices within memory.

This file provides a collection of routines for manipulating MxN matrices which are stored within memory, rather than in the XMTRX FP register back-bank.

Some of these routines are simply loading into the back-bank and are performing work there, temporarily. Some of them have implementations which have specific optimizations for when the matrices are NOT within such registers, which are faster than having to go through XMTRX and clobbering the back-bank.

Todo
Author
2025, 2026 Falco Girgis
2025 Daniel Fairchild

Definition in file shz_matrix.h.

Typedef Documentation

◆ shz_mat4x4

Alternate shz_mat4x4_t C typedef for those who hate POSIX style.

Definition at line 88 of file shz_matrix.h.

Function Documentation

◆ shz_mat4x4_init_identity()

void shz_mat4x4_init_identity ( shz_mat4x4_t * mat)

Initializes the given matrix to the identity matrix as fast as possible.

Warning
This routine will NOT zero out NaNs properly!
This routine clobbers XMTRX.
See also
shz_mat4x4_init_identity_safe()

◆ shz_mat4x4_init_identity_safe()

void shz_mat4x4_init_identity_safe ( shz_mat4x4_t * mat)

Initializes the given matrix to the identity matrix, safely zeroing out NaN values.

Warning
This routine clobbers XMTRX.
See also
shz_mat4x4_init_identity()

◆ shz_mat4x4_init_zero()

void shz_mat4x4_init_zero ( shz_mat4x4_t * mat)

Initializes the given matrix with all 0s for its element values.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_one()

void shz_mat4x4_init_one ( shz_mat4x4_t * mat)

Initializes the given matrix with all 1s for its element values.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_fill()

void shz_mat4x4_init_fill ( shz_mat4x4_t * mat,
float value )

Initializes the given matrix with all elements assigned to the given value.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_translation()

void shz_mat4x4_init_translation ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Initializes the given matrix to a 3D translation matrix with the given coordinates.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_scale()

void shz_mat4x4_init_scale ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Initializes the given matrix to a 3D scaling matrix with the given dimensions.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_x()

void shz_mat4x4_init_rotation_x ( shz_mat4x4_t * mat,
float xAngle )

Initializes the given matrix to a 3D rotation matrix by xAngle radians over the X-axis.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_y()

void shz_mat4x4_init_rotation_y ( shz_mat4x4_t * mat,
float yAngle )

Initializes the given matrix to a 3D rotation matrix by yAngle radians over the Y-axis.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_z()

void shz_mat4x4_init_rotation_z ( shz_mat4x4_t * mat,
float zAngle )

Initializes the given matrix to a 3D rotation matrix by zAngle radians over the Z-axis.

Warning
This routine clobber XMTRX.

◆ shz_mat4x4_init_rotation_xyz()

void shz_mat4x4_init_rotation_xyz ( shz_mat4x4_t * mat,
float xAngle,
float yAngle,
float zAngle )

Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given Tait-Bryan X-Y-Z angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_zyx()

void shz_mat4x4_init_rotation_zyx ( shz_mat4x4_t * mat,
float zAngle,
float yAngle,
float xAngle )

Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given Tait-Bryan Z-Y-X angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_zxy()

void shz_mat4x4_init_rotation_zxy ( shz_mat4x4_t * mat,
float zAngle,
float xAngle,
float yAngle )

Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given Tait-Bryan Z-X-Y angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_yxz()

void shz_mat4x4_init_rotation_yxz ( shz_mat4x4_t * mat,
float yAngle,
float xAngle,
float zAngle )

Initializes the given matrix to a 3D rotation matrix from the intrinsic rotation created by the given Tait-Bryan Y-X-Z angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation()

void shz_mat4x4_init_rotation ( shz_mat4x4_t * mat,
float radians,
float xAxis,
float yAxis,
float zAxis )

Initializes the given matrix to a 3D rotation matrix about the given axis rotated by angle radians.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_rotation_quat()

void shz_mat4x4_init_rotation_quat ( shz_mat4x4_t * m,
shz_quat_t q )

Initializes the given matrix to a 3D rotation matrix with its orientation given by a quaternion.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_diagonal()

void shz_mat4x4_init_diagonal ( shz_mat4x4_t * mat,
float x,
float y,
float z,
float w )

Initializes the given matrix to a diagonal matrix with the given 4 values.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_upper_triangular()

void shz_mat4x4_init_upper_triangular ( shz_mat4x4_t * mat,
float col1,
shz_vec2_t col2,
shz_vec3_t col3,
shz_vec4_t col4 )

Initializes the given matrix to an upper triangular matrix whose nonzero entries have the given value.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_lower_triangular()

void shz_mat4x4_init_lower_triangular ( shz_mat4x4_t * mat,
shz_vec4_t col1,
shz_vec3_t col2,
shz_vec2_t col3,
float col4 )

Initializes the given matrix to a lower triangular matrix whose nonzero entries have the given value.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_symmetric_skew()

void shz_mat4x4_init_symmetric_skew ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Initializes the given matrix to be the symmetric skew of the given 3D vector components.

Note
This can be useful for batching the cross-product operation against a constant vector. For one-offs, prefer shz_vec3_cross().
Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_outer_product()

void shz_mat4x4_init_outer_product ( shz_mat4x4_t * mat,
shz_vec4_t v1,
shz_vec4_t v2 )

Initializes the given matrix to be the result from taking the outer product of the two given 4D vectors.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_permutation_wxyz()

void shz_mat4x4_init_permutation_wxyz ( shz_mat4x4_t * mat)

Initializes the matrix to to a permutation matrix, which reorders the components of transformed vectors to be in WXYZ order.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_permutation_yzwx()

void shz_mat4x4_init_permutation_yzwx ( shz_mat4x4_t * mat)

Initializes the matrix to to a permutation matrix, which reorders the components of transformed vectors to be in YZWX order.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_screen()

void shz_mat4x4_init_screen ( shz_mat4x4_t * mat,
float width,
float height )

Initializes the given matrix to the viewport matrix with the given dimenions.

See also
This routine clobbers XMTRX.

◆ shz_mat4x4_init_lookat()

void shz_mat4x4_init_lookat ( shz_mat4x4_t * mat,
shz_vec3_t eye,
shz_vec3_t center,
shz_vec3_t up )

Initializes the given matrix to a "lookAt" view matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_ortho()

void shz_mat4x4_init_ortho ( shz_mat4x4_t * mat,
float left,
float right,
float bottom,
float top,
float near,
float far )

Initializes the given matrix to an orthographic projection matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_frustum()

void shz_mat4x4_init_frustum ( shz_mat4x4_t * mat,
float left,
float right,
float bottom,
float top,
float near,
float far )

Initializes the given matrix to a frustum projection matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_init_perspective()

void shz_mat4x4_init_perspective ( shz_mat4x4_t * mat,
float fov,
float aspect,
float near_z )

Initializes the given matrix to a perspective projection matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_decompose()

void shz_mat4x4_decompose ( const shz_mat4x4_t * mat,
shz_vec3_t * translation,
shz_quat_t * rotation,
shz_vec3_t * scale )

Decomposes a 4x4 transform matrix into translation, rotation, and scale.

Note
Any output pointer may be NULL to skip that component.
Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_row()

shz_vec4_t shz_mat4x4_row ( const shz_mat4x4_t * mat,
size_t row )

Extracts the row index as a 4D row vector from the given matrix.

◆ shz_mat4x4_col()

shz_vec4_t shz_mat4x4_col ( const shz_mat4x4_t * mat,
size_t col )

Extracts the col index as a 4D column vector from the given matrix.

◆ shz_mat4x4_determinant()

float shz_mat4x4_determinant ( const shz_mat4x4_t * mat)

Returns the determinant of the given 4x4 matrix.

◆ shz_mat4x4_trace()

float shz_mat4x4_trace ( const shz_mat4x4_t * mat)

Returns the trace of the given 4x4 matrix.

◆ shz_mat4x4_3x3()

void shz_mat4x4_3x3 ( const shz_mat4x4_t * mat4,
shz_mat3x3_t * mat3 )

Extracts the top-left 3x3 of the given 4D matrix.

◆ shz_mat4x4_3x3_inverse_unscaled()

void shz_mat4x4_3x3_inverse_unscaled ( const shz_mat4x4_t * mat4,
shz_mat3x3_t * invmat3 )

Extracts and inverts the top-level, unscaled 3x3 of the given 4x4 matrix.

◆ shz_mat4x4_3x3_inverse()

void shz_mat4x4_3x3_inverse ( const shz_mat4x4_t * mat4,
shz_mat3x3_t * invmat3 )

Extracts and inverts the top-level 3x3 (which may be scaled) of the given 4x4 matrix.

◆ shz_mat4x4_3x3_determinant()

float shz_mat4x4_3x3_determinant ( const shz_mat4x4_t * mat)

Returns the determinant of the given 4x4 matrix's internal top-level 3x3 matrix.

◆ shz_mat4x4_set_row()

void shz_mat4x4_set_row ( shz_mat4x4_t * mat,
size_t row,
shz_vec4_t vec )

Sets the values of mat at the given row to those of the 4D vector, vec.

◆ shz_mat4x4_set_col()

void shz_mat4x4_set_col ( shz_mat4x4_t * mat,
size_t col,
shz_vec4_t vec )

Sets the values of mat at the given col to those of the 4D vector, vec.

◆ shz_mat4x4_swap_rows()

void shz_mat4x4_swap_rows ( shz_mat4x4_t * mat,
size_t row1,
size_t row2 )

Swaps the 4D row vectors located at row1 and row2 within mat.

◆ shz_mat4x4_swap_cols()

void shz_mat4x4_swap_cols ( shz_mat4x4_t * mat,
size_t col1,
size_t col2 )

Swaps the 4D column vectors located at col1 and col2 within mat.

◆ shz_mat4x4_set_translation()

void shz_mat4x4_set_translation ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Assigns only the 3D translation-related elements of the given matrix to the given values.

◆ shz_mat4x4_set_scale()

void shz_mat4x4_set_scale ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Assigns only the 3D scale-related elements of the given matrix to the given values.

◆ shz_mat4x4_set_rotation_quat()

void shz_mat4x4_set_rotation_quat ( shz_mat4x4_t * m,
shz_quat_t q )

Sets just the rotational component of the matrix to the orientation given by a quaternion, keeping the other elements in-tact.

◆ shz_mat4x4_set_diagonal()

void shz_mat4x4_set_diagonal ( shz_mat4x4_t * mat,
float x,
float y,
float z,
float w )

Assigns only the 4 elements along the diagonal of the given matrix to the given values.

◆ shz_mat4x4_apply()

void shz_mat4x4_apply ( shz_mat4x4_t * dst,
const shz_mat4x4_t * src )

Multiplies and accumulates the src 4x4 matrix onto the dst 4x4 matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_unaligned()

void shz_mat4x4_apply_unaligned ( shz_mat4x4_t * dst,
const float src[16] )

Multiplies and accumulates the unaligned src 4x4 matrix onto the dst 4x4 matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_transpose()

void shz_mat4x4_apply_transpose ( shz_mat4x4_t * dst,
const shz_mat4x4_t * src )

Multiplies and accumulates the transposed src 4x4 matrix onto the dst 4x4 matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_transpose_unaligned()

void shz_mat4x4_apply_transpose_unaligned ( shz_mat4x4_t * dst,
const float src[16] )

Multiplies and accumulates the transposed unaligned src 4x4 matrix onto the dst 4x4 matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_translation()

void shz_mat4x4_apply_translation ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Adds the given 3D vector components to the translational values of the given matrix.

Note
This routine does not use XMTRX.

◆ shz_mat4x4_apply_scale()

void shz_mat4x4_apply_scale ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Multiplies and accumulates the scale-related elements of the given matrix by the given 3D components.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_x()

void shz_mat4x4_apply_rotation_x ( shz_mat4x4_t * mat,
float xAngle )

Multiplies and accumulates a rotation matrix by xAngle radians about the X-axis onto the given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_y()

void shz_mat4x4_apply_rotation_y ( shz_mat4x4_t * mat,
float yAngle )

Multiplies and accumulates a rotation matrix by yAngle radians about the Y-axis onto the given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_z()

void shz_mat4x4_apply_rotation_z ( shz_mat4x4_t * mat,
float zAngle )

Multiplies and accumulates a rotation matrix by zAngle radians about the Z-axis onto the given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_xyz()

void shz_mat4x4_apply_rotation_xyz ( shz_mat4x4_t * mat,
float xAngle,
float yAngle,
float zAngle )

Rotates the given transform matrix about the X axis, then the Y axis, then the Z axis by the given angles in radians.

Multiplies and accumulates the given matrix with the 3D rotation matrix formed from the intrinsic rotation created by the given Tait-Bryan X-Y-Z angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_zyx()

void shz_mat4x4_apply_rotation_zyx ( shz_mat4x4_t * mat,
float zAngle,
float yAngle,
float xAngle )

Rotates the given transform matrix about the Z axis, then the Y axis, then the X axis by the given angles in radians.

Multiplies and accumulates the given matrix with the 3D rotation matrix formed from the intrinsic rotation created by the given Tait-Bryan Z-Y-X angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_zxy()

void shz_mat4x4_apply_rotation_zxy ( shz_mat4x4_t * mat,
float zAngle,
float xAngle,
float yAngle )

Rotates the given transform matrix about the Z axis, then the X axis, then the Y axis by the given angles in radians.

Multiplies and accumulates the given matrix with the 3D rotation matrix formed from the intrinsic rotation created by the given Tait-Bryan Z-Y-X angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_yxz()

void shz_mat4x4_apply_rotation_yxz ( shz_mat4x4_t * mat,
float yAngle,
float xAngle,
float zAngle )

Rotates the given transform matrix about the Y axis, then the X axis, then the Z axis by the given angles in radians.

Multiplies and accumulates the given matrix with the 3D rotation matrix formed from the intrinsic rotation created by the given Tait-Bryan Y-X-Z angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation()

void shz_mat4x4_apply_rotation ( shz_mat4x4_t * mat,
float angle,
float xAxis,
float yAxis,
float zAxis )

Rotates the given transform matrix about the arbitrary axis given by a 3D direction vector and angle of rotation in radians.

Multiplies and accumulates the given matrix with the 3D rotation matrix formed from the intrinsic rotation created by the given Tait-Bryan Z-Y-X angles.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_rotation_quat()

void shz_mat4x4_apply_rotation_quat ( shz_mat4x4_t * m,
shz_quat_t q )

Multiplies and accumulates the given matrix with a rotation matrix whose orientation is given by a quaternion.

Note
This routine does not use XMTRX.

◆ shz_mat4x4_apply_lookat()

void shz_mat4x4_apply_lookat ( shz_mat4x4_t * m,
shz_vec3_t pos,
shz_vec3_t target,
shz_vec3_t up )

Applies the 3D "lookAt" matrix constructed with the given vector components onto the given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_perspective()

void shz_mat4x4_apply_perspective ( shz_mat4x4_t * m,
float fov,
float aspect,
float near_z )

Multiplies and accumulates the perspective matrix constructed from the given values onto the given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_screen()

void shz_mat4x4_apply_screen ( shz_mat4x4_t * m,
float width,
float height )

Multiplies and accumulates the viewport matrix created with the given components ont othe given matrix.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_symmetric_skew()

void shz_mat4x4_apply_symmetric_skew ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Multiplies and accumulates the given matrix with a symmetric skew matrix formed from the given 3D vector components.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_permutation_wxyz()

void shz_mat4x4_apply_permutation_wxyz ( shz_mat4x4_t * mat)

Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors to be in WXYZ order.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_permutation_yzwx()

void shz_mat4x4_apply_permutation_yzwx ( shz_mat4x4_t * mat)

Multiplies and accumulates a permutation matrix, which reorders the components of transformed vectors to be in YZWX order.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_apply_self()

void shz_mat4x4_apply_self ( shz_mat4x4_t * mat)

Multiplies and accumulates the given matrix onto itself.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_translate()

void shz_mat4x4_translate ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Multiplies and accumulates mat by a 3D translation matrix with the given components.

Note
glTranslatef() equivalent.
Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_scale()

void shz_mat4x4_scale ( shz_mat4x4_t * mat,
float x,
float y,
float z )

Multiplies and accumulates mat by a 3D scaling matrix with the given components.

Note
glScalef() equivalent.
Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_x()

void shz_mat4x4_rotate_x ( shz_mat4x4_t * mat,
float radians )

Multiplies and accumulates mat by a 3D rotation matrix about the X axis.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_y()

void shz_mat4x4_rotate_y ( shz_mat4x4_t * mat,
float radians )

Multiplies and accumulates mat by a 3D rotation matrix about the Y axis.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_z()

void shz_mat4x4_rotate_z ( shz_mat4x4_t * mat,
float radians )

Multiplies and accumulates mat by a 3D rotation matrix about the Z axis.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_xyz()

void shz_mat4x4_rotate_xyz ( shz_mat4x4_t * mat,
float xRadians,
float yRadians,
float zRadians )

Multiplies and accumulates mat by 3D rotation matrices about the X then Y then Z axes.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_zyx()

void shz_mat4x4_rotate_zyx ( shz_mat4x4_t * mat,
float zRadians,
float yRadians,
float xRadians )

Multiplies and accumulates mat by 3D rotation matrices about the Z then Y then X axes.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_zxy()

void shz_mat4x4_rotate_zxy ( shz_mat4x4_t * mat,
float zRadians,
float xRadians,
float yRadians )

Multiplies and accumulates mat by 3D rotation matrices about the Z then X then Y axes.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate_yxz()

void shz_mat4x4_rotate_yxz ( shz_mat4x4_t * mat,
float yRadians,
float xRadians,
float zRadians )

Multiplies and accumulates mat by 3D rotation matrices about the Y then X then Z axes.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_rotate()

void shz_mat4x4_rotate ( shz_mat4x4_t * mat,
float radians,
float xAxis,
float yAxis,
float zAxis )

Multiplies and accumulates mat by the 3D rotation matrix formed by the given axis and angle.

Note
Equivalent to glRotatef().
Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_mult()

void shz_mat4x4_mult ( shz_mat4x4_t * mat,
const shz_mat4x4_t * lhs,
const shz_mat4x4_t * rhs )

Multiplies two 4x4 matrices together, storing the result into a third.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_mult_unaligned()

void shz_mat4x4_mult_unaligned ( shz_mat4x4_t * mat,
const shz_mat4x4_t * lhs,
const float rhs[16] )

Multiplies two 4x4 matrices together, with the right handed matrix being unaligned, storing the result into a third.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_transform_vec2()

shz_vec2_t shz_mat4x4_transform_vec2 ( const shz_mat4x4_t * m,
shz_vec2_t v )

Transforms a 2D vector by a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 2D vector by a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 2D vectors against the same 4x4 matrix, preload the matrix into XMTRX, then use shz_xmtrx_trans_vec2().
See also
shz_mat4x4_transform_vec2(), shz_xmtrx_transform_vec3()

◆ shz_mat4x4_transform_vec3()

shz_vec3_t shz_mat4x4_transform_vec3 ( const shz_mat4x4_t * m,
shz_vec3_t v )

Transforms a 3D vector by a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 3D vector (such as a normal, without a W component) by a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 3D vectors against the same 4x4 matrix, preload the matrix into XMTRX, then use shz_xmtrx_trans_vec3().
See also
shz_mat4x4_transform_vec4(), shz_xmtrx_transform_vec3()

◆ shz_mat4x4_transform_vec4()

shz_vec4_t shz_mat4x4_transform_vec4 ( const shz_mat4x4_t * mat,
shz_vec4_t in )

Transforms a 4D vector by a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 4D vector by a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 4D vectors against the same 4x4 matrix, preload the matrix into XMTRX, then use shz_xmtrx_trans_vec4().
See also
shz_mat4x4_transform_vec3(), shz_xmtrx_transform_vec4()

◆ shz_mat4x4_transform_vec2_transpose()

shz_vec2_t shz_mat4x4_transform_vec2_transpose ( const shz_mat4x4_t * m,
shz_vec2_t v )

Transforms a 2D vector the the transpose of a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 2D vector by the transpose of a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 2D vectors against the transpose of the same 4x4 matrix, preload the matrix into XMTRX, take its transpose with shz_xmtrx_transpose(), then use shz_xmtrx_transform_vec2().
See also
shz_xmtrx_transpose(), shz_xmtrx_transform_vec2().

◆ shz_mat4x4_transform_vec3_transpose()

shz_vec3_t shz_mat4x4_transform_vec3_transpose ( const shz_mat4x4_t * m,
shz_vec3_t v )

Transforms a 3D vector the the transpose of a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 3D vector by the transpose of a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 3D vectors against the transpose of the same 4x4 matrix, preload the matrix into XMTRX, take its transpose with shz_xmtrx_transpose(), then use shz_xmtrx_transform_vec3().
See also
shz_xmtrx_transpose(), shz_xmtrx_transform_vec3().

◆ shz_mat4x4_transform_vec4_transpose()

shz_vec4_t shz_mat4x4_transform_vec4_transpose ( const shz_mat4x4_t * m,
shz_vec4_t v )

Transforms a 4D vector the the transpose of a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 4D vector by the transpose of a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 4D vectors against the transpose of the same 4x4 matrix, preload the matrix into XMTRX, take its transpose with shz_xmtrx_transpose(), then use shz_xmtrx_transform_vec4().
See also
shz_xmtrx_transpose(), shz_xmtrx_transform_vec4().

◆ shz_mat4x4_transform_point2()

shz_vec2_t shz_mat4x4_transform_point2 ( const shz_mat4x4_t * mat,
shz_vec2_t pt )

Transforms a 2D point by a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 2D point by a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 2D points against the same 4x4 matrix, preload the matrix into XMTRX, then use shz_xmtrx_transform_point2().
See also
shz_xmtrx_transform_point2()

◆ shz_mat4x4_transform_point3()

shz_vec3_t shz_mat4x4_transform_point3 ( const shz_mat4x4_t * mat,
shz_vec3_t pt )

Transforms a 3D point by a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 3D point by a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 3D points against the same 4x4 matrix, preload the matrix into XMTRX, then use shz_xmtrx_transform_point3().
See also
shz_xmtrx_transform_point3()

◆ shz_mat4x4_transform_point2_transpose()

shz_vec2_t shz_mat4x4_transform_point2_transpose ( const shz_mat4x4_t * mat,
shz_vec2_t pt )

Transforms a 2D point by the transpose of a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 2D point by the transpose of a a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 2D points against the same 4x4 matrix, preload the matrix into XMTRX, use shz_xmtrx_transpose(), then use shz_xmtrx_transform_point2().
See also
shz_xmtrx_transpose(), shz_xmtrx_transform_point2()

◆ shz_mat4x4_transform_point3_transpose()

shz_vec3_t shz_mat4x4_transform_point3_transpose ( const shz_mat4x4_t * mat,
shz_vec3_t pt )

Transforms a 3D point by the transpose of a 4x4 matrix.

This is a routine specializing in one-off transforms of a single 3D point by the transpose of a a single 4x4 matrix. It should be faster than going through XMTRX.

Note
For batch transforming multiple 3D points against the same 4x4 matrix, preload the matrix into XMTRX, use shz_xmtrx_transpose(), then use shz_xmtrx_transform_point2().
See also
shz_xmtrx_transpose(), shz_xmtrx_transform_point3()

◆ shz_mat4x4_to_quat()

shz_quat_t shz_mat4x4_to_quat ( const shz_mat4x4_t * mat)

Converts the given 4x4 orientation matrix into a quaternion.

◆ shz_mat4x4_transpose()

void shz_mat4x4_transpose ( const shz_mat4x4_t * mat,
shz_mat4x4_t * out )

Stores the transpose of mat within out.

Warning
This routine clobbers XMTRX.

◆ shz_mat4x4_inverse()

void shz_mat4x4_inverse ( const shz_mat4x4_t *SHZ_RESTRICT mtrx,
shz_mat4x4_t *SHZ_RESTRICT out )

Computes the inverse of a 4x4 matrix.

Note
In-place inversion (mtrx == out) is not supported.
Warning
This routine clobbers XMTRX.
Parameters
mtrxPointer to the 4x4 matrix to invert.
outPointer to the resulting inverted matrix.

◆ shz_mat4x4_inverse_block_triangular()

void shz_mat4x4_inverse_block_triangular ( const shz_mat4x4_t * mtx,
shz_mat4x4_t * out )

Computes the inverse of a 4x4 matrix in block-triangular form.

This is a special-case faster optimization for 4x4 matrices which take the form:

A = [ M   b ]
    [ 0   w ]

Where A is 4x4, M is 3x3, b is 3x1, and the bottom row is (0, 0, 0, w) with w != 0. For this block-triangular form, det(A) = det(M) * w. Then

inv(A) = [ inv(M)        -inv(M) * b / w ]
         [   0                 1/w       ]
Note
A regular 3D transform matrix is already in this form.
shz_mat4x4_inverse() will dynamically check whether to use this optimization.

◆ shz_mat4x4_equal()

bool shz_mat4x4_equal ( const shz_mat4x4_t *SHZ_RESTRICT mat1,
const shz_mat4x4_t * mat2 )

Returns true if the two matrices are equal, based on either absolute or relative tolerance.

◆ shz_mat4x4_is_block_triangular()

bool shz_mat4x4_is_block_triangular ( const shz_mat4x4_t * mat)

Returns true if the given matrix is in block-triangular form: having a bottom row in the form of <0.0f, 0.0f, 0.0f, w>.

◆ shz_mat4x4_copy()

void shz_mat4x4_copy ( shz_mat4x4_t * dst,
const shz_mat4x4_t * src )

Copies the given src 4x4 matrix into the given dst 4x4 matrix.

Warning
This routine clobbers XMTRX!

◆ shz_mat4x4_copy_unaligned()

void shz_mat4x4_copy_unaligned ( shz_mat4x4_t * dst,
const float src[16] )

Copies the given unaligned src 4x4 matrix into the given dst 4x4 matrix.

Warning
This routine clobbers XMtRX.