Add more vector operations

This commit is contained in:
2025-10-18 17:43:22 +01:00
parent 1907d00782
commit 0b4f014b33
2 changed files with 12 additions and 0 deletions

10
maths.c
View File

@@ -2,11 +2,21 @@
#include <math.h> #include <math.h>
float vec2_len(vec2_t v)
{
return sqrtf(v.x * v.x + v.y * v.y);
}
vec2_t vec2_add(vec2_t v1, vec2_t v2) vec2_t vec2_add(vec2_t v1, vec2_t v2)
{ {
return (vec2_t) { v1.x + v2.x, v1.y + v2.y }; return (vec2_t) { v1.x + v2.x, v1.y + v2.y };
} }
vec2_t vec2_sub(vec2_t v1, vec2_t v2)
{
return (vec2_t) { v1.x - v2.x, v1.y - v2.y };
}
vec2_t vec2_scale(vec2_t v, float s) vec2_t vec2_scale(vec2_t v, float s)
{ {
return (vec2_t) { s * v.x, s * v.y }; return (vec2_t) { s * v.x, s * v.y };

View File

@@ -19,7 +19,9 @@ typedef struct {
vec3_t x, y, z; vec3_t x, y, z;
} mat3_t; } mat3_t;
float vec2_len(vec2_t v);
vec2_t vec2_add(vec2_t v1, vec2_t v2); vec2_t vec2_add(vec2_t v1, vec2_t v2);
vec2_t vec2_sub(vec2_t v1, vec2_t v2);
vec2_t vec2_scale(vec2_t v, float s); vec2_t vec2_scale(vec2_t v, float s);
vec3_t vec2_extend(vec2_t v); vec3_t vec2_extend(vec2_t v);