diff options
author | Marvin Borner | 2021-03-26 21:55:50 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-26 22:02:20 +0100 |
commit | 05498860e8f7b1e8bb27880bc7526de026694804 (patch) | |
tree | 3bddf16e9439a950a3810d45e42a5cefdbcb7663 /libs/libc/inc/vec.h | |
parent | a96e9c4c858d47f61b89d879aa0ce6a02bdacb38 (diff) |
Renamed libs
Cleaner and more flexible.
Diffstat (limited to 'libs/libc/inc/vec.h')
-rw-r--r-- | libs/libc/inc/vec.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/libs/libc/inc/vec.h b/libs/libc/inc/vec.h new file mode 100644 index 0000000..a036931 --- /dev/null +++ b/libs/libc/inc/vec.h @@ -0,0 +1,36 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef VEC_H +#define VEC_H + +#include <def.h> + +typedef struct vec2 { + u32 x, y; +} vec2; + +typedef struct vec3 { + u32 x, y, z; +} vec3; + +#define vec2(x, y) ((vec2){ (x), (y) }) +#define vec2to3(a, z) ((vec3){ a.x, a.y, (z) }) +#define vec2_add(a, b) ((vec2){ a.x + b.x, a.y + b.y }) +#define vec2_sub(a, b) ((vec2){ a.x - b.x, a.y - b.y }) +#define vec2_mul(a, b) ((vec2){ a.x * (b), a.y * (b) }) +#define vec2_div(a, b) ((vec2){ a.x / (b), a.y / (b) }) +#define vec2_dot(a, b) ((u32)(a.x * b.x + a.y * b.y)) +#define vec2_eq(a, b) (a.x == b.x && a.y == b.y) + +#define vec3(x, y, z) ((vec3){ (x), (y), (z) }) +#define vec3to2(a) ((vec2){ a.x, a.y }) +#define vec3_add(a, b) ((vec3){ a.x + b.x, a.y + b.y, a.z + b.z }) +#define vec3_sub(a, b) ((vec3){ a.x - b.x, a.y - b.y, a.z - b.z }) +#define vec3_mul(a, b) ((vec3){ a.x * (b), a.y * (b), a.z * (b) }) +#define vec3_div(a, b) ((vec3){ a.x / (b), a.y / (b), a.z / (b) }) +#define vec3_dot(a, b) ((u32)(a.x * b.x + a.y * b.y + a.z * b.z)) +#define vec3_eq(a, b) (a.x == b.x && a.y == b.y && a.z == c.z) +#define vec3_cross(a, b) \ + ((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 }) + +#endif |