From e4483eca01b48b943cd0461e24a74ae1a3139ed4 Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Wed, 12 Feb 2025 21:57:46 +1100 Subject: Update to most recent version (old initial commit) --- src/shared/math/angles.hh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/shared/math/angles.hh (limited to 'src/shared/math/angles.hh') 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 +#include + +#include + +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 -- cgit v1.2.3