From 4551850a6785b6f73da9d5a664e4d1c293655a6e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 3 Jan 2022 22:47:38 +0000 Subject: Display on what/where we clicked in the main window Just debug for now... never likely to last --- ui/gameMainWindow.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'ui') diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index 41bbb39..d53db4b 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -2,6 +2,8 @@ #include "gfx/camera_controller.h" #include "manualCameraController.h" #include "maths.h" +#include "ray.hpp" +#include "text.h" #include "toolbar.h" #include "ui/uiComponent.h" #include "window.h" @@ -9,12 +11,17 @@ #include #include #include +#include #include #include // IWYU pragma: keep #include #include #include -#include +#include +#include +#include +#include +#include class UIShader; @@ -31,13 +38,18 @@ public: } }; +#include + class GameMainSelector : public UIComponent { public: GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } void - render(const UIShader &, const Position &) const override + render(const UIShader & shader, const Position & pos) const override { + if (!clicked.empty()) { + Text {clicked, {{50, 10}, {0, 15}}, {1, 1, 0}}.render(shader, pos); + } } bool @@ -51,8 +63,24 @@ public: glm::vec2 baryPos {}; float eh; - std::ignore = gameState->world.applyOne( - &Selectable::intersectRay, camera->unProject(mouse), &baryPos, &eh); + const auto ray = camera->unProject(mouse); + if (const auto selected + = gameState->world.applyOne(&Selectable::intersectRay, ray, &baryPos, &eh); + selected != gameState->world.end()) { + const auto & ref = *selected.base()->get(); + clicked = typeid(ref).name(); + } + else { + try { + const auto dist = camera->pos.z / -ray.direction.z; + const auto pos = !camera->pos + (!ray.direction * dist); + + clicked = streamed_string(gameState->geoData->positionAt(pos)); + } + catch (std::range_error &) { + clicked.clear(); + } + } } } return false; @@ -60,6 +88,7 @@ public: private: const Camera * camera; + std::string clicked; }; GameMainWindow::GameMainWindow(size_t w, size_t h) : -- cgit v1.2.3