From cb869cb647b8cfb78e0d762e952508d044f556cf Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 24 Sep 2023 23:41:13 +0200 Subject: [PATCH] vmulf is now a Vector*Vector multiplication, Vector*float is now vmulff --- src/vmath.h | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/vmath.h b/src/vmath.h index 838bffd..58d6ed1 100644 --- a/src/vmath.h +++ b/src/vmath.h @@ -2,6 +2,15 @@ #define _fencer_vmath_h #include + +#if VMATH_SDL == 1 + +#include +typedef SDL_FPoint Vector; +typedef SDL_Point IVector; + +#else + typedef struct Vector { float x; float y; @@ -12,6 +21,8 @@ typedef struct IVector { int y; } IVector; +#endif + // Vector Constant Macros #define ZeroVector (Vector){0.0f, 0.0f} #define InfinityVector (Vector){INFINITY, INFINITY} @@ -43,10 +54,14 @@ Vector vsubf(Vector a, Vector b) { return (Vector){a.x - b.x, a.y - b.y}; } static inline -Vector vmulf(Vector a, float b) { +Vector vmulff(Vector a, float b) { return (Vector){a.x * b, a.y * b}; } static inline +Vector vmulf(Vector a, Vector b) { + return (Vector) {a.x * b.x, a.y * b.y}; +} +static inline Vector vinvf(Vector a) { return (Vector){-a.x, -a.y}; } @@ -64,7 +79,7 @@ float vsqrmagnitudef(Vector a) { } static inline Vector vnormalizedf(Vector a) { - return vmulf(a, 1.0/vmagnitudef(a)); + return vmulff(a, 1.0/vmagnitudef(a)); } static inline float vdotf(Vector a, Vector b) { @@ -78,5 +93,29 @@ static inline float vsqrdistf(Vector a, Vector b) { return vsqrmagnitudef(vsubf(a, b)); } +static inline +Vector vreciprocalf(Vector a) { + return (Vector){1.0/a.x, 1.0/a.y}; +} +static inline +Vector vrotatef(Vector a, float t) { + return (Vector){ + cosf(t) * a.x - sinf(t) * a.y, + sinf(t) * a.x + cosf(t) * a.y + }; +} + +static inline +IVector vaddi(IVector a, IVector b) { + return (IVector){a.x + b.x, a.y + b.y}; +} +static inline +IVector vsubi(IVector a, IVector b) { + return (IVector){a.x - b.x, a.y - b.y}; +} +static inline +IVector vmuli(IVector a, IVector b) { + return (IVector){a.x * b.x, a.y * b.y}; +} #endif // !_fencer_vmath_h