aboutsummaryrefslogtreecommitdiff
path: root/include/fml/vec3.h
blob: a006619ae8bc4bd9a3d1d7775975ea7690aaab6a (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef VEC3_H
#define VEC3_H
#include <iostream>

#include "fml.h"

namespace fml {
    class quat;

    class vec3 {
    public:
        scalar v[3];
    public:
        vec3();
        vec3(scalar x);
        vec3(scalar x, scalar y, scalar z);
        scalar &operator[](int index);
        scalar operator[](int index) const;
        vec3 operator*(scalar scale) const;
        vec3 operator/(scalar scale) const;
        vec3 operator+(const vec3 &other) const;
        vec3 operator-(const vec3 &other) const;
        vec3 operator-() const;
        const vec3 &operator*=(scalar scale);
        const vec3 &operator/=(scalar scale);
        const vec3 &operator+=(const vec3 &other);
        const vec3 &operator-=(const vec3 &other);
        scalar magnitude() const;
        scalar magnitudeSquared() const;
        vec3 normalize() const;
        scalar dot(const vec3 &other) const;

        /* order is this x other. */
        vec3 cross(const vec3 &other) const;

        /* rotate by a rotation quaternion */
        vec3 rotateby(const quat &rotquat) const;

        /* return an arbitrary unit vector normal to other */
        static vec3 any_unit_normal(const vec3 &other);
    };

    vec3 operator*(scalar scale, const vec3 &v);

    std::ostream &operator<<(std::ostream &output, const vec3 &v);
    std::istream &operator>>(std::istream &input, vec3 &v);
}

#endif