summaryrefslogtreecommitdiff
path: root/vector.h
blob: c4f5ab33548d6ab082216de4ff78978e6dabee5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <math.h>

typedef float scalar;

typedef struct vector_t {
    enum { RECT, SPH } type;
    union {
        struct {
            scalar x, y, z;
        } rect;
        struct {
            scalar r, elevation, azimuth;
        } sph;
    };
} vector;

scalar vect_abs(vector);

vector vect_mul(vector, scalar);
vector vect_add(vector, vector);
vector vect_sub(vector, vector);

vector vect_normalize(vector);
vector vect_negate(vector);

void vect_to_rect(vector*);
void vect_to_sph(vector*);

scalar vect_dot(vector v1, vector v2);
vector vect_cross(vector v1, vector v2);