aboutsummaryrefslogtreecommitdiff
path: root/libs/libc/inc/vec.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libc/inc/vec.h')
-rw-r--r--libs/libc/inc/vec.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/libs/libc/inc/vec.h b/libs/libc/inc/vec.h
index bcd4cca..b2755ae 100644
--- a/libs/libc/inc/vec.h
+++ b/libs/libc/inc/vec.h
@@ -5,6 +5,10 @@
#include <def.h>
+/**
+ * Unsigned 32
+ */
+
typedef struct vec2 {
u32 x, y;
} vec2;
@@ -35,4 +39,38 @@ typedef struct vec3 {
((vec3){ a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x })
#define vec3_sum(a) ((u32)(a.x + a.y + a.z))
+/**
+ * Floating 32
+ */
+
+typedef struct vec2f {
+ f64 x, y;
+} vec2f;
+
+typedef struct vec3f {
+ f64 x, y, z;
+} vec3f;
+
+#define vec2f(x, y) ((vec2f){ (x), (y) })
+#define vec2fto3f(a, z) ((vec3f){ a.x, a.y, (z) })
+#define vec2f_add(a, b) ((vec2f){ a.x + b.x, a.y + b.y })
+#define vec2f_sub(a, b) ((vec2f){ a.x - b.x, a.y - b.y })
+#define vec2f_mul(a, b) ((vec2f){ a.x * (b), a.y * (b) })
+#define vec2f_div(a, b) ((vec2f){ a.x / (b), a.y / (b) })
+#define vec2f_dot(a, b) ((f64)(a.x * b.x + a.y * b.y))
+#define vec2f_eq(a, b) (a.x == b.x && a.y == b.y)
+#define vec2f_sum(a) ((f64)(a.x + a.y))
+
+#define vec3f(x, y, z) ((vec3f){ (x), (y), (z) })
+#define vec3fto2f(a) ((vec2f){ a.x, a.y })
+#define vec3f_add(a, b) ((vec3f){ a.x + b.x, a.y + b.y, a.z + b.z })
+#define vec3f_sub(a, b) ((vec3f){ a.x - b.x, a.y - b.y, a.z - b.z })
+#define vec3f_mul(a, b) ((vec3f){ a.x * (b), a.y * (b), a.z * (b) })
+#define vec3f_div(a, b) ((vec3f){ a.x / (b), a.y / (b), a.z / (b) })
+#define vec3f_dot(a, b) ((f64f)(a.x * b.x + a.y * b.y + a.z * b.z))
+#define vec3f_eq(a, b) (a.x == b.x && a.y == b.y && a.z == c.z)
+#define vec3f_cross(a, b) \
+ ((vec3f){ a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x })
+#define vec3f_sum(a) ((f64)(a.x + a.y + a.z))
+
#endif