Vecmat 0.2.3
C math and linear algebra library for 2D/3D graphics, physics, and science.
Loading...
Searching...
No Matches
matrix4_ptr.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 <string.h>
6#include <vecmat.h>
7#include "features/cpu.h"
8
17{
18 memset(res->v, 0, sizeof(res->v)); // Zero out all 16 floats
19 res->v[0] = 1.0f;
20 res->v[5] = 1.0f;
21 res->v[10] = 1.0f;
22 res->v[15] = 1.0f;
23}
24
36{
37 /* Column-major: C's column j is A times B's column j (matches mul_vec). */
38 matrix4 tmp;
39 for (int c = 0; c < 4; c++) {
40 for (int r = 0; r < 4; r++) {
41 vm_float_t s = 0.0f;
42 for (int k = 0; k < 4; k++) {
43 s += a->v[k * 4 + r] * b->v[c * 4 + k];
44 }
45 tmp.v[c * 4 + r] = s;
46 }
47 }
48 *res = tmp;
49}
50
61{
62 for (int i = 0; i < 4; i++) {
63 for (int j = 0; j < 4; j++) {
64 res->v[i * 4 + j] = m->v[j * 4 + i];
65 }
66 }
67}
68
69void mat4_mul_ptr(matrix4 *res, const matrix4 *a, const matrix4 *b)
70{
71#ifdef VECMAT_RUNTIME_DISPATCH
73 mat4_mul_ptr_(res, a, b);
74#else
75 mat4_mul_ptr_scalar(res, a, b);
76#endif
77}
78
80{
81#ifdef VECMAT_RUNTIME_DISPATCH
83 mat4_transpose_ptr_(res, m);
84#else
86#endif
87}
88
98void mat4_inverse_ptr(matrix4 *res, const matrix4 *m)
99{
100 vm_float_t inv[16];
101
102 inv[0] = 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] + 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];
103 inv[4] = -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] - 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];
104 inv[8] = 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] + 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];
105 inv[12] = -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] - 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];
106 inv[1] = -m->v[1] * m->v[10] * m->v[15] + m->v[1] * m->v[14] * m->v[11] + m->v[9] * m->v[2] * m->v[15] - m->v[9] * m->v[14] * m->v[3] - m->v[13] * m->v[2] * m->v[11] + m->v[13] * m->v[10] * m->v[3];
107 inv[5] = m->v[0] * m->v[10] * m->v[15] - m->v[0] * m->v[14] * m->v[11] - m->v[8] * m->v[2] * m->v[15] + m->v[8] * m->v[14] * m->v[3] + m->v[12] * m->v[2] * m->v[11] - m->v[12] * m->v[10] * m->v[3];
108 inv[9] = -m->v[0] * m->v[9] * m->v[15] + m->v[0] * m->v[13] * m->v[11] + m->v[8] * m->v[1] * m->v[15] - m->v[8] * m->v[13] * m->v[3] - m->v[12] * m->v[1] * m->v[11] + m->v[12] * m->v[9] * m->v[3];
109 inv[13] = m->v[0] * m->v[9] * m->v[14] - m->v[0] * m->v[13] * m->v[10] - m->v[8] * m->v[1] * m->v[14] + m->v[8] * m->v[13] * m->v[2] + m->v[12] * m->v[1] * m->v[10] - m->v[12] * m->v[9] * m->v[2];
110 inv[2] = m->v[1] * m->v[6] * m->v[15] - m->v[1] * m->v[14] * m->v[7] - m->v[5] * m->v[2] * m->v[15] + m->v[5] * m->v[14] * m->v[3] + m->v[13] * m->v[2] * m->v[7] - m->v[13] * m->v[6] * m->v[3];
111 inv[6] = -m->v[0] * m->v[6] * m->v[15] + m->v[0] * m->v[14] * m->v[7] + m->v[4] * m->v[2] * m->v[15] - m->v[4] * m->v[14] * m->v[3] - m->v[12] * m->v[2] * m->v[7] + m->v[12] * m->v[6] * m->v[3];
112 inv[10] = m->v[0] * m->v[5] * m->v[15] - m->v[0] * m->v[13] * m->v[7] - m->v[4] * m->v[1] * m->v[15] + m->v[4] * m->v[13] * m->v[3] + m->v[12] * m->v[1] * m->v[7] - m->v[12] * m->v[5] * m->v[3];
113 inv[14] = -m->v[0] * m->v[5] * m->v[14] + m->v[0] * m->v[13] * m->v[6] + m->v[4] * m->v[1] * m->v[14] - m->v[4] * m->v[13] * m->v[2] - m->v[12] * m->v[1] * m->v[6] + m->v[12] * m->v[5] * m->v[2];
114 inv[3] = -m->v[1] * m->v[6] * m->v[11] + m->v[1] * m->v[10] * m->v[7] + m->v[5] * m->v[2] * m->v[11] - m->v[5] * m->v[10] * m->v[3] - m->v[9] * m->v[2] * m->v[7] + m->v[9] * m->v[6] * m->v[3];
115 inv[7] = m->v[0] * m->v[6] * m->v[11] - m->v[0] * m->v[10] * m->v[7] - m->v[4] * m->v[2] * m->v[11] + m->v[4] * m->v[10] * m->v[3] + m->v[8] * m->v[2] * m->v[7] - m->v[8] * m->v[6] * m->v[3];
116 inv[11] = -m->v[0] * m->v[5] * m->v[11] + m->v[0] * m->v[9] * m->v[7] + m->v[4] * m->v[1] * m->v[11] - m->v[4] * m->v[9] * m->v[3] - m->v[8] * m->v[1] * m->v[7] + m->v[8] * m->v[5] * m->v[3];
117 inv[15] = m->v[0] * m->v[5] * m->v[10] - m->v[0] * m->v[9] * m->v[6] - m->v[4] * m->v[1] * m->v[10] + m->v[4] * m->v[9] * m->v[2] + m->v[8] * m->v[1] * m->v[6] - m->v[8] * m->v[5] * m->v[2];
118
119 vm_float_t det = m->v[0] * inv[0] + m->v[1] * inv[4] + m->v[2] * inv[8] + m->v[3] * inv[12];
120 if (det == 0.0f) {
121 res->v[0] = 1.0f;
122 res->v[5] = 1.0f;
123 res->v[10] = 1.0f;
124 res->v[15] = 1.0f;
125 return;
126 }
127
128 det = 1.0f / det;
129
130 for (int i = 0; i < 16; i++) {
131 res->v[i] = inv[i] * det;
132 }
133}
134
146{
147 res->v[0] = 1.0f;
148 res->v[1] = 0.0f;
149 res->v[2] = 0.0f;
150 res->v[3] = 0.0f;
151 res->v[4] = 0.0f;
152 res->v[5] = 1.0f;
153 res->v[6] = 0.0f;
154 res->v[7] = 0.0f;
155 res->v[8] = 0.0f;
156 res->v[9] = 0.0f;
157 res->v[10] = 1.0f;
158 res->v[11] = 0.0f;
159 res->v[12] = v->x;
160 res->v[13] = v->y;
161 res->v[14] = v->z;
162 res->v[15] = 1.0f;
163}
164
176void mat4_scale_ptr(matrix4 *res, const vector3 *v)
177{
178 memset(res->v, 0, sizeof(res->v));
179 res->v[0] = v->x;
180 res->v[5] = v->y;
181 res->v[10] = v->z;
182 res->v[15] = 1.0f;
183}
184
195void mat4_rotation_ptr(matrix4 *res, const vector3 *axis, const vm_float_t angle)
196{
197 const vector3 normalized_axis = vec3_normalize(*axis);
198 const vm_float_t rad = deg_to_rad(angle);
199 const vm_float_t c = VECMAT_COS(rad);
200 const vm_float_t s = VECMAT_SIN(rad);
201 const vm_float_t omc = 1.0f - c;
202 const vm_float_t x = normalized_axis.x, y = normalized_axis.y, z = normalized_axis.z;
203
204 memset(res->v, 0, sizeof(res->v));
205 res->v[0] = x * x * omc + c;
206 res->v[1] = x * y * omc + z * s;
207 res->v[2] = x * z * omc - y * s;
208 res->v[4] = x * y * omc - z * s;
209 res->v[5] = y * y * omc + c;
210 res->v[6] = y * z * omc + x * s;
211 res->v[8] = x * z * omc + y * s;
212 res->v[9] = y * z * omc - x * s;
213 res->v[10] = z * z * omc + c;
214 res->v[15] = 1.0f;
215}
216
223void mat4_rotation_x_ptr(matrix4 *res, const vm_float_t degrees)
224{
225 const vm_float_t rad = deg_to_rad(degrees);
226 const vm_float_t c = VECMAT_COS(rad);
227 const vm_float_t s = VECMAT_SIN(rad);
229 res->m22 = c;
230 res->m32 = s;
231 res->m23 = -s;
232 res->m33 = c;
233}
234
241void mat4_rotation_y_ptr(matrix4 *res, const vm_float_t degrees)
242{
243 const vm_float_t rad = deg_to_rad(degrees);
244 const vm_float_t c = VECMAT_COS(rad);
245 const vm_float_t s = VECMAT_SIN(rad);
247 res->m11 = c;
248 res->m31 = -s;
249 res->m13 = s;
250 res->m33 = c;
251}
252
259void mat4_rotation_z_ptr(matrix4 *res, const vm_float_t degrees)
260{
261 const vm_float_t rad = deg_to_rad(degrees);
262 const vm_float_t c = VECMAT_COS(rad);
263 const vm_float_t s = VECMAT_SIN(rad);
265 res->m11 = c;
266 res->m21 = s;
267 res->m12 = -s;
268 res->m22 = c;
269}
270
278{
280 res->m11 = m->m11; res->m21 = m->m21; res->m31 = m->m31;
281 res->m12 = m->m12; res->m22 = m->m22; res->m32 = m->m32;
282 res->m13 = m->m13; res->m23 = m->m23; res->m33 = m->m33;
283}
284
293void mat4_trs_ptr(matrix4 *res, const vector3 *translation, const quaternion *rotation, const vector3 *scale)
294{
295 quat_to_mat4_ptr(res, rotation);
296 res->m11 *= scale->x; res->m21 *= scale->x; res->m31 *= scale->x;
297 res->m12 *= scale->y; res->m22 *= scale->y; res->m32 *= scale->y;
298 res->m13 *= scale->z; res->m23 *= scale->z; res->m33 *= scale->z;
299 res->m14 = translation->x;
300 res->m24 = translation->y;
301 res->m34 = translation->z;
302}
303
311{
312 res->x = m->m14;
313 res->y = m->m24;
314 res->z = m->m34;
315}
316
324{
325 res->x = VECMAT_SQRT(m->m11 * m->m11 + m->m21 * m->m21 + m->m31 * m->m31);
326 res->y = VECMAT_SQRT(m->m12 * m->m12 + m->m22 * m->m22 + m->m32 * m->m32);
327 res->z = VECMAT_SQRT(m->m13 * m->m13 + m->m23 * m->m23 + m->m33 * m->m33);
328}
329
337{
338 vector3 s;
340 matrix3 r;
341 r.m11 = (s.x != 0.0f) ? m->m11 / s.x : 0.0f;
342 r.m21 = (s.x != 0.0f) ? m->m21 / s.x : 0.0f;
343 r.m31 = (s.x != 0.0f) ? m->m31 / s.x : 0.0f;
344 r.m12 = (s.y != 0.0f) ? m->m12 / s.y : 0.0f;
345 r.m22 = (s.y != 0.0f) ? m->m22 / s.y : 0.0f;
346 r.m32 = (s.y != 0.0f) ? m->m32 / s.y : 0.0f;
347 r.m13 = (s.z != 0.0f) ? m->m13 / s.z : 0.0f;
348 r.m23 = (s.z != 0.0f) ? m->m23 / s.z : 0.0f;
349 r.m33 = (s.z != 0.0f) ? m->m33 / s.z : 0.0f;
350 quat_from_mat3_ptr(res, &r);
351}
352
365void mat4_perspective_ptr(matrix4 *res, const vm_float_t fov, const vm_float_t aspect,
366 const vm_float_t near, const vm_float_t far)
367{
368 const vm_float_t rad = deg_to_rad(fov / 2.0f);
369 const vm_float_t tan_half_fov = VECMAT_TAN(rad);
370
371 for (int i = 0; i < 16; i++) res->v[i] = 0.0f;
372 res->v[0] = 1.0f / (aspect * tan_half_fov);
373 res->v[5] = 1.0f / tan_half_fov;
374 res->v[10] = -(far + near) / (far - near);
375 res->v[11] = -1.0f;
376 res->v[14] = -2.0f * far * near / (far - near);
377}
378
393void mat4_ortho_ptr(matrix4 *res, const vm_float_t left, const vm_float_t right, const vm_float_t bottom,
394 const vm_float_t top, const vm_float_t near, const vm_float_t far)
395{
396 res->v[0] = 2.0f / (right - left);
397 res->v[5] = 2.0f / (top - bottom);
398 res->v[10] = -2.0f / (far - near);
399 res->v[12] = -(right + left) / (right - left);
400 res->v[13] = -(top + bottom) / (top - bottom);
401 res->v[14] = -(far + near) / (far - near);
402 res->v[15] = 1.0f;
403}
404
418void mat4_look_at_ptr(matrix4 *res, const vector3 *position, const vector3 *target, const vector3 *up)
419{
420 const vector3 forward = vec3_normalize(vec3_sub(*target, *position));
421 const vector3 right = vec3_normalize(vec3_cross(forward, *up));
422 const vector3 true_up = vec3_cross(right, forward);
423
424 *res = mat4_identity();
425 res->v[0] = right.x;
426 res->v[1] = true_up.x;
427 res->v[2] = -forward.x;
428 res->v[4] = right.y;
429 res->v[5] = true_up.y;
430 res->v[6] = -forward.y;
431 res->v[8] = right.z;
432 res->v[9] = true_up.z;
433 res->v[10] = -forward.z;
434 res->v[12] = -vec3_dot(right, *position);
435 res->v[13] = -vec3_dot(true_up, *position);
436 res->v[14] = vec3_dot(forward, *position);
437}
438
452void mat4_perspective_fov_ptr(matrix4 *res, const vm_float_t fov, const vm_float_t w, const vm_float_t h,
453 const vm_float_t n, const vm_float_t f)
454{
455 const vm_float_t rad = deg_to_rad(fov / 2.0f);
456 const vm_float_t tan_half_fov = VECMAT_TAN(rad);
457 const vm_float_t aspect = w / h;
458
459 for (int i = 0; i < 16; i++) res->v[i] = 0.0f;
460 res->v[0] = 1.0f / (aspect * tan_half_fov);
461 res->v[5] = 1.0f / tan_half_fov;
462 res->v[10] = -(f + n) / (f - n);
463 res->v[11] = -1.0f;
464 res->v[14] = -2.0f * f * n / (f - n);
465}
466
479void mat4_perspective_infinite_ptr(matrix4 *res, vm_float_t const fov_y, vm_float_t const aspect, vm_float_t const n)
480{
481 const vm_float_t rad = deg_to_rad(fov_y / 2.0f);
482 const vm_float_t tan_half_fov = VECMAT_TAN(rad);
483 for (int i = 0; i < 16; i++) res->v[i] = 0.0f;
484 res->v[0] = 1.0f / (aspect * tan_half_fov);
485 res->v[5] = 1.0f / tan_half_fov;
486 res->v[10] = -1.0f;
487 res->v[11] = -1.0f;
488 res->v[14] = -2.0f * n;
489}
490
499{
500 const vm_float_t x = v->x;
501 const vm_float_t y = v->y;
502 const vm_float_t z = v->z;
503 const vm_float_t w = v->w;
504 res->x = m->m11 * x + m->m12 * y + m->m13 * z + m->m14 * w;
505 res->y = m->m21 * x + m->m22 * y + m->m23 * z + m->m24 * w;
506 res->z = m->m31 * x + m->m32 * y + m->m33 * z + m->m34 * w;
507 res->w = m->m41 * x + m->m42 * y + m->m43 * z + m->m44 * w;
508}
509
510void mat4_mul_vec4_ptr(vector4 *res, const matrix4 *m, const vector4 *v)
511{
512#ifdef VECMAT_RUNTIME_DISPATCH
513 vm_cpu_init();
514 mat4_mul_vec4_ptr_(res, m, v);
515#else
516 mat4_mul_vec4_ptr_scalar(res, m, v);
517#endif
518}
519
529{
530 const vm_float_t x = v->x;
531 const vm_float_t y = v->y;
532 const vm_float_t z = v->z;
533 res->x = m->m11 * x + m->m12 * y + m->m13 * z + m->m14 * w;
534 res->y = m->m21 * x + m->m22 * y + m->m23 * z + m->m24 * w;
535 res->z = m->m31 * x + m->m32 * y + m->m33 * z + m->m34 * w;
536}
537
538void mat4_mul_vec3_ptr(vector3 *res, const matrix4 *m, const vector3 *v, const vm_float_t w)
539{
540#ifdef VECMAT_RUNTIME_DISPATCH
541 vm_cpu_init();
542 mat4_mul_vec3_ptr_(res, m, v, w);
543#else
544 mat4_mul_vec3_ptr_scalar(res, m, v, w);
545#endif
546}
#define VECMAT_SCALAR_API
Definition cpu.h:17
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.
void mat4_scale_ptr(matrix4 *res, const vector3 *v)
Sets the matrix to a scaling matrix using the provided scale vector.
void mat4_mul_vec4_ptr(vector4 *res, const matrix4 *m, const vector4 *v)
void mat4_extract_scale_ptr(vector3 *res, const matrix4 *m)
Extracts the scale vector from a matrix4.
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_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,...
void mat4_rotation_z_ptr(matrix4 *res, const vm_float_t degrees)
Builds a 4x4 rotation matrix around the Z axis (degrees).
VECMAT_SCALAR_API void mat4_mul_ptr_scalar(matrix4 *res, const matrix4 *a, const matrix4 *b)
Multiplies two 4x4 matrices.
Definition matrix4_ptr.c:35
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_extract_rotation_ptr(quaternion *res, const matrix4 *m)
Extracts the rotation quaternion from a matrix4.
void mat4_rotation_x_ptr(matrix4 *res, const vm_float_t degrees)
Builds a 4x4 rotation matrix around the X axis (degrees).
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_inverse_ptr(matrix4 *res, const matrix4 *m)
Computes the inverse of a 4x4 matrix.
Definition matrix4_ptr.c:98
VECMAT_SCALAR_API void mat4_transpose_ptr_scalar(matrix4 *res, const matrix4 *m)
Transposes the given 4x4 matrix.
Definition matrix4_ptr.c:60
void mat4_mul_vec3_ptr(vector3 *res, const matrix4 *m, const vector3 *v, const vm_float_t w)
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_rotation_y_ptr(matrix4 *res, const vm_float_t degrees)
Builds a 4x4 rotation matrix around the Y axis (degrees).
void mat4_translate_ptr(matrix4 *res, const vector3 *v)
Sets the matrix to a translation matrix.
void mat4_extract_translation_ptr(vector3 *res, const matrix4 *m)
Extracts the translation vector from a matrix4.
void mat4_transpose_ptr(matrix4 *res, const matrix4 *m)
Definition matrix4_ptr.c:79
void mat4_from_mat3_ptr(matrix4 *res, const matrix3 *m)
Embeds a matrix3 into the upper-left of 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_mul_ptr(matrix4 *res, const matrix4 *a, const matrix4 *b)
Definition matrix4_ptr.c:69
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_identity_ptr(matrix4 *res)
Sets the matrix to the identity matrix.
Definition matrix4_ptr.c:16
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.
vm_float_t m13
Definition vecmat.h:234
vm_float_t m21
Definition vecmat.h:229
vm_float_t m32
Definition vecmat.h:233
vm_float_t m23
Definition vecmat.h:235
vm_float_t m12
Definition vecmat.h:231
vm_float_t m33
Definition vecmat.h:236
vm_float_t m11
Definition vecmat.h:228
vm_float_t m31
Definition vecmat.h:230
vm_float_t m22
Definition vecmat.h:232
vm_float_t m44
Definition vecmat.h:269
vm_float_t v[VECMAT_MAT4_SIZE]
Definition vecmat.h:271
vm_float_t m12
Definition vecmat.h:258
vm_float_t m41
Definition vecmat.h:257
vm_float_t m13
Definition vecmat.h:262
vm_float_t m33
Definition vecmat.h:264
vm_float_t m42
Definition vecmat.h:261
vm_float_t m23
Definition vecmat.h:263
vm_float_t m21
Definition vecmat.h:255
vm_float_t m43
Definition vecmat.h:265
vm_float_t m22
Definition vecmat.h:259
vm_float_t m32
Definition vecmat.h:260
vm_float_t m24
Definition vecmat.h:267
vm_float_t m11
Definition vecmat.h:254
vm_float_t m31
Definition vecmat.h:256
vm_float_t m14
Definition vecmat.h:266
vm_float_t m34
Definition vecmat.h:268
vm_float_t z
Definition vecmat.h:139
vm_float_t y
Definition vecmat.h:138
vm_float_t x
Definition vecmat.h:137
vm_float_t z
Definition vecmat.h:150
vm_float_t x
Definition vecmat.h:148
vm_float_t y
Definition vecmat.h:149
vm_float_t w
Definition vecmat.h:151
vm_float_t vec3_dot(vector3 a, vector3 b)
Computes the dot product of two vector3.
Definition vector3.c:428
void quat_from_mat3_ptr(quaternion *res, const matrix3 *m)
Builds a quaternion from a 3x3 rotation matrix.
matrix4 mat4_identity(void)
Constructs the 4x4 identity matrix.
Definition matrix4.c:14
#define VECMAT_SIN(x)
Definition vecmat.h:415
vector3 vec3_normalize(vector3 v)
Normalizes a vector3 to unit length.
Definition vector3.c:227
#define VECMAT_TAN(x)
Definition vecmat.h:417
vector3 vec3_cross(vector3 a, vector3 b)
Computes the cross-product of two vector3.
Definition vector3.c:212
double vm_float_t
Definition vecmat.h:79
#define VECMAT_SQRT(x)
Definition vecmat.h:414
void quat_to_mat4_ptr(matrix4 *res, const quaternion *q)
Converts a unit quaternion to a 4x4 rotation matrix and stores in res.
vm_float_t deg_to_rad(vm_float_t degrees)
Converts degrees to radians.
Definition vecmat.c:14
#define VECMAT_COS(x)
Definition vecmat.h:416
void vm_cpu_init(void)
Definition dispatch.c:77
vector3 vec3_sub(vector3 a, vector3 b)
Component-wise subtraction of two vectors.
Definition vector3.c:118