Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
matrix4.c File Reference
#include <vecmat.h>

Go to the source code of this file.

Functions

matrix4 mat4_identity (void)
 Constructs the 4x4 identity matrix.
matrix4 mat4_mul (const matrix4 a, const matrix4 b)
 Multiplies two 4x4 matrices (a * b).
matrix4 mat4_transpose (const matrix4 m)
 Computes the transpose of a 4x4 matrix.
matrix4 mat4_inverse (const matrix4 m)
 Computes the inverse of a 4x4 matrix.
matrix4 mat4_translate (const vector3 v)
 Constructs a translation matrix from the given vector.
matrix4 mat4_scale (const vector3 v)
 Constructs a scaling matrix from the given scale vector.
matrix4 mat4_rotation (const vector3 axis, const vm_float_t angle)
 Constructs a rotation matrix around the given axis by the specified angle (in radians).
matrix4 mat4_perspective (const vm_float_t fov, const vm_float_t aspect, const vm_float_t near, const vm_float_t far)
 Constructs a perspective projection matrix.
matrix4 mat4_ortho (const vm_float_t left, const vm_float_t right, const vm_float_t bottom, const vm_float_t top, const vm_float_t near, const vm_float_t far)
 Constructs an orthographic projection matrix.
matrix4 mat4_look_at (const vector3 position, const vector3 target, const vector3 up)
 Constructs a view matrix from eye position, target, and up vector.
matrix4 mat4_perspective_fov (const vm_float_t fov, const vm_float_t w, const vm_float_t h, const vm_float_t n, const vm_float_t f)
 Constructs a perspective projection matrix using FOV, width, and height.
matrix4 mat4_perspective_infinite (const vm_float_t fov_y, const vm_float_t aspect, const vm_float_t n)
 Constructs an infinite far-plane perspective projection matrix.
vm_float_t mat4_determinant (const matrix4 m)
 Calculates the determinant of the given 4x4 matrix.
vector4 mat4_mul_vec4 (const matrix4 m, const vector4 v)
 Multiplies a 4x4 matrix by a vector4.
vector3 mat4_mul_vec3 (const matrix4 m, const vector3 v, const vm_float_t w)
 Transforms a vector3 by a 4x4 matrix using homogeneous w.
matrix4 mat4_rotation_x (const vm_float_t degrees)
 Builds a 4x4 rotation matrix around the X axis (degrees).
matrix4 mat4_rotation_y (const vm_float_t degrees)
 Builds a 4x4 rotation matrix around the Y axis (degrees).
matrix4 mat4_rotation_z (const vm_float_t degrees)
 Builds a 4x4 rotation matrix around the Z axis (degrees).
matrix4 mat4_trs (const vector3 translation, const quaternion rotation, const vector3 scale)
 Builds a 4x4 TRS matrix from translation, rotation, and scale.
matrix4 mat4_from_mat3 (const matrix3 m)
 Embeds a matrix3 into the upper-left of a matrix4.
vector3 mat4_extract_translation (const matrix4 m)
 Extracts the translation vector from a matrix4.
vector3 mat4_extract_scale (const matrix4 m)
 Extracts the scale vector from a matrix4.
quaternion mat4_extract_rotation (const matrix4 m)
 Extracts the rotation quaternion from a matrix4.

Function Documentation

◆ mat4_determinant()

vm_float_t mat4_determinant ( const matrix4 m)

Calculates the determinant of the given 4x4 matrix.

Uses cofactor expansion for computation.

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

Definition at line 214 of file matrix4.c.

References matrix4::v.

◆ mat4_extract_rotation()

quaternion mat4_extract_rotation ( const matrix4 m)

Extracts the rotation quaternion from a matrix4.

See mat4_extract_rotation_ptr instead.

Parameters
mInput matrix.
Returns
The resulting quaternion.

Definition at line 379 of file matrix4.c.

References mat4_extract_rotation_ptr().

◆ mat4_extract_scale()

vector3 mat4_extract_scale ( const matrix4 m)

Extracts the scale vector from a matrix4.

See mat4_extract_scale_ptr instead.

Parameters
mInput matrix.
Returns
The resulting vector3.

Definition at line 364 of file matrix4.c.

References mat4_extract_scale_ptr().

◆ mat4_extract_translation()

vector3 mat4_extract_translation ( const matrix4 m)

Extracts the translation vector from a matrix4.

See mat4_extract_translation_ptr instead.

Parameters
mInput matrix.
Returns
The resulting vector3.

Definition at line 349 of file matrix4.c.

References mat4_extract_translation_ptr().

◆ mat4_from_mat3()

matrix4 mat4_from_mat3 ( const matrix3 m)

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

See mat4_from_mat3_ptr instead.

Parameters
mInput matrix.
Returns
The resulting matrix4.

Definition at line 334 of file matrix4.c.

References mat4_from_mat3_ptr().

◆ mat4_identity()

matrix4 mat4_identity ( void )

Constructs the 4x4 identity matrix.

See mat4_identity_ptr instead.

Returns
The identity matrix4.

Definition at line 14 of file matrix4.c.

References mat4_identity_ptr().

Referenced by mat4_look_at_ptr().

◆ mat4_inverse()

matrix4 mat4_inverse ( const matrix4 m)

Computes the inverse of a 4x4 matrix.

See mat4_inverse_ptr instead.

Parameters
mThe input matrix.
Returns
The inverse matrix4.

Definition at line 60 of file matrix4.c.

References mat4_inverse_ptr().

◆ mat4_look_at()

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

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

See mat4_look_at_ptr instead.

Parameters
positionEye position.
targetTarget position.
upUp vector.
Returns
The view matrix4.

Definition at line 162 of file matrix4.c.

References mat4_look_at_ptr().

◆ mat4_mul()

matrix4 mat4_mul ( const matrix4 a,
const matrix4 b )

Multiplies two 4x4 matrices (a * b).

See mat4_mul_ptr instead.

Parameters
aThe first matrix.
bThe second matrix.
Returns
The resulting product matrix4.

Definition at line 30 of file matrix4.c.

References mat4_mul_ptr().

◆ mat4_mul_vec3()

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

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

See mat4_mul_vec3_ptr instead.

Parameters
mInput matrix.
vInput vector.
wHomogeneous w component.
Returns
The resulting vector3.

Definition at line 257 of file matrix4.c.

References mat4_mul_vec3_ptr().

◆ mat4_mul_vec4()

vector4 mat4_mul_vec4 ( const matrix4 m,
const vector4 v )

Multiplies a 4x4 matrix by a vector4.

See mat4_mul_vec4_ptr instead.

Parameters
mInput matrix.
vInput vector.
Returns
The resulting vector4.

Definition at line 240 of file matrix4.c.

References mat4_mul_vec4_ptr().

◆ mat4_ortho()

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

Constructs an orthographic projection matrix.

See mat4_ortho_ptr instead.

Parameters
leftLeft clipping plane.
rightRight clipping plane.
bottomBottom clipping plane.
topTop clipping plane.
nearNear plane distance.
farFar plane distance.
Returns
The orthographic matrix4.

Definition at line 144 of file matrix4.c.

References mat4_ortho_ptr().

◆ mat4_perspective()

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

Constructs a perspective projection matrix.

See mat4_perspective_ptr instead.

Parameters
fovField of view (radians).
aspectAspect ratio (width/height).
nearNear plane distance.
farFar plane distance.
Returns
The perspective matrix4.

Definition at line 124 of file matrix4.c.

References mat4_perspective_ptr().

◆ mat4_perspective_fov()

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

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

See mat4_perspective_fov_ptr instead.

Parameters
fovVertical field of view (radians).
wViewport width.
hViewport height.
nNear plane.
fFar plane.
Returns
The perspective matrix4.

Definition at line 181 of file matrix4.c.

References mat4_perspective_fov_ptr().

◆ mat4_perspective_infinite()

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

Constructs an infinite far-plane perspective projection matrix.

See mat4_perspective_infinite_ptr instead.

Parameters
fov_yVertical field of view (radians).
aspectAspect ratio.
nNear plane distance.
Returns
The perspective matrix4.

Definition at line 199 of file matrix4.c.

References mat4_perspective_infinite_ptr().

◆ mat4_rotation()

matrix4 mat4_rotation ( const vector3 axis,
const vm_float_t angle )

Constructs a rotation matrix around the given axis by the specified angle (in radians).

See mat4_rotation_ptr instead.

Parameters
axisThe rotation axis vector.
angleThe rotation angle in radians.
Returns
The rotation matrix4.

Definition at line 106 of file matrix4.c.

References mat4_rotation_ptr().

◆ mat4_rotation_x()

matrix4 mat4_rotation_x ( const vm_float_t degrees)

Builds a 4x4 rotation matrix around the X axis (degrees).

See mat4_rotation_x_ptr instead.

Parameters
degreesRotation angle in degrees.
Returns
The resulting matrix4.

Definition at line 272 of file matrix4.c.

References mat4_rotation_x_ptr().

◆ mat4_rotation_y()

matrix4 mat4_rotation_y ( const vm_float_t degrees)

Builds a 4x4 rotation matrix around the Y axis (degrees).

See mat4_rotation_y_ptr instead.

Parameters
degreesRotation angle in degrees.
Returns
The resulting matrix4.

Definition at line 287 of file matrix4.c.

References mat4_rotation_y_ptr().

◆ mat4_rotation_z()

matrix4 mat4_rotation_z ( const vm_float_t degrees)

Builds a 4x4 rotation matrix around the Z axis (degrees).

See mat4_rotation_z_ptr instead.

Parameters
degreesRotation angle in degrees.
Returns
The resulting matrix4.

Definition at line 302 of file matrix4.c.

References mat4_rotation_z_ptr().

◆ mat4_scale()

matrix4 mat4_scale ( const vector3 v)

Constructs a scaling matrix from the given scale vector.

See mat4_scale_ptr instead.

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

Definition at line 90 of file matrix4.c.

References mat4_scale_ptr().

◆ mat4_translate()

matrix4 mat4_translate ( const vector3 v)

Constructs a translation matrix from the given vector.

See mat4_translate_ptr instead.

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

Definition at line 75 of file matrix4.c.

References mat4_translate_ptr().

◆ mat4_transpose()

matrix4 mat4_transpose ( const matrix4 m)

Computes the transpose of a 4x4 matrix.

See mat4_transpose_ptr instead.

Parameters
mThe input matrix.
Returns
The transposed matrix4.

Definition at line 45 of file matrix4.c.

References mat4_transpose_ptr().

◆ mat4_trs()

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

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

See mat4_trs_ptr instead.

Parameters
translationTranslation vector.
rotationRotation quaternion.
scaleScale vector.
Returns
The resulting matrix4.

Definition at line 319 of file matrix4.c.

References mat4_trs_ptr().