From 63a84080f9f0e3d719d5470e370584a5eff18a47 Mon Sep 17 00:00:00 2001 From: Julian T Date: Wed, 19 Feb 2020 22:35:48 +0100 Subject: Viewpoint system and share/ray intersection working --- vector.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 vector.h (limited to 'vector.h') diff --git a/vector.h b/vector.h new file mode 100644 index 0000000..5609215 --- /dev/null +++ b/vector.h @@ -0,0 +1,36 @@ +#ifndef VECTOR_H +#define VECTOR_H + +#define COORD_T float +#define ZERO_APROX 1e-6 + +typedef struct { + COORD_T x; + COORD_T y; + COORD_T z; +} vector_t; + +// Set vector to specified coordinates +// If p is NULL it is created +vector_t *vector_set(vector_t *p, COORD_T x, COORD_T y, COORD_T z); + +// Copy vector src. If dest is NULL a vector is allocated +vector_t *vector_copy(vector_t *dest, vector_t *src); + +// Calculate the length of v +COORD_T vector_len(vector_t *v); + +COORD_T vector_dot(vector_t *a, vector_t *b); + +// Basic math functions +vector_t *vector_add(vector_t *dest, vector_t *a, vector_t *b); +vector_t *vector_sub(vector_t *dest, vector_t *a, vector_t *b); +vector_t *vector_mult(vector_t *dest, vector_t *a, vector_t *b); + +vector_t *vector_cross(vector_t *dest, vector_t *a, vector_t *b); + +vector_t *vector_scale(vector_t *dest, vector_t *a, COORD_T b); +vector_t *vector_scale_inv(vector_t *dest, vector_t *a, COORD_T b); + +void vector_print(vector_t *v); +#endif -- cgit v1.2.3