aboutsummaryrefslogtreecommitdiff
path: root/src/core/vector.hpp
blob: adc0bae3436b8ab3e2b96d66dbe0a0683c01e602 (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
50
#ifndef VECTOR_H
#define VECTOR_H

#include <iostream>
#include <math.h>

class Vec2d {
    public:
        Vec2d();
        Vec2d(double x, double y);

        void set(double x, double y);

        double m_x, m_y, m_z;
};

class Vec3d {
    public:
        Vec3d();
        Vec3d(double x, double y, double z);

        static inline Vec3d FromSpherical(double sinTheta, double cosTheta, double phi) {
            return Vec3d(sinTheta * std::cos(phi),
                    sinTheta * std::sin(phi),
                    cosTheta);
        }

        void set(double x, double y, double z);
        void normalize();

        double length() const;
        double dot(const Vec3d &vec) const;

        Vec3d cross(const Vec3d &vec) const;

        // Operators
        Vec3d operator+(const Vec3d &vec) const;
        Vec3d& operator+=(const Vec3d &vec);
        Vec3d operator-(const Vec3d &vec) const;
        Vec3d operator-() const;
        Vec3d operator*(double) const;
        Vec3d operator*(const Vec3d &vec) const;
        Vec3d operator/(double) const;

        friend std::ostream& operator<<(std::ostream& os, const Vec3d &v);

        double m_x, m_y, m_z;
};

#endif