61 for (
int i = 0; i < 3; i++) {
62 for (
int j = 0; j < 3; j++) {
63 temp.
v[i * 3 + j] = m->
v[j * 3 + i];
81 const vm_float_t det = m->
v[0] * (m->
v[4] * m->
v[8] - m->
v[5] * m->
v[7]) -
82 m->
v[1] * (m->
v[3] * m->
v[8] - m->
v[5] * m->
v[6]) +
83 m->
v[2] * (m->
v[3] * m->
v[7] - m->
v[4] * m->
v[6]);
93 inv.
v[0] = (m->
v[4] * m->
v[8] - m->
v[5] * m->
v[7]) * inv_det;
94 inv.
v[1] = (m->
v[2] * m->
v[7] - m->
v[1] * m->
v[8]) * inv_det;
95 inv.
v[2] = (m->
v[1] * m->
v[5] - m->
v[2] * m->
v[4]) * inv_det;
96 inv.
v[3] = (m->
v[5] * m->
v[6] - m->
v[3] * m->
v[8]) * inv_det;
97 inv.
v[4] = (m->
v[0] * m->
v[8] - m->
v[2] * m->
v[6]) * inv_det;
98 inv.
v[5] = (m->
v[2] * m->
v[3] - m->
v[0] * m->
v[5]) * inv_det;
99 inv.
v[6] = (m->
v[3] * m->
v[7] - m->
v[4] * m->
v[6]) * inv_det;
100 inv.
v[7] = (m->
v[1] * m->
v[6] - m->
v[0] * m->
v[7]) * inv_det;
101 inv.
v[8] = (m->
v[0] * m->
v[4] - m->
v[1] * m->
v[3]) * inv_det;
143 .m11 = 1.0f, .m21 = 0.0f, .m31 = 0.0f,
144 .m12 = 0.0f, .m22 = c, .m32 = s,
145 .m13 = 0.0f, .m23 = -s, .m33 = c
161 .m11 = c, .m21 = 0.0f, .m31 = -s,
162 .m12 = 0.0f, .m22 = 1.0f, .m32 = 0.0f,
163 .m13 = s, .m23 = 0.0f, .m33 = c
218 res->
x = m->
m11 * x + m->
m12 * y + m->
m13 * z;
219 res->
y = m->
m21 * x + m->
m22 * y + m->
m23 * z;
220 res->
z = m->
m31 * x + m->
m32 * y + m->
m33 * z;
void mat3_identity_ptr(matrix3 *res)
Initializes the 3x3 matrix to identity (diagonal 1.0, others 0.0).
void mat3_mul_vec2_ptr(vector2 *res, const matrix3 *m, const vector2 *v)
Applies a 3x3 affine transform to a vector2.
void mat3_translate_ptr(matrix3 *res, const vector2 *t)
Builds a 3x3 2D translation matrix.
void mat3_from_mat4_ptr(matrix3 *res, const matrix4 *m)
Copies the upper-left 3x3 of a matrix4.
void mat3_inverse_ptr(matrix3 *res, const matrix3 *m)
Computes the inverse of the input 3x3 matrix using the adjugate method and stores in res.
void mat3_mul_ptr(matrix3 *res, const matrix3 *a, const matrix3 *b)
Multiplies two 3x3 matrices (a * b) in column-major / column-vector convention.
void mat3_mul_vec3_ptr(vector3 *res, const matrix3 *m, const vector3 *v)
Multiplies a 3x3 matrix by a vector3.
void mat3_rotation_z_ptr(matrix3 *res, const vm_float_t degrees)
Sets the 3x3 matrix to a rotation around the Z-axis by the given angle in degrees.
void mat3_scale_ptr(matrix3 *res, const vector2 *s)
Builds a 3x3 2D scaling matrix.
void mat3_transpose_ptr(matrix3 *res, const matrix3 *m)
Computes the transpose of the input 3x3 matrix and stores in res.
void mat3_rotation_y_ptr(matrix3 *res, const vm_float_t degrees)
Builds a 3x3 rotation matrix around the Y axis (degrees).
void mat3_rotation_x_ptr(matrix3 *res, const vm_float_t degrees)
Builds a 3x3 rotation matrix around the X axis (degrees).
vm_float_t v[VECMAT_MAT3_SIZE]
vm_float_t deg_to_rad(vm_float_t degrees)
Converts degrees to radians.