From a1f911f8257f614f874c201fede5d5206f5b7e80 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 3 Aug 2015 18:40:03 +0200 Subject: [PATCH] show camera position in debug overlay --- src/ui/Interface.hpp | 4 +++- src/ui/ui.cpp | 22 ++++++++++++++++++++-- src/world/Entity.hpp | 4 ++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/ui/Interface.hpp b/src/ui/Interface.hpp index eaed0fc..1ade2d1 100644 --- a/src/ui/Interface.hpp +++ b/src/ui/Interface.hpp @@ -69,8 +69,9 @@ public: void ToggleAudio(); void ToggleVisual(); - void ToggleCounter(); + void ToggleDebug(); void UpdateCounter(); + void UpdatePosition(); void PostMessage(const char *); void PostMessage(const std::string &msg) { @@ -101,6 +102,7 @@ private: glm::mat4 outline_transform; FixedText counter_text; + FixedText position_text; MessageBox messages; IntervalTimer msg_timer; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 198defb..6fa7356 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -124,6 +124,10 @@ Interface::Interface( 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 + font.LineSkip(), 0.0f), Gravity::NORTH_EAST); + position_text.Foreground(glm::vec4(1.0f)); + position_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)); @@ -182,7 +186,7 @@ void Interface::HandlePress(const SDL_KeyboardEvent &event) { ToggleVisual(); break; case SDLK_F3: - ToggleCounter(); + ToggleDebug(); break; case SDLK_F4: ToggleAudio(); @@ -338,10 +342,12 @@ void Interface::ToggleVisual() { } } -void Interface::ToggleCounter() { +void Interface::ToggleDebug() { counter_text.Toggle(); + position_text.Toggle(); if (counter_text.Visible()) { UpdateCounter(); + UpdatePosition(); } } @@ -354,6 +360,12 @@ void Interface::UpdateCounter() { counter_text.Set(font, text); } +void Interface::UpdatePosition() { + std::stringstream s; + s << std::setprecision(3) << "pos: " << ctrl.Controlled().AbsolutePosition(); + position_text.Set(font, s.str()); +} + void Interface::Handle(const SDL_MouseMotionEvent &event) { if (config.mouse_disabled) return; @@ -487,6 +499,9 @@ void Interface::Update(int dt) { if (counter_text.Visible() && counter.Changed()) { UpdateCounter(); } + if (position_text.Visible()) { + UpdatePosition(); + } } namespace { @@ -522,6 +537,9 @@ void Interface::Render(Viewport &viewport) noexcept { if (counter_text.Visible()) { counter_text.Render(viewport); } + if (position_text.Visible()) { + position_text.Render(viewport); + } if (msg_timer.Running()) { messages.Render(viewport); diff --git a/src/world/Entity.hpp b/src/world/Entity.hpp index a5723f4..05d795f 100644 --- a/src/world/Entity.hpp +++ b/src/world/Entity.hpp @@ -43,6 +43,10 @@ public: const Chunk::Pos ChunkCoords() const noexcept { return chunk; } + glm::vec3 AbsolutePosition() const noexcept { + return glm::vec3(chunk * Chunk::Extent()) + position; + } + const glm::quat &AngularVelocity() const noexcept { return angular_velocity; } void AngularVelocity(const glm::quat &) noexcept; -- 2.39.2