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/vector4f.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 08-august/src/math/vector4f.c (limited to '08-august/src/math/vector4f.c') diff --git a/08-august/src/math/vector4f.c b/08-august/src/math/vector4f.c new file mode 100644 index 0000000..57e4925 --- /dev/null +++ b/08-august/src/math/vector4f.c @@ -0,0 +1,53 @@ +#include "vector4f.h" +#include + +vec4_t vec4_add(const vec4_t* a, const vec4_t* b) +{ + vec4_t c; + c.x = a->x + b->x; + c.y = a->y + b->y; + c.z = a->z + b->z; + c.w = a->w + b->w; + return c; +} + +vec4_t vec4_sub(const vec4_t* a, const vec4_t* b) +{ + vec4_t c; + c.x = a->x - b->x; + c.y = a->y - b->y; + c.z = a->z - b->z; + c.w = a->w - b->w; + return c; +} + +vec4_t vec4_scalar_mul(const vec4_t* a, GLfloat scalar) +{ + vec4_t c; + c.x = a->x * scalar; + c.y = a->y * scalar; + c.z = a->z * scalar; + c.w = a->w * scalar; + return c; +} + +GLfloat vec4_dot_mul(const vec4_t* a, const vec4_t* b) +{ + return ( (a->x * b->x) + (a->y * b->y) + (a->z * b->z) + (a->w * b->w) ); +} + +GLfloat vec4_length(vec4_t* a) +{ + return SDL_sqrtf(SDL_pow(a->x, 2.0f) + SDL_pow(a->y, 2.0f) + SDL_pow(a->z, 2.0f) + SDL_pow(a->w, 2.0f) ); +} + +vec4_t vec4_normalize(vec4_t* a) +{ + vec4_t b; + GLfloat length = vec4_length(a); + b.x = a->x / length; + b.y = a->y / length; + b.z = a->z / length; + b.w = a->w / length; + return b; +} -- cgit v1.2.3