From be78434a9c6d5db29f2b81ec324d1ab9e5fb77f5 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 21 Jan 2024 20:31:51 +0000 Subject: [PATCH] Player: Fix rotate Rotation wasn't handled properly at all. Properly bound between 0 and 360, and use a proper modulo for floats. Switch to float to have a more fluid rotation between frames. --- Player.cpp | 8 ++++---- Player.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Player.cpp b/Player.cpp index b23f8c5..4f2024d 100644 --- a/Player.cpp +++ b/Player.cpp @@ -14,14 +14,14 @@ void Player::move(float dx, float dy) y += dy; } -void Player::rotate(int alpha) +void Player::rotate(float alpha) { - orientation += alpha%360; - if(orientation >= 360) + orientation += fmodf(alpha, 360); + if(orientation > 360) { orientation -= 360; } - if(orientation <= 360) + else if(orientation < 0) { orientation += 360; } diff --git a/Player.h b/Player.h index 05426c5..fd9cf84 100644 --- a/Player.h +++ b/Player.h @@ -17,7 +17,7 @@ public: float fov = 70; void move(float dx, float dy); - void rotate(int alpha); + void rotate(float alpha); };