aboutsummaryrefslogtreecommitdiff
path: root/src/shared/math/angles.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/math/angles.hh')
-rw-r--r--src/shared/math/angles.hh44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/shared/math/angles.hh b/src/shared/math/angles.hh
new file mode 100644
index 0000000..aec388f
--- /dev/null
+++ b/src/shared/math/angles.hh
@@ -0,0 +1,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