summary refs log tree commit diff
path: root/src/Math/Rotation.hpp
blob: 0c5c6069b3cffbaa5fbf950b673c377a00b46538 (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
#pragma once

#include <cmath>
#include "Vector.hpp"

struct Rotation {
public:
    Rotation() : vector{} {};

    Rotation(Vector<3> vector) : vector{ wrap(vector) } {};

    Rotation(float angles[3]) : Rotation(angles[0], angles[1], angles[2]) {};

    Rotation(float pitch, float yaw, float roll) {
        vector = wrap({pitch, yaw, roll });
    };

    Rotation operator+(Rotation other) const {
        return wrap(vector + other.vector);
    }

    std::string string() const {
        return vector.string();
    }

    static Vector<3> wrap(Vector<3> v) {
        return v.map([](auto a) { return fmod(a, 360.0f); });
    }

    float& pitch() {
        return vector[0];
    }

    float& yaw() {
        return vector[1];
    }

    float& roll() {
        return vector[2];
    }

    Vector<3> vector;
};