summaryrefslogtreecommitdiff
path: root/include/toBeSorted/deg_angle_util.h
blob: ec71074826325bfd093b881ebd6c32d93c27e4a6 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef TOBESORTED_DEG_ANGLE_UTIL_H
#define TOBESORTED_DEG_ANGLE_UTIL_H

#include "common.h"
#include "m/m_vec.h"

struct dDegree {
public:
    /** Wraps a degree angle so that value is within [-180.0f; 180.0f] */
    static f32 adjust(f32 value);
    /** Canonicalizes a degree angle so that value is within [-180.0f; 180.0f) */
    static f32 canonicalize(f32 value);

    f32 rotate180F() const;
    void rotate180();
    f32 abs() const;

    f32 sin() const;
    f32 cos() const;
    f32 tan() const;
    f32 tan2() const;
    f32 toRad() const;
    s16 toIdx(); // can't be const...

    void Set(f32 v) {
        value = adjust(v);
    }

    f32 operator-(const dDegree &other) const {
        return value - other.value;
    }

    f32 operator+(const dDegree &other) const {
        return value + other.value;
    }

    dDegree() : value(0.0f) {}
    dDegree(f32 value) : value(adjust(value)) {}
    dDegree(const dDegree &other) : value(other.value) {}

    /* 0x0 */ f32 value;
};

struct dPolar {
public:
    dPolar() : R(0.0f), U(0.0f), V(0.0f) {}
    dPolar(f32 r, f32 u, f32 v);
    dPolar(const mVec3_c &v);

    dPolar *canonicalize();

    void Set(f32 r, f32 u, f32 v);

    void setCartesian(const mVec3_c &v);
    mVec3_c toCartesian() const;

    f32 SetR(f32 r);
    f32 SetU(f32 u);
    f32 SetV(f32 v);

    /* 0x0 */ f32 R;
    /* 0x4 */ dDegree U;
    /* 0x8 */ dDegree V;
};

#endif