ObjectivelyGPU
Object oriented graphics framework for SDL3 and C
Loading...
Searching...
No Matches
Mathlib.h
Go to the documentation of this file.
1/*
2 * ObjectivelyGPU: Object oriented graphics framework for SDL3 and C.
3 * Copyright (C) 2026 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <math.h>
27#include <stdbool.h>
28#include <string.h>
29
30#ifndef M_PI
31#define M_PI 3.14159265358979323846
32#endif
33
34#pragma mark - float
35
39static inline float float_radians(float degrees) {
40 return degrees * (float) (M_PI / 180.0);
41}
42
46static inline float float_degrees(float radians) {
47 return radians * (float) (180.0 / M_PI);
48}
49
53static inline float float_clamp(float f, float min, float max) {
54 return f < min ? min : f > max ? max : f;
55}
56
60static inline float float_saturate(float f) {
61 return float_clamp(f, 0.f, 1.f);
62}
63
67static inline float float_lerp(float a, float b, float t) {
68 return a + (b - a) * t;
69}
70
74static inline float float_smoothstep(float edge0, float edge1, float f) {
75 const float t = float_saturate((f - edge0) / (edge1 - edge0));
76 return t * t * (3.f - 2.f * t);
77}
78
82static inline float float_sign(float f) {
83 return (f > 0.f) - (f < 0.f);
84}
85
86#pragma mark - vec2
87
91typedef union {
92
96 float xy[2];
97
101 struct {
102 float x, y;
103 };
104} vec2;
105
109static inline vec2 vec2_new(float x, float y) {
110 return (vec2) { .x = x + 0.f, .y = y + 0.f };
111}
112
116static inline vec2 vec2_zero(void) {
117 return vec2_new(0.f, 0.f);
118}
119
123static inline vec2 vec2_one(void) {
124 return vec2_new(1.f, 1.f);
125}
126
130static inline vec2 vec2_add(vec2 a, vec2 b) {
131 return vec2_new(a.x + b.x, a.y + b.y);
132}
133
137static inline vec2 vec2_sub(vec2 a, vec2 b) {
138 return vec2_new(a.x - b.x, a.y - b.y);
139}
140
144static inline vec2 vec2_mul(vec2 a, vec2 b) {
145 return vec2_new(a.x * b.x, a.y * b.y);
146}
147
151static inline vec2 vec2_scale(vec2 v, float s) {
152 return vec2_new(v.x * s, v.y * s);
153}
154
158static inline vec2 vec2_negate(vec2 v) {
159 return vec2_scale(v, -1.f);
160}
161
165static inline float vec2_dot(vec2 a, vec2 b) {
166 return a.x * b.x + a.y * b.y;
167}
168
172static inline float vec2_length_squared(vec2 v) {
173 return vec2_dot(v, v);
174}
175
179static inline float vec2_length(vec2 v) {
180 return sqrtf(vec2_length_squared(v));
181}
182
186static inline float vec2_distance(vec2 a, vec2 b) {
187 return vec2_length(vec2_sub(a, b));
188}
189
193static inline vec2 vec2_normalize(vec2 v) {
194 const float l = vec2_length(v);
195 return l > 0.f ? vec2_scale(v, 1.f / l) : v;
196}
197
201static inline vec2 vec2_min(vec2 a, vec2 b) {
202 return vec2_new(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y);
203}
204
208static inline vec2 vec2_max(vec2 a, vec2 b) {
209 return vec2_new(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y);
210}
211
215static inline vec2 vec2_lerp(vec2 a, vec2 b, float t) {
216 return vec2_add(vec2_scale(a, 1.f - t), vec2_scale(b, t));
217}
218
222static inline bool vec2_equal(vec2 a, vec2 b) {
223 return a.x == b.x && a.y == b.y;
224}
225
226#pragma mark - vec3
227
232typedef union {
233
237 float xyz[3];
238
242 struct {
243 float x, y, z;
244 };
245
250} vec3;
251
255static inline vec3 vec3_new(float x, float y, float z) {
256 return (vec3) { .x = x + 0.f, .y = y + 0.f, .z = z + 0.f };
257}
258
262static inline vec3 vec3_zero(void) {
263 return vec3_new(0.f, 0.f, 0.f);
264}
265
269static inline vec3 vec3_one(void) {
270 return vec3_new(1.f, 1.f, 1.f);
271}
272
276static inline vec3 vec3_add(vec3 a, vec3 b) {
277 return vec3_new(a.x + b.x, a.y + b.y, a.z + b.z);
278}
279
283static inline vec3 vec3_sub(vec3 a, vec3 b) {
284 return vec3_new(a.x - b.x, a.y - b.y, a.z - b.z);
285}
286
290static inline vec3 vec3_mul(vec3 a, vec3 b) {
291 return vec3_new(a.x * b.x, a.y * b.y, a.z * b.z);
292}
293
297static inline vec3 vec3_scale(vec3 v, float s) {
298 return vec3_new(v.x * s, v.y * s, v.z * s);
299}
300
304static inline vec3 vec3_negate(vec3 v) {
305 return vec3_scale(v, -1.f);
306}
307
311static inline float vec3_dot(vec3 a, vec3 b) {
312 return a.x * b.x + a.y * b.y + a.z * b.z;
313}
314
318static inline vec3 vec3_cross(vec3 a, vec3 b) {
319 return vec3_new(
320 a.y * b.z - a.z * b.y,
321 a.z * b.x - a.x * b.z,
322 a.x * b.y - a.y * b.x
323 );
324}
325
329static inline float vec3_length_squared(vec3 v) {
330 return vec3_dot(v, v);
331}
332
336static inline float vec3_length(vec3 v) {
337 return sqrtf(vec3_length_squared(v));
338}
339
343static inline float vec3_distance(vec3 a, vec3 b) {
344 return vec3_length(vec3_sub(a, b));
345}
346
350static inline vec3 vec3_normalize(vec3 v) {
351 const float l = vec3_length(v);
352 return l > 0.f ? vec3_scale(v, 1.f / l) : v;
353}
354
358static inline vec3 vec3_min(vec3 a, vec3 b) {
359 return vec3_new(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z);
360}
361
365static inline vec3 vec3_max(vec3 a, vec3 b) {
366 return vec3_new(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z);
367}
368
372static inline vec3 vec3_lerp(vec3 a, vec3 b, float t) {
373 return vec3_add(vec3_scale(a, 1.f - t), vec3_scale(b, t));
374}
375
379static inline vec3 vec3_fma(vec3 v, vec3 add, float s) {
380 return vec3_new(fmaf(add.x, s, v.x), fmaf(add.y, s, v.y), fmaf(add.z, s, v.z));
381}
382
386static inline vec3 vec3_reflect(vec3 v, vec3 n) {
387 return vec3_sub(v, vec3_scale(n, 2.f * vec3_dot(v, n)));
388}
389
393static inline bool vec3_equal(vec3 a, vec3 b) {
394 return a.x == b.x && a.y == b.y && a.z == b.z;
395}
396
397#pragma mark - vec4
398
403typedef union {
404
408 float xyzw[4];
409
413 struct {
414 float x, y, z, w;
415 };
416
421
425 struct {
428 };
429} vec4;
430
434static inline vec4 vec4_new(float x, float y, float z, float w) {
435 return (vec4) { .x = x + 0.f, .y = y + 0.f, .z = z + 0.f, .w = w + 0.f };
436}
437
441static inline vec4 vec4_zero(void) {
442 return vec4_new(0.f, 0.f, 0.f, 0.f);
443}
444
448static inline vec4 vec4_one(void) {
449 return vec4_new(1.f, 1.f, 1.f, 1.f);
450}
451
455static inline vec4 vec4_add(vec4 a, vec4 b) {
456 return vec4_new(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
457}
458
462static inline vec4 vec4_sub(vec4 a, vec4 b) {
463 return vec4_new(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
464}
465
469static inline vec4 vec4_mul(vec4 a, vec4 b) {
470 return vec4_new(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
471}
472
476static inline vec4 vec4_scale(vec4 v, float s) {
477 return vec4_new(v.x * s, v.y * s, v.z * s, v.w * s);
478}
479
483static inline vec4 vec4_negate(vec4 v) {
484 return vec4_scale(v, -1.f);
485}
486
490static inline float vec4_dot(vec4 a, vec4 b) {
491 return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
492}
493
497static inline float vec4_length_squared(vec4 v) {
498 return vec4_dot(v, v);
499}
500
504static inline float vec4_length(vec4 v) {
505 return sqrtf(vec4_length_squared(v));
506}
507
511static inline float vec4_distance(vec4 a, vec4 b) {
512 return vec4_length(vec4_sub(a, b));
513}
514
518static inline vec4 vec4_normalize(vec4 v) {
519 const float l = vec4_length(v);
520 return l > 0.f ? vec4_scale(v, 1.f / l) : v;
521}
522
526static inline vec4 vec4_min(vec4 a, vec4 b) {
527 return vec4_new(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y, a.z < b.z ? a.z : b.z, a.w < b.w ? a.w : b.w);
528}
529
533static inline vec4 vec4_max(vec4 a, vec4 b) {
534 return vec4_new(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y, a.z > b.z ? a.z : b.z, a.w > b.w ? a.w : b.w);
535}
536
540static inline vec4 vec4_lerp(vec4 a, vec4 b, float t) {
541 return vec4_add(vec4_scale(a, 1.f - t), vec4_scale(b, t));
542}
543
547static inline bool vec4_equal(vec4 a, vec4 b) {
548 return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
549}
550
551#pragma mark - mat4
552
558typedef union {
559
563 float f[16];
564
568 float m[4][4];
569
573 vec4 cols[4];
574} mat4;
575
579static inline mat4 mat4_new(const float src[16]) {
580 mat4 m;
581 memcpy(m.f, src, sizeof(m.f));
582 return m;
583}
584
588static inline mat4 mat4_from_cols(vec4 c0, vec4 c1, vec4 c2, vec4 c3) {
589 return (mat4) { .cols = { c0, c1, c2, c3 } };
590}
591
595static inline mat4 mat4_identity(void) {
596 return mat4_new((const float[]) {
597 1.f, 0.f, 0.f, 0.f,
598 0.f, 1.f, 0.f, 0.f,
599 0.f, 0.f, 1.f, 0.f,
600 0.f, 0.f, 0.f, 1.f,
601 });
602}
603
607static inline mat4 mat4_mul(mat4 a, mat4 b) {
608 return mat4_from_cols(
609 vec4_new(
610 a.m[0][0] * b.m[0][0] + a.m[1][0] * b.m[0][1] + a.m[2][0] * b.m[0][2] + a.m[3][0] * b.m[0][3],
611 a.m[0][1] * b.m[0][0] + a.m[1][1] * b.m[0][1] + a.m[2][1] * b.m[0][2] + a.m[3][1] * b.m[0][3],
612 a.m[0][2] * b.m[0][0] + a.m[1][2] * b.m[0][1] + a.m[2][2] * b.m[0][2] + a.m[3][2] * b.m[0][3],
613 a.m[0][3] * b.m[0][0] + a.m[1][3] * b.m[0][1] + a.m[2][3] * b.m[0][2] + a.m[3][3] * b.m[0][3]
614 ),
615 vec4_new(
616 a.m[0][0] * b.m[1][0] + a.m[1][0] * b.m[1][1] + a.m[2][0] * b.m[1][2] + a.m[3][0] * b.m[1][3],
617 a.m[0][1] * b.m[1][0] + a.m[1][1] * b.m[1][1] + a.m[2][1] * b.m[1][2] + a.m[3][1] * b.m[1][3],
618 a.m[0][2] * b.m[1][0] + a.m[1][2] * b.m[1][1] + a.m[2][2] * b.m[1][2] + a.m[3][2] * b.m[1][3],
619 a.m[0][3] * b.m[1][0] + a.m[1][3] * b.m[1][1] + a.m[2][3] * b.m[1][2] + a.m[3][3] * b.m[1][3]
620 ),
621 vec4_new(
622 a.m[0][0] * b.m[2][0] + a.m[1][0] * b.m[2][1] + a.m[2][0] * b.m[2][2] + a.m[3][0] * b.m[2][3],
623 a.m[0][1] * b.m[2][0] + a.m[1][1] * b.m[2][1] + a.m[2][1] * b.m[2][2] + a.m[3][1] * b.m[2][3],
624 a.m[0][2] * b.m[2][0] + a.m[1][2] * b.m[2][1] + a.m[2][2] * b.m[2][2] + a.m[3][2] * b.m[2][3],
625 a.m[0][3] * b.m[2][0] + a.m[1][3] * b.m[2][1] + a.m[2][3] * b.m[2][2] + a.m[3][3] * b.m[2][3]
626 ),
627 vec4_new(
628 a.m[0][0] * b.m[3][0] + a.m[1][0] * b.m[3][1] + a.m[2][0] * b.m[3][2] + a.m[3][0] * b.m[3][3],
629 a.m[0][1] * b.m[3][0] + a.m[1][1] * b.m[3][1] + a.m[2][1] * b.m[3][2] + a.m[3][1] * b.m[3][3],
630 a.m[0][2] * b.m[3][0] + a.m[1][2] * b.m[3][1] + a.m[2][2] * b.m[3][2] + a.m[3][2] * b.m[3][3],
631 a.m[0][3] * b.m[3][0] + a.m[1][3] * b.m[3][1] + a.m[2][3] * b.m[3][2] + a.m[3][3] * b.m[3][3]
632 )
633 );
634}
635
639static inline mat4 mat4_translation(vec3 t) {
640 return mat4_new((const float[]) {
641 1.f, 0.f, 0.f, 0.f,
642 0.f, 1.f, 0.f, 0.f,
643 0.f, 0.f, 1.f, 0.f,
644 t.x, t.y, t.z, 1.f,
645 });
646}
647
651static inline mat4 mat4_rotation(float degrees, vec3 axis) {
652 const float r = float_radians(degrees);
653 const float c = cosf(r), s = sinf(r), ic = 1.f - c;
654 const vec3 u = vec3_normalize(axis);
655 return mat4_from_cols(
656 vec4_new(u.x * u.x * ic + c, u.x * u.y * ic + u.z * s, u.x * u.z * ic - u.y * s, 0.f),
657 vec4_new(u.x * u.y * ic - u.z * s, u.y * u.y * ic + c, u.y * u.z * ic + u.x * s, 0.f),
658 vec4_new(u.x * u.z * ic + u.y * s, u.y * u.z * ic - u.x * s, u.z * u.z * ic + c, 0.f),
659 vec4_new(0.f, 0.f, 0.f, 1.f)
660 );
661}
662
666static inline mat4 mat4_scale3(vec3 s) {
667 return mat4_new((const float[]) {
668 s.x, 0.f, 0.f, 0.f,
669 0.f, s.y, 0.f, 0.f,
670 0.f, 0.f, s.z, 0.f,
671 0.f, 0.f, 0.f, 1.f,
672 });
673}
674
678static inline mat4 mat4_scale(float s) {
679 return mat4_scale3(vec3_new(s, s, s));
680}
681
689static inline mat4 mat4_perspective(float fovy, float aspect, float znear, float zfar) {
690 const float f = 1.f / tanf(float_radians(fovy) * 0.5f);
691 const float nf = 1.f / (znear - zfar);
692 return mat4_new((const float[]) {
693 f / aspect, 0.f, 0.f, 0.f,
694 0.f, f, 0.f, 0.f,
695 0.f, 0.f, (znear + zfar) * nf, -1.f,
696 0.f, 0.f, (2.f * znear * zfar) * nf, 0.f,
697 });
698}
699
703static inline mat4 mat4_ortho(float left, float right, float bottom, float top, float znear, float zfar) {
704 const float lr = 1.f / (left - right);
705 const float bt = 1.f / (bottom - top);
706 const float nf = 1.f / (znear - zfar);
707 return mat4_new((const float[]) {
708 -2.f * lr, 0.f, 0.f, 0.f,
709 0.f, -2.f * bt, 0.f, 0.f,
710 0.f, 0.f, 2.f * nf, 0.f,
711 (left + right) * lr, (top + bottom) * bt, (zfar + znear) * nf, 1.f,
712 });
713}
714
718static inline mat4 mat4_look_at(vec3 eye, vec3 center, vec3 up) {
719 const vec3 z = vec3_normalize(vec3_sub(eye, center));
720 const vec3 x = vec3_normalize(vec3_cross(up, z));
721 const vec3 y = vec3_normalize(vec3_cross(z, x));
722 return mat4_new((const float[]) {
723 x.x, y.x, z.x, 0.f,
724 x.y, y.y, z.y, 0.f,
725 x.z, y.z, z.z, 0.f,
726 -vec3_dot(x, eye), -vec3_dot(y, eye), -vec3_dot(z, eye), 1.f,
727 });
728}
729
733static inline mat4 mat4_inverse(mat4 a) {
734 const float b00 = a.m[0][0] * a.m[1][1] - a.m[0][1] * a.m[1][0];
735 const float b01 = a.m[0][0] * a.m[1][2] - a.m[0][2] * a.m[1][0];
736 const float b02 = a.m[0][0] * a.m[1][3] - a.m[0][3] * a.m[1][0];
737 const float b03 = a.m[0][1] * a.m[1][2] - a.m[0][2] * a.m[1][1];
738 const float b04 = a.m[0][1] * a.m[1][3] - a.m[0][3] * a.m[1][1];
739 const float b05 = a.m[0][2] * a.m[1][3] - a.m[0][3] * a.m[1][2];
740 const float b06 = a.m[2][0] * a.m[3][1] - a.m[2][1] * a.m[3][0];
741 const float b07 = a.m[2][0] * a.m[3][2] - a.m[2][2] * a.m[3][0];
742 const float b08 = a.m[2][0] * a.m[3][3] - a.m[2][3] * a.m[3][0];
743 const float b09 = a.m[2][1] * a.m[3][2] - a.m[2][2] * a.m[3][1];
744 const float b10 = a.m[2][1] * a.m[3][3] - a.m[2][3] * a.m[3][1];
745 const float b11 = a.m[2][2] * a.m[3][3] - a.m[2][3] * a.m[3][2];
746
747 float det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
748 if (!det) {
749 return mat4_identity();
750 }
751 det = 1.f / det;
752
753 return mat4_new((const float[]) {
754 ( a.m[1][1] * b11 - a.m[1][2] * b10 + a.m[1][3] * b09) * det,
755 (-a.m[0][1] * b11 + a.m[0][2] * b10 - a.m[0][3] * b09) * det,
756 ( a.m[3][1] * b05 - a.m[3][2] * b04 + a.m[3][3] * b03) * det,
757 (-a.m[2][1] * b05 + a.m[2][2] * b04 - a.m[2][3] * b03) * det,
758 (-a.m[1][0] * b11 + a.m[1][2] * b08 - a.m[1][3] * b07) * det,
759 ( a.m[0][0] * b11 - a.m[0][2] * b08 + a.m[0][3] * b07) * det,
760 (-a.m[3][0] * b05 + a.m[3][2] * b02 - a.m[3][3] * b01) * det,
761 ( a.m[2][0] * b05 - a.m[2][2] * b02 + a.m[2][3] * b01) * det,
762 ( a.m[1][0] * b10 - a.m[1][1] * b08 + a.m[1][3] * b06) * det,
763 (-a.m[0][0] * b10 + a.m[0][1] * b08 - a.m[0][3] * b06) * det,
764 ( a.m[3][0] * b04 - a.m[3][1] * b02 + a.m[3][3] * b00) * det,
765 (-a.m[2][0] * b04 + a.m[2][1] * b02 - a.m[2][3] * b00) * det,
766 (-a.m[1][0] * b09 + a.m[1][1] * b07 - a.m[1][2] * b06) * det,
767 ( a.m[0][0] * b09 - a.m[0][1] * b07 + a.m[0][2] * b06) * det,
768 (-a.m[3][0] * b03 + a.m[3][1] * b01 - a.m[3][2] * b00) * det,
769 ( a.m[2][0] * b03 - a.m[2][1] * b01 + a.m[2][2] * b00) * det,
770 });
771}
772
776static inline vec3 mat4_transform(mat4 m, vec3 v) {
777 return vec3_new(
778 v.x * m.m[0][0] + v.y * m.m[1][0] + v.z * m.m[2][0] + m.m[3][0],
779 v.x * m.m[0][1] + v.y * m.m[1][1] + v.z * m.m[2][1] + m.m[3][1],
780 v.x * m.m[0][2] + v.y * m.m[1][2] + v.z * m.m[2][2] + m.m[3][2]
781 );
782}
783
787static inline vec4 mat4_transform4(mat4 m, vec4 v) {
788 return vec4_new(
789 v.x * m.m[0][0] + v.y * m.m[1][0] + v.z * m.m[2][0] + v.w * m.m[3][0],
790 v.x * m.m[0][1] + v.y * m.m[1][1] + v.z * m.m[2][1] + v.w * m.m[3][1],
791 v.x * m.m[0][2] + v.y * m.m[1][2] + v.z * m.m[2][2] + v.w * m.m[3][2],
792 v.x * m.m[0][3] + v.y * m.m[1][3] + v.z * m.m[2][3] + v.w * m.m[3][3]
793 );
794}
static mat4 mat4_look_at(vec3 eye, vec3 center, vec3 up)
Definition Mathlib.h:718
static vec3 vec3_scale(vec3 v, float s)
Definition Mathlib.h:297
static vec3 vec3_normalize(vec3 v)
Definition Mathlib.h:350
static vec4 vec4_min(vec4 a, vec4 b)
Definition Mathlib.h:526
static vec4 vec4_lerp(vec4 a, vec4 b, float t)
Definition Mathlib.h:540
static mat4 mat4_new(const float src[16])
Definition Mathlib.h:579
static vec2 vec2_max(vec2 a, vec2 b)
Definition Mathlib.h:208
static vec3 vec3_cross(vec3 a, vec3 b)
Definition Mathlib.h:318
static float float_radians(float degrees)
Definition Mathlib.h:39
static vec3 vec3_reflect(vec3 v, vec3 n)
Definition Mathlib.h:386
static vec2 vec2_scale(vec2 v, float s)
Definition Mathlib.h:151
static mat4 mat4_ortho(float left, float right, float bottom, float top, float znear, float zfar)
Definition Mathlib.h:703
static float float_clamp(float f, float min, float max)
Definition Mathlib.h:53
static float vec4_length(vec4 v)
Definition Mathlib.h:504
static float vec4_length_squared(vec4 v)
Definition Mathlib.h:497
static float vec4_distance(vec4 a, vec4 b)
Definition Mathlib.h:511
static vec2 vec2_add(vec2 a, vec2 b)
Definition Mathlib.h:130
static float float_lerp(float a, float b, float t)
Definition Mathlib.h:67
static vec2 vec2_zero(void)
Definition Mathlib.h:116
static vec3 vec3_sub(vec3 a, vec3 b)
Definition Mathlib.h:283
static float float_degrees(float radians)
Definition Mathlib.h:46
static bool vec2_equal(vec2 a, vec2 b)
Definition Mathlib.h:222
static vec3 mat4_transform(mat4 m, vec3 v)
Definition Mathlib.h:776
static vec2 vec2_normalize(vec2 v)
Definition Mathlib.h:193
static vec3 vec3_lerp(vec3 a, vec3 b, float t)
Definition Mathlib.h:372
static float vec3_length_squared(vec3 v)
Definition Mathlib.h:329
static vec2 vec2_one(void)
Definition Mathlib.h:123
static vec2 vec2_sub(vec2 a, vec2 b)
Definition Mathlib.h:137
static vec4 mat4_transform4(mat4 m, vec4 v)
Definition Mathlib.h:787
static vec4 vec4_new(float x, float y, float z, float w)
Definition Mathlib.h:434
static mat4 mat4_translation(vec3 t)
Definition Mathlib.h:639
static float vec4_dot(vec4 a, vec4 b)
Definition Mathlib.h:490
static float vec2_distance(vec2 a, vec2 b)
Definition Mathlib.h:186
static bool vec3_equal(vec3 a, vec3 b)
Definition Mathlib.h:393
static vec3 vec3_new(float x, float y, float z)
Definition Mathlib.h:255
static vec4 vec4_scale(vec4 v, float s)
Definition Mathlib.h:476
static float vec2_dot(vec2 a, vec2 b)
Definition Mathlib.h:165
static mat4 mat4_inverse(mat4 a)
Definition Mathlib.h:733
static mat4 mat4_perspective(float fovy, float aspect, float znear, float zfar)
Definition Mathlib.h:689
static mat4 mat4_identity(void)
Definition Mathlib.h:595
static vec2 vec2_negate(vec2 v)
Definition Mathlib.h:158
static vec4 vec4_sub(vec4 a, vec4 b)
Definition Mathlib.h:462
static mat4 mat4_rotation(float degrees, vec3 axis)
Definition Mathlib.h:651
static vec3 vec3_mul(vec3 a, vec3 b)
Definition Mathlib.h:290
static float float_smoothstep(float edge0, float edge1, float f)
Definition Mathlib.h:74
static vec2 vec2_mul(vec2 a, vec2 b)
Definition Mathlib.h:144
static vec3 vec3_zero(void)
Definition Mathlib.h:262
static float float_sign(float f)
Definition Mathlib.h:82
static vec3 vec3_one(void)
Definition Mathlib.h:269
static float vec3_dot(vec3 a, vec3 b)
Definition Mathlib.h:311
static mat4 mat4_scale(float s)
Definition Mathlib.h:678
static float float_saturate(float f)
Definition Mathlib.h:60
static vec3 vec3_add(vec3 a, vec3 b)
Definition Mathlib.h:276
static float vec2_length(vec2 v)
Definition Mathlib.h:179
static vec4 vec4_negate(vec4 v)
Definition Mathlib.h:483
static float vec3_length(vec3 v)
Definition Mathlib.h:336
static vec4 vec4_add(vec4 a, vec4 b)
Definition Mathlib.h:455
static vec3 vec3_negate(vec3 v)
Definition Mathlib.h:304
static vec2 vec2_min(vec2 a, vec2 b)
Definition Mathlib.h:201
static vec4 vec4_one(void)
Definition Mathlib.h:448
static mat4 mat4_from_cols(vec4 c0, vec4 c1, vec4 c2, vec4 c3)
Definition Mathlib.h:588
static vec4 vec4_normalize(vec4 v)
Definition Mathlib.h:518
static vec2 vec2_lerp(vec2 a, vec2 b, float t)
Definition Mathlib.h:215
static vec3 vec3_min(vec3 a, vec3 b)
Definition Mathlib.h:358
static mat4 mat4_scale3(vec3 s)
Definition Mathlib.h:666
static vec3 vec3_max(vec3 a, vec3 b)
Definition Mathlib.h:365
static vec4 vec4_zero(void)
Definition Mathlib.h:441
static float vec3_distance(vec3 a, vec3 b)
Definition Mathlib.h:343
static vec2 vec2_new(float x, float y)
Definition Mathlib.h:109
#define M_PI
Definition Mathlib.h:31
static bool vec4_equal(vec4 a, vec4 b)
Definition Mathlib.h:547
static vec3 vec3_fma(vec3 v, vec3 add, float s)
Definition Mathlib.h:379
static vec4 vec4_mul(vec4 a, vec4 b)
Definition Mathlib.h:469
static mat4 mat4_mul(mat4 a, mat4 b)
Definition Mathlib.h:607
static float vec2_length_squared(vec2 v)
Definition Mathlib.h:172
static vec4 vec4_max(vec4 a, vec4 b)
Definition Mathlib.h:533
Column-major 4×4 single-precision matrix. Layout matches GLSL mat4.
Definition Mathlib.h:558
float f[16]
Flat array accessor.
Definition Mathlib.h:563
float m[4][4]
Column-major 2D array accessor. m[col][row].
Definition Mathlib.h:568
vec4 cols[4]
Column vectors.
Definition Mathlib.h:573
Two-component single-precision vector. Component layout matches GLSL vec2.
Definition Mathlib.h:91
float x
Definition Mathlib.h:102
float y
Definition Mathlib.h:102
Three-component single-precision vector. Component layout matches GLSL vec3.
Definition Mathlib.h:232
float x
Definition Mathlib.h:243
vec2 xy
Swizzle to vec2.
Definition Mathlib.h:249
float y
Definition Mathlib.h:243
float z
Definition Mathlib.h:243
Four-component single-precision vector. Component layout matches GLSL vec4.
Definition Mathlib.h:403
float w
Definition Mathlib.h:414
float z
Definition Mathlib.h:414
vec3 xyz
Swizzle to vec3.
Definition Mathlib.h:420
float x
Definition Mathlib.h:414
vec2 zw
Definition Mathlib.h:427
float y
Definition Mathlib.h:414
vec2 xy
Definition Mathlib.h:426