aboutsummaryrefslogtreecommitdiff
path: root/src/shared/math/angles.hh
blob: aec388f340e2683bdbf63ab5f96b4cb0ca27efff (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
#ifndef SHARED_MATH_ANGLES_HH_
#define SHARED_MATH_ANGLES_HH_

#include <algorithm>
#include <compare>

#include <glm/glm.hpp>

namespace shared {
namespace math {

struct angles {
public:
    float pitch;
    float yaw;

public:
    // Returns the closest yaw from this to other, assumes they are normalised.
    static float get_yaw_delta(const float& a, const float& b) noexcept;

public:
    glm::vec3 to_dir() const noexcept;

public:
    // Removes bad floating point values!
    // Clamps pitch to its max positions of += glm::radians(89).
    // Clamps yaw to its max positions of += glm::radians(180).
    angles& clamp() noexcept;

    // Returns yaw angles to [glm::radians(-180), glm::radians(180)].
    angles& normalise() noexcept;

public:
    angles operator+(const angles& a) const noexcept;
    angles operator*(const float& f) const noexcept;

public:
    auto operator<=>(const angles&) const noexcept = default;
};

} // namespace math
} // namespace shared

#endif