From efecc44a520b8bd160aafe9d70a5f6f28ddf1011 Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Wed, 19 Feb 2025 11:20:48 +0100 Subject: [PATCH] better angle precision --- src/types.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/types.hpp b/src/types.hpp index 0d5210b..345e14b 100644 --- a/src/types.hpp +++ b/src/types.hpp @@ -3,39 +3,40 @@ #include #include #include +#include #ifndef TYPES_NS #define TYPES_NS -struct Angle360 { +struct Angle { private: - int value{0}; + float value{0}; void normalize() { - value %= 360; + value = std::fmod(value, 360); if (value < 0) value += 360; // Handle negative values } public: // Constructor - Angle360(int val = 0) : value(val) { normalize(); } + Angle(int val = 0) : value(val) { normalize(); } // Assignment operator - Angle360 &operator=(int val) { + Angle &operator=(int val) { value = val; normalize(); return *this; } // Compound assignment - Angle360 &operator+=(int rhs) { + Angle &operator+=(int rhs) { value += rhs; normalize(); return *this; } - Angle360 &operator-=(int rhs) { + Angle &operator-=(int rhs) { value -= rhs; normalize(); return *this; @@ -45,7 +46,7 @@ public: operator int() const { return value; } // Stream output - friend std::ostream &operator<<(std::ostream &os, const Angle360 &a) { + friend std::ostream &operator<<(std::ostream &os, const Angle &a) { return os << a.value; } }; @@ -62,7 +63,7 @@ struct Entity { SDL_Texture *texture; SDL_Rect srcRect; float speed; - Angle360 angle = 0; + Angle angle = 0; basic_cords Central_position(std::optional x = std::nullopt, std::optional y = std::nullopt) {