From 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Fri, 16 Jan 2026 23:02:32 +0100 Subject: Initial commit --- 08-august/src/math/vector2f.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 08-august/src/math/vector2f.c (limited to '08-august/src/math/vector2f.c') diff --git a/08-august/src/math/vector2f.c b/08-august/src/math/vector2f.c new file mode 100644 index 0000000..37ffa9c --- /dev/null +++ b/08-august/src/math/vector2f.c @@ -0,0 +1,54 @@ +#include "vector2f.h" +#include + +vec2_t vec2_add(const vec2_t* a, const vec2_t* b) +{ + vec2_t c; + c.x = a->x + b->x; + c.y = a->y + b->y; + return c; +} + +vec2_t vec2_sub(const vec2_t* a, const vec2_t* b) +{ + vec2_t c; + c.x = a->x - b->x; + c.y = a->y - b->y; + return c; +} + +vec2_t vec2_scalar_mul(const vec2_t* a, GLfloat scalar) +{ + vec2_t c; + c.x = a->x * scalar; + c.y = a->y * scalar; + return c; +} + +GLfloat vec2_dot_mul(const vec2_t* a, const vec2_t* b) +{ + return ( (a->x * b->x) + (a->y * b->y) ); +} + + +vec2_t vec2_cross_mul(const vec2_t* a, const vec2_t* b) +{ + vec2_t c; + c.x = (a->x * b->y) - (a->y * b->x); + c.y = (a->y * b->x) - (a->x * b->y); + return c; +} + +GLfloat vec2_length(vec2_t* a) +{ + return SDL_sqrtf(SDL_pow(a->x, 2.0f) + SDL_pow(a->y, 2.0f) ); +} + +vec2_t vec2_normalize(vec2_t* a) +{ + vec2_t b; + GLfloat length = vec2_length(a); + b.x = a->x / length; + b.y = a->y / length; + return b; +} -- cgit v1.2.3