|
Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
|
Go to the source code of this file.
Functions | |
| void | mat4_identity_ptr (matrix4 *res) |
| Sets the matrix to the identity matrix. | |
| VECMAT_SCALAR_API void | mat4_mul_ptr_scalar (matrix4 *res, const matrix4 *a, const matrix4 *b) |
| Multiplies two 4x4 matrices. | |
| VECMAT_SCALAR_API void | mat4_transpose_ptr_scalar (matrix4 *res, const matrix4 *m) |
| Transposes the given 4x4 matrix. | |
| void | mat4_mul_ptr (matrix4 *res, const matrix4 *a, const matrix4 *b) |
| void | mat4_transpose_ptr (matrix4 *res, const matrix4 *m) |
| 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 angle) |
| Sets the matrix to a rotation matrix around the specified axis by the given angle. | |
| void | mat4_rotation_x_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 degrees) |
| Builds a 4x4 rotation matrix around the Y axis (degrees). | |
| void | mat4_rotation_z_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_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_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. | |
| VECMAT_SCALAR_API void | mat4_mul_vec4_ptr_scalar (vector4 *res, const matrix4 *m, const vector4 *v) |
| Multiplies a 4x4 matrix by a vector4. | |
| void | mat4_mul_vec4_ptr (vector4 *res, const matrix4 *m, const vector4 *v) |
| 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. | |
| void | mat4_mul_vec3_ptr (vector3 *res, const matrix4 *m, const vector3 *v, const vm_float_t w) |
| void mat4_extract_rotation_ptr | ( | quaternion * | res, |
| const matrix4 * | m ) |
Extracts the rotation quaternion from a matrix4.
| res | Output value. |
| m | Input matrix. |
Definition at line 336 of file matrix4_ptr.c.
References matrix3::m11, matrix4::m11, matrix3::m12, matrix4::m12, matrix3::m13, matrix4::m13, matrix3::m21, matrix4::m21, matrix3::m22, matrix4::m22, matrix3::m23, matrix4::m23, matrix3::m31, matrix4::m31, matrix3::m32, matrix4::m32, matrix3::m33, matrix4::m33, mat4_extract_scale_ptr(), quat_from_mat3_ptr(), vector3::x, vector3::y, and vector3::z.
Referenced by mat4_extract_rotation().
Extracts the scale vector from a matrix4.
| res | Output value. |
| m | Input matrix. |
Definition at line 323 of file matrix4_ptr.c.
References matrix4::m11, matrix4::m12, matrix4::m13, matrix4::m21, matrix4::m22, matrix4::m23, matrix4::m31, matrix4::m32, matrix4::m33, VECMAT_SQRT, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_extract_rotation_ptr(), and mat4_extract_scale().
Extracts the translation vector from a matrix4.
| res | Output value. |
| m | Input matrix. |
Definition at line 310 of file matrix4_ptr.c.
References matrix4::m14, matrix4::m24, matrix4::m34, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_extract_translation().
Embeds a matrix3 into the upper-left of a matrix4.
| res | Output value. |
| m | Input matrix. |
Definition at line 277 of file matrix4_ptr.c.
References matrix3::m11, matrix4::m11, matrix3::m12, matrix4::m12, matrix3::m13, matrix4::m13, matrix3::m21, matrix4::m21, matrix3::m22, matrix4::m22, matrix3::m23, matrix4::m23, matrix3::m31, matrix4::m31, matrix3::m32, matrix4::m32, matrix3::m33, matrix4::m33, and mat4_identity_ptr().
Referenced by mat4_from_mat3().
| void mat4_identity_ptr | ( | matrix4 * | res | ) |
Sets the matrix to the identity matrix.
The identity matrix is a 4x4 matrix with 1s on the main diagonal and 0s elsewhere.
| res | Pointer to the matrix4 to set to identity. |
Definition at line 16 of file matrix4_ptr.c.
References matrix4::v.
Referenced by mat4_from_mat3_ptr(), mat4_identity(), mat4_rotation_x_ptr(), mat4_rotation_y_ptr(), mat4_rotation_z_ptr(), and quat_to_mat4_ptr().
Computes the inverse of a 4x4 matrix.
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.
| res | Pointer to the matrix4 where the inverse will be stored. |
| m | Pointer to the matrix4 to invert. |
Definition at line 98 of file matrix4_ptr.c.
References matrix4::v.
Referenced by mat4_inverse().
| 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.
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.
| 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. |
Definition at line 418 of file matrix4_ptr.c.
References mat4_identity(), matrix4::v, vec3_cross(), vec3_dot(), vec3_normalize(), vec3_sub(), vector3::x, vector3::y, and vector3::z.
Referenced by mat4_look_at().
Definition at line 69 of file matrix4_ptr.c.
References mat4_mul_ptr_scalar(), and vm_cpu_init().
Referenced by mat4_mul().
| VECMAT_SCALAR_API void mat4_mul_ptr_scalar | ( | matrix4 * | res, |
| const matrix4 * | a, | ||
| const matrix4 * | b ) |
Multiplies two 4x4 matrices.
This function computes the product of two input matrices and stores the result in the provided matrix. The multiplication follows standard matrix multiplication rules.
| res | Pointer to the matrix4 where the result is stored. |
| a | Pointer to the first matrix4 operand. |
| b | Pointer to the second matrix4 operand. |
Definition at line 35 of file matrix4_ptr.c.
References matrix4::v, and VECMAT_SCALAR_API.
Referenced by mat4_mul_ptr().
| void mat4_mul_vec3_ptr | ( | vector3 * | res, |
| const matrix4 * | m, | ||
| const vector3 * | v, | ||
| const vm_float_t | w ) |
Definition at line 538 of file matrix4_ptr.c.
References mat4_mul_vec3_ptr_scalar(), and vm_cpu_init().
Referenced by mat4_mul_vec3().
| 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.
| res | Output value. |
| m | Input matrix. |
| v | Input vector. |
| w | Homogeneous w component. |
Definition at line 528 of file matrix4_ptr.c.
References matrix4::m11, matrix4::m12, matrix4::m13, matrix4::m14, matrix4::m21, matrix4::m22, matrix4::m23, matrix4::m24, matrix4::m31, matrix4::m32, matrix4::m33, matrix4::m34, VECMAT_SCALAR_API, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_mul_vec3_ptr().
Definition at line 510 of file matrix4_ptr.c.
References mat4_mul_vec4_ptr_scalar(), and vm_cpu_init().
Referenced by mat4_mul_vec4().
| VECMAT_SCALAR_API void mat4_mul_vec4_ptr_scalar | ( | vector4 * | res, |
| const matrix4 * | m, | ||
| const vector4 * | v ) |
Multiplies a 4x4 matrix by a vector4.
| res | Output value. |
| m | Input matrix. |
| v | Input vector. |
Definition at line 498 of file matrix4_ptr.c.
References matrix4::m11, matrix4::m12, matrix4::m13, matrix4::m14, matrix4::m21, matrix4::m22, matrix4::m23, matrix4::m24, matrix4::m31, matrix4::m32, matrix4::m33, matrix4::m34, matrix4::m41, matrix4::m42, matrix4::m43, matrix4::m44, VECMAT_SCALAR_API, vector4::w, vector4::x, vector4::y, and vector4::z.
Referenced by mat4_mul_vec4_ptr().
| 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.
This function configures the matrix for an orthographic projection, mapping a rectangular frustum defined by the clipping planes to the canonical view volume.
| 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. |
Definition at line 393 of file matrix4_ptr.c.
References matrix4::v.
Referenced by mat4_ortho().
| 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.
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.
| res | Pointer to the matrix4 to set to the perspective projection matrix. |
| fov | Field of view angle in degrees. |
| w | Viewport width. |
| h | Viewport height. |
| n | Near clipping plane distance. |
| f | Far clipping plane distance. |
Definition at line 452 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::v, and VECMAT_TAN.
Referenced by mat4_perspective_fov().
| 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.
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.
| res | Pointer to the matrix4 to set to the infinite perspective projection. |
| fov_y | Vertical field of view in degrees. |
| aspect | Aspect ratio of the viewport (width / height). |
| n | Distance to the near clipping plane. |
Definition at line 479 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::v, and VECMAT_TAN.
Referenced by mat4_perspective_infinite().
| 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.
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.
| res | Pointer to the matrix4 to store the perspective projection matrix. |
| fov | Field of view in degrees. |
| aspect | Aspect ratio of the viewport (width divided by height). |
| near | Distance to the near clipping plane. |
| far | Distance to the far clipping plane. |
Definition at line 365 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::v, and VECMAT_TAN.
Referenced by mat4_perspective().
| void mat4_rotation_ptr | ( | matrix4 * | res, |
| const vector3 * | axis, | ||
| const vm_float_t | angle ) |
Sets the matrix to a rotation matrix around the specified axis by the given angle.
The rotation is performed around the normalized axis vector by the specified angle in degrees. The resulting matrix is a 4x4 rotation matrix stored in column-major order.
| res | Pointer to the matrix4 to store the resulting rotation matrix. |
| axis | Pointer to the vector3 representing the axis of rotation. |
| angle | The rotation angle in degrees. |
Definition at line 195 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::v, vec3_normalize(), VECMAT_COS, VECMAT_SIN, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_rotation().
| void mat4_rotation_x_ptr | ( | matrix4 * | res, |
| const vm_float_t | degrees ) |
Builds a 4x4 rotation matrix around the X axis (degrees).
| res | Output value. |
| degrees | Rotation angle in degrees. |
Definition at line 223 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::m22, matrix4::m23, matrix4::m32, matrix4::m33, mat4_identity_ptr(), VECMAT_COS, and VECMAT_SIN.
Referenced by mat4_rotation_x().
| void mat4_rotation_y_ptr | ( | matrix4 * | res, |
| const vm_float_t | degrees ) |
Builds a 4x4 rotation matrix around the Y axis (degrees).
| res | Output value. |
| degrees | Rotation angle in degrees. |
Definition at line 241 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::m11, matrix4::m13, matrix4::m31, matrix4::m33, mat4_identity_ptr(), VECMAT_COS, and VECMAT_SIN.
Referenced by mat4_rotation_y().
| void mat4_rotation_z_ptr | ( | matrix4 * | res, |
| const vm_float_t | degrees ) |
Builds a 4x4 rotation matrix around the Z axis (degrees).
| res | Output value. |
| degrees | Rotation angle in degrees. |
Definition at line 259 of file matrix4_ptr.c.
References deg_to_rad(), matrix4::m11, matrix4::m12, matrix4::m21, matrix4::m22, mat4_identity_ptr(), VECMAT_COS, and VECMAT_SIN.
Referenced by mat4_rotation_z().
Sets the matrix to a scaling matrix using the provided scale vector.
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).
| res | Pointer to the matrix4 to set as a scaling matrix. |
| v | Pointer to the vector3 containing the scale factors (x, y, z). |
Definition at line 176 of file matrix4_ptr.c.
References matrix4::v, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_scale().
Sets the matrix to a translation matrix.
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.
| res | Pointer to the matrix4 to set. |
| v | Pointer to the vector3 containing the translation values. |
Definition at line 145 of file matrix4_ptr.c.
References matrix4::v, vector3::x, vector3::y, and vector3::z.
Referenced by mat4_translate().
Definition at line 79 of file matrix4_ptr.c.
References mat4_transpose_ptr_scalar(), and vm_cpu_init().
Referenced by mat4_transpose().
| VECMAT_SCALAR_API void mat4_transpose_ptr_scalar | ( | matrix4 * | res, |
| const matrix4 * | m ) |
Transposes the given 4x4 matrix.
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.
| res | Pointer to the matrix4 where the transposed result will be stored. |
| m | Pointer to the constant matrix4 to be transposed. |
Definition at line 60 of file matrix4_ptr.c.
References matrix4::v, and VECMAT_SCALAR_API.
Referenced by mat4_transpose_ptr().
| 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.
| res | Output value. |
| translation | Translation vector. |
| rotation | Rotation quaternion. |
| scale | Scale vector. |
Definition at line 293 of file matrix4_ptr.c.
References matrix4::m11, matrix4::m12, matrix4::m13, matrix4::m14, matrix4::m21, matrix4::m22, matrix4::m23, matrix4::m24, matrix4::m31, matrix4::m32, matrix4::m33, matrix4::m34, quat_to_mat4_ptr(), vector3::x, vector3::y, and vector3::z.
Referenced by mat4_trs().