Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
matrix4i.c
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025-2026 Igal Alkon
2// SPDX-FileCopyrightText: 2026 ALKONTEK <git@alkontek.com>
3// SPDX-License-Identifier: BSD-3-Clause
4
5#include <vecmat.h>
6
15{
16 matrix4i res;
18 return res;
19}
20
31{
32 matrix4i res;
33 mat4i_mul_ptr(&res, &a, &b);
34 return res;
35}
36
46{
47 matrix4i res;
48 mat4i_transpose_ptr(&res, &m);
49 return res;
50}
51
61{
62 matrix4i res;
63 mat4i_inverse_ptr(&res, &m);
64 return res;
65}
66
74{
75 const vm_int_t cofactor_1 = m.v[5] * m.v[10] * m.v[15] - m.v[5] * m.v[14] * m.v[11] - m.v[9] * m.v[6] * m.v[15] +
76 m.v[9] * m.v[14] * m.v[7] + m.v[13] * m.v[6] * m.v[11] - m.v[13] * m.v[10] * m.v[7];
77
78 const vm_int_t cofactor_2 = -m.v[4] * m.v[10] * m.v[15] + m.v[4] * m.v[14] * m.v[11] + m.v[8] * m.v[6] * m.v[15] -
79 m.v[8] * m.v[14] * m.v[7] - m.v[12] * m.v[6] * m.v[11] + m.v[12] * m.v[10] * m.v[7];
80
81 const vm_int_t cofactor_3 = m.v[4] * m.v[9] * m.v[15] - m.v[4] * m.v[13] * m.v[11] - m.v[8] * m.v[5] * m.v[15] +
82 m.v[8] * m.v[13] * m.v[7] + m.v[12] * m.v[5] * m.v[11] - m.v[12] * m.v[9] * m.v[7];
83
84 const vm_int_t cofactor_4 = -m.v[4] * m.v[9] * m.v[14] + m.v[4] * m.v[13] * m.v[10] + m.v[8] * m.v[5] * m.v[14] -
85 m.v[8] * m.v[13] * m.v[6] - m.v[12] * m.v[5] * m.v[10] + m.v[12] * m.v[9] * m.v[6];
86
87 return m.v[0] * cofactor_1 + m.v[1] * cofactor_2 + m.v[2] * cofactor_3 + m.v[3] * cofactor_4;
88}
89
100{
101 vector4i res;
102 mat4i_mul_vec4i_ptr(&res, &m, &v);
103 return res;
104}
105
117{
118 vector3i res;
119 mat4i_mul_vec3i_ptr(&res, &m, &v, w);
120 return res;
121}
matrix4i mat4i_transpose(const matrix4i m)
Computes the transpose of a 4x4 integer matrix.
Definition matrix4i.c:45
matrix4i mat4i_identity(void)
Constructs the 4x4 identity matrix.
Definition matrix4i.c:14
matrix4i mat4i_mul(const matrix4i a, const matrix4i b)
Multiplies two 4x4 integer matrices.
Definition matrix4i.c:30
vector3i mat4i_mul_vec3i(const matrix4i m, const vector3i v, const vm_int_t w)
Transforms a vector3i by a 4x4 integer matrix using homogeneous w.
Definition matrix4i.c:116
matrix4i mat4i_inverse(const matrix4i m)
Computes the inverse of a 4x4 integer matrix.
Definition matrix4i.c:60
vm_int_t mat4i_determinant(const matrix4i m)
Computes the determinant of a 4x4 integer matrix (Laplace expansion along first row).
Definition matrix4i.c:73
vector4i mat4i_mul_vec4i(const matrix4i m, const vector4i v)
Multiplies a 4x4 integer matrix by a vector4i.
Definition matrix4i.c:99
vm_int_t v[VECMAT_MAT4_SIZE]
Definition vecmat.h:352
void mat4i_mul_vec3i_ptr(vector3i *res, const matrix4i *m, const vector3i *v, vm_int_t w)
Transforms a vector3i by a 4x4 integer matrix using homogeneous w.
void mat4i_mul_ptr(matrix4i *res, const matrix4i *a, const matrix4i *b)
Performs matrix multiplication of two 4x4 matrices and stores the result.
void mat4i_transpose_ptr(matrix4i *res, const matrix4i *m)
Transposes the given 4x4 integer matrix and stores the result in the provided matrix structure.
void mat4i_inverse_ptr(matrix4i *res, const matrix4i *m)
Computes the inverse of the given 4x4 integer matrix and stores the result in the specified matrix.
void mat4i_identity_ptr(matrix4i *res)
Sets the given 4x4 integer matrix to the identity matrix.
int8_t vm_int_t
Definition vecmat.h:103
void mat4i_mul_vec4i_ptr(vector4i *res, const matrix4i *m, const vector4i *v)
Multiplies a 4x4 integer matrix by a vector4i.