From 3eedcceb09c19498b7e98828dbb6298625636812 Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 24 Apr 2018 13:36:09 +0200 Subject: [PATCH] add overloaded vec_new (with macro tricks) --- sweet_math_short.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ sweet_math_short.h | 18 +++++++++++ 2 files changed, 99 insertions(+) create mode 100644 sweet_math_short.c diff --git a/sweet_math_short.c b/sweet_math_short.c new file mode 100644 index 0000000..f91e68c --- /dev/null +++ b/sweet_math_short.c @@ -0,0 +1,81 @@ +#include "sweet_math.h" + +vec2 vec2_new_2f(float x, float y) +{ + vec2 v; + v.x = x; + v.y = y; + return v; +} + +vec2 vec2_new_v3(vec3 w) +{ + vec2 v; + v.x = w.x; + v.y = w.y; + return v; +} + +vec3 vec3_new_3f(float x, float y, float z) +{ + vec3 v; + v.x = x; + v.y = y; + v.z = z; + return v; +} + +vec3 vec3_new_v2_1f(vec2 w, float z) +{ + vec3 v; + v.x = w.x; + v.y = w.y; + v.z = z; + return v; +} + +vec3 vec3_new_v4(vec4 w) +{ + vec3 v; + v.x = w.x; + v.y = w.y; + v.z = w.z; + return v; +} + +vec4 vec4_new_4f(float x, float y, float z, float w) +{ + vec4 v; + v.x = x; + v.y = y; + v.z = z; + v.w = w; + return v; +} + +vec4 vec4_new_v2_2f(vec2 u, float z, float w) +{ + vec4 v; + v.x = u.x; + v.y = u.y; + v.z = z; + v.w = w; + return v; +} + +vec4 vec4_new_v3_1f(vec3 u, float w) +{ + vec4 v; + v.x = u.x; + v.y = u.y; + v.z = u.z; + v.w = w; + return v; +} + +vec4 vec4_new_v4 (vec4 v) +{ + return v; +} + + diff --git a/sweet_math_short.h b/sweet_math_short.h index 89af7b6..9323aed 100644 --- a/sweet_math_short.h +++ b/sweet_math_short.h @@ -21,6 +21,24 @@ #include "sweet_math.h" +#define VEC2_BUILDER(_1, _2, NAME, ...) NAME +#define VEC3_BUILDER(_1, _2, _3, NAME, ...) NAME +#define VEC4_BUILDER(_1, _2, _3, _4, NAME, ...) NAME + +#define vec2_new(...) VEC2_BUILDER(__VA_ARGS__, vec2_new_2f, vec2_new_v3)(__VA_ARGS__) +#define vec3_new(...) VEC3_BUILDER(__VA_ARGS__, vec3_new_3f, vec3_new_v2_1f, vec3_new_v4)(__VA_ARGS__) +#define vec4_new(...) VEC4_BUILDER(__VA_ARGS__, vec4_new_4f, vec4_new_v2_2f, vec4_new_v3_1f, vec4_new_v4)(__VA_ARGS__) + +vec2 vec2_new_2f(float x, float y); +vec2 vec2_new_v3(vec3 w); +vec3 vec3_new_3f(float x, float y, float z); +vec3 vec3_new_v2_1f(vec2 w, float z); +vec3 vec3_new_v4(vec4 w); +vec4 vec4_new_4f(float x, float y, float z, float w); +vec4 vec4_new_v2_2f(vec2 u, float z, float w); +vec4 vec4_new_v3_1f(vec3 u, float w); +vec4 vec4_new_v4 (vec4 v); + #define radian_2_degree(radian) radian * 57.2957795130823208767981548 #define degree_2_radian(degree) degree * 0.01745329251994329576923690768488