From c1becd9ae7e64acf047dba108099a4a8b72e1bbd Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sun, 1 Mar 2020 23:15:34 +0100 Subject: [PATCH] [DebugOverlay] Now displaying player direction and angle. --- client/source/hud/DebugOverlay.cpp | 5 +++++ client/source/world/ClientPlayer.cpp | 16 ++++++++++++++++ client/source/world/ClientPlayer.hpp | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/client/source/hud/DebugOverlay.cpp b/client/source/hud/DebugOverlay.cpp index 5ea523e73..19df495b7 100644 --- a/client/source/hud/DebugOverlay.cpp +++ b/client/source/hud/DebugOverlay.cpp @@ -48,6 +48,9 @@ void DebugOverlay::update() { s32 py = std::floor(m_player.y()); s32 pz = std::floor(m_player.z()); + const char *directions[5] = {"West", "East", "South", "North"}; + const char *direction = directions[m_player.getDirection()]; + std::stringstream stream; stream << "x: " << px << " | "; stream << "y: " << py << " | "; @@ -61,6 +64,8 @@ void DebugOverlay::update() { stream << "cy: " << (py & -CHUNK_DEPTH) / CHUNK_DEPTH << " | "; stream << "cz: " << (pz & -CHUNK_HEIGHT) / CHUNK_HEIGHT; stream << '\n'; + stream << "dir: " << direction << " (" << m_player.viewAngleH() << ")"; + stream << '\n'; stream << "Loaded chunks: " << m_world.loadedChunkCount(); m_positionText.setText(stream.str()); diff --git a/client/source/world/ClientPlayer.cpp b/client/source/world/ClientPlayer.cpp index 0a4cb3857..b685b0ba2 100644 --- a/client/source/world/ClientPlayer.cpp +++ b/client/source/world/ClientPlayer.cpp @@ -57,6 +57,7 @@ void ClientPlayer::turnH(double angle) { m_viewAngleH + angle : fmod(m_viewAngleH + angle, 360.); if (m_viewAngleH >= 180.) m_viewAngleH -= 360.; + if (m_viewAngleH <= -180.) m_viewAngleH += 360.; // FIXME: Temporary fix, needs review updateDir(); } @@ -67,6 +68,21 @@ void ClientPlayer::turnViewV(double angle) { updateDir(); } +u8 ClientPlayer::getDirection() const { + if (m_viewAngleH >= -45. && m_viewAngleH <= 45.) { + return West; + } + else if (m_viewAngleH >= -135. && m_viewAngleH <= -45.) { + return North; + } + else if (m_viewAngleH <= -135. || m_viewAngleH >= 135.) { + return East; + } + else { + return South; + } +} + void ClientPlayer::updateDir() { double ch = cos(m_viewAngleH * RADIANS_PER_DEGREES); double sh = sin(m_viewAngleH * RADIANS_PER_DEGREES); diff --git a/client/source/world/ClientPlayer.hpp b/client/source/world/ClientPlayer.hpp index 47d8877c0..d6bf90522 100644 --- a/client/source/world/ClientPlayer.hpp +++ b/client/source/world/ClientPlayer.hpp @@ -52,6 +52,10 @@ class ClientPlayer : public Player { void turnH(double angle); void turnViewV(double angle); + // West, East, South, North + u8 getDirection() const; + double viewAngleH() const { return m_viewAngleH; } + void move(double direction); void processInputs();