aboutsummaryrefslogtreecommitdiff
path: root/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'vector.c')
-rw-r--r--vector.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/vector.c b/vector.c
index 0bcd1dc..661516e 100644
--- a/vector.c
+++ b/vector.c
@@ -43,6 +43,17 @@ COORD_T vector_len(vector_t *v)
return sqrt( v->x * v->x + v->y * v->y + v->z * v->z );
}
+void vector_norm(vector_t *v)
+{
+ COORD_T len = vector_len(v);
+ if (len == 0) {
+ vector_set(v, 0, 0, 0);
+ return;
+ }
+
+ vector_scale_inv(v, v, len);
+}
+
vector_t *vector_add(vector_t *dest, vector_t *a, vector_t *b)
{
dest = vector_exists(dest);