Add more vector operations
This commit is contained in:
10
maths.c
10
maths.c
@@ -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 };
|
||||||
|
|||||||
2
maths.h
2
maths.h
@@ -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);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user