aboutsummaryrefslogtreecommitdiff
path: root/vector.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-05-07 09:46:56 +0200
committerJulian T <julian@jtle.dk>2020-05-07 09:46:56 +0200
commitba99860760eda6ec221b15190547736407723f84 (patch)
tree18aa0f770efd4d584ea44709c16c78ea82d3ec3f /vector.c
parentc2bd065bafe52a3e85be7a87945ed47aec7a33d9 (diff)
Global illumination
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);