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

Go to the source code of this file.

Functions

void mat2_identity_ptr (matrix2 *res)
 Initializes the 2x2 matrix to identity (diagonal 1.0, others 0.0).
void mat2_mul_ptr (matrix2 *res, const matrix2 *a, const matrix2 *b)
 Multiplies two 2x2 matrices (a * b) in column-major / column-vector convention.
void mat2_transpose_ptr (matrix2 *res, const matrix2 *m)
 Computes the transpose of the input 2x2 matrix and stores in res.
void mat2_inverse_ptr (matrix2 *res, const matrix2 *m)
 Computes the inverse of the input 2x2 matrix using determinant and stores in res.
void mat2_mul_vec2_ptr (vector2 *res, const matrix2 *m, const vector2 *v)
 Multiplies a 2x2 matrix by a vector2.
void mat2_rotation_z_ptr (matrix2 *res, const vm_float_t degrees)
 Sets res to a 2x2 rotation matrix for rotation around the Z-axis.
void mat2_scale_ptr (matrix2 *res, const vector2 *s)
 Builds a 2x2 scaling matrix from a vector2.
void mat2_from_mat3_ptr (matrix2 *res, const matrix3 *m)
 Copies the upper-left 2x2 of a matrix3.

Function Documentation

◆ mat2_from_mat3_ptr()

void mat2_from_mat3_ptr ( matrix2 * res,
const matrix3 * m )

Copies the upper-left 2x2 of a matrix3.

Parameters
resOutput value.
mInput matrix.

Definition at line 128 of file matrix2_ptr.c.

References matrix3::m11, matrix3::m12, matrix3::m21, and matrix3::m22.

Referenced by mat2_from_mat3().

◆ mat2_identity_ptr()

void mat2_identity_ptr ( matrix2 * res)

Initializes the 2x2 matrix to identity (diagonal 1.0, others 0.0).

Parameters
resPointer to the output matrix2.

Definition at line 12 of file matrix2_ptr.c.

References matrix2::v.

Referenced by mat2_identity(), and mat2_inverse_ptr().

◆ mat2_inverse_ptr()

void mat2_inverse_ptr ( matrix2 * res,
const matrix2 * m )

Computes the inverse of the input 2x2 matrix using determinant and stores in res.

If the determinant is zero, sets res to identity matrix.

Parameters
resPointer to the output matrix2.
mPointer to the input matrix.

Definition at line 60 of file matrix2_ptr.c.

References mat2_determinant(), mat2_identity_ptr(), and matrix2::v.

Referenced by mat2_inverse().

◆ mat2_mul_ptr()

void mat2_mul_ptr ( matrix2 * res,
const matrix2 * a,
const matrix2 * b )

Multiplies two 2x2 matrices (a * b) in column-major / column-vector convention.

Parameters
resPointer to the output matrix2.
aPointer to the first matrix.
bPointer to the second matrix.

Definition at line 26 of file matrix2_ptr.c.

References matrix2::m11, matrix2::m12, matrix2::m21, and matrix2::m22.

Referenced by mat2_mul().

◆ mat2_mul_vec2_ptr()

void mat2_mul_vec2_ptr ( vector2 * res,
const matrix2 * m,
const vector2 * v )

Multiplies a 2x2 matrix by a vector2.

Parameters
resOutput value.
mInput matrix.
vInput vector.

Definition at line 81 of file matrix2_ptr.c.

References matrix2::m11, matrix2::m12, matrix2::m21, matrix2::m22, vector2::x, and vector2::y.

Referenced by mat2_mul_vec2().

◆ mat2_rotation_z_ptr()

void mat2_rotation_z_ptr ( matrix2 * res,
const vm_float_t degrees )

Sets res to a 2x2 rotation matrix for rotation around the Z-axis.

Converts degrees to radians; positive is counter-clockwise.

Parameters
resPointer to the output matrix2.
degreesRotation angle in degrees.

Definition at line 97 of file matrix2_ptr.c.

References deg_to_rad(), VECMAT_COS, and VECMAT_SIN.

Referenced by mat2_rotation_z().

◆ mat2_scale_ptr()

void mat2_scale_ptr ( matrix2 * res,
const vector2 * s )

Builds a 2x2 scaling matrix from a vector2.

Parameters
resOutput value.
sScale vector.

Definition at line 114 of file matrix2_ptr.c.

References vector2::x, and vector2::y.

Referenced by mat2_scale().

◆ mat2_transpose_ptr()

void mat2_transpose_ptr ( matrix2 * res,
const matrix2 * m )

Computes the transpose of the input 2x2 matrix and stores in res.

Parameters
resPointer to the output matrix2.
mPointer to the input matrix.

Definition at line 43 of file matrix2_ptr.c.

References matrix2::v.

Referenced by mat2_transpose().