From 5e8eee742138f2578e83e710ffc41408abd3073f Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 13 Aug 2015 18:30:13 +0200 Subject: [PATCH] show player orientation in debug overlay --- src/model/geometry.hpp | 12 ++++++++++++ src/ui/Interface.hpp | 4 ++++ src/ui/ui.cpp | 37 ++++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/model/geometry.hpp b/src/model/geometry.hpp index df45fff..f1b3762 100644 --- a/src/model/geometry.hpp +++ b/src/model/geometry.hpp @@ -13,6 +13,18 @@ constexpr float PI_0p5 = PI * 0.5f; constexpr float PI_1p5 = PI * 1.5f; constexpr float PI_2p0 = PI * 2.0f; +constexpr float DEG_RAD_FACTOR = PI / 180.0f; +constexpr float RAD_DEG_FACTOR = 180.0f / PI; + +constexpr float deg2rad(float d) { + return d * DEG_RAD_FACTOR; +} + +constexpr float rad2deg(float r) { + return r * RAD_DEG_FACTOR; +} + + struct AABB { glm::vec3 min; glm::vec3 max; diff --git a/src/ui/Interface.hpp b/src/ui/Interface.hpp index 0cffd76..d045cc9 100644 --- a/src/ui/Interface.hpp +++ b/src/ui/Interface.hpp @@ -70,6 +70,7 @@ public: void ToggleDebug(); void UpdateCounter(); void UpdatePosition(); + void UpdateOrientation(); void PostMessage(const char *); void PostMessage(const std::string &msg) { @@ -99,6 +100,7 @@ private: FixedText counter_text; FixedText position_text; + FixedText orientation_text; MessageBox messages; IntervalTimer msg_timer; @@ -115,6 +117,8 @@ private: glm::ivec3 fwd, rev; + bool debug; + }; } diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index f9836ba..6dfe516 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -107,6 +107,8 @@ Interface::Interface( , outline() , outline_transform(1.0f) , counter_text() +, position_text() +, orientation_text() , messages(env.assets.small_ui_font) , msg_timer(5000) , config(config) @@ -117,15 +119,17 @@ Interface::Interface( , place_sound(env.assets.LoadSound("thump")) , remove_sound(env.assets.LoadSound("plop")) , fwd(0) -, rev(0) { - counter_text.Hide(); +, rev(0) +, debug(false) { counter_text.Position(glm::vec3(-25.0f, 25.0f, 0.0f), Gravity::NORTH_EAST); counter_text.Foreground(glm::vec4(1.0f)); counter_text.Background(glm::vec4(0.5f)); - position_text.Hide(); position_text.Position(glm::vec3(-25.0f, 25.0f + env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); position_text.Foreground(glm::vec4(1.0f)); position_text.Background(glm::vec4(0.5f)); + orientation_text.Position(glm::vec3(-25.0f, 25.0f + 2 * env.assets.small_ui_font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + orientation_text.Foreground(glm::vec4(1.0f)); + orientation_text.Background(glm::vec4(0.5f)); messages.Position(glm::vec3(25.0f, -25.0f, 0.0f), Gravity::SOUTH_WEST); messages.Foreground(glm::vec4(1.0f)); messages.Background(glm::vec4(0.5f)); @@ -341,11 +345,11 @@ void Interface::ToggleVisual() { } void Interface::ToggleDebug() { - counter_text.Toggle(); - position_text.Toggle(); - if (counter_text.Visible()) { + debug = !debug; + if (debug) { UpdateCounter(); UpdatePosition(); + UpdateOrientation(); } } @@ -364,6 +368,13 @@ void Interface::UpdatePosition() { position_text.Set(env.assets.small_ui_font, s.str()); } +void Interface::UpdateOrientation() { + std::stringstream s; + s << std::setprecision(3) << "pitch: " << rad2deg(ctrl.Pitch()) + << ", yaw: " << rad2deg(ctrl.Yaw()); + orientation_text.Set(env.assets.small_ui_font, s.str()); +} + void Interface::Handle(const SDL_MouseMotionEvent &event) { if (config.mouse_disabled) return; @@ -492,11 +503,12 @@ void Interface::Update(int dt) { CheckAim(); } - if (counter_text.Visible() && env.counter.Changed()) { - UpdateCounter(); - } - if (position_text.Visible()) { + if (debug) { + if (env.counter.Changed()) { + UpdateCounter(); + } UpdatePosition(); + UpdateOrientation(); } } @@ -530,11 +542,10 @@ void Interface::Render(Viewport &viewport) noexcept { outline.Draw(); } - if (counter_text.Visible()) { + if (debug) { counter_text.Render(viewport); - } - if (position_text.Visible()) { position_text.Render(viewport); + orientation_text.Render(viewport); } if (msg_timer.Running()) { -- 2.39.2