diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-01 17:56:26 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-01 17:56:26 +0000 |
commit | d5cdbbf38380239524e351cb69aec94090884ca5 (patch) | |
tree | 5d7dff2f2775701069806eceb4eaef23b22eba3f /ui | |
parent | Reformat with new clang-format (diff) | |
parent | Remove more use of legacy types (diff) | |
download | ilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.bz2 ilt-d5cdbbf38380239524e351cb69aec94090884ca5.tar.xz ilt-d5cdbbf38380239524e351cb69aec94090884ca5.zip |
Merge remote-tracking branch 'origin/terrain'
Diffstat (limited to 'ui')
-rw-r--r-- | ui/builders/freeExtend.h | 2 | ||||
-rw-r--r-- | ui/builders/straight.cpp | 2 | ||||
-rw-r--r-- | ui/builders/straight.h | 4 | ||||
-rw-r--r-- | ui/editNetwork.h | 2 | ||||
-rw-r--r-- | ui/gameMainSelector.cpp | 11 | ||||
-rw-r--r-- | ui/gameMainSelector.h | 3 | ||||
-rw-r--r-- | ui/gameMainWindow.cpp | 4 | ||||
-rw-r--r-- | ui/manualCameraController.cpp | 8 | ||||
-rw-r--r-- | ui/manualCameraController.h | 6 | ||||
-rw-r--r-- | ui/window.h | 2 |
10 files changed, 23 insertions, 21 deletions
diff --git a/ui/builders/freeExtend.h b/ui/builders/freeExtend.h index 55fe7ff..b276426 100644 --- a/ui/builders/freeExtend.h +++ b/ui/builders/freeExtend.h @@ -9,5 +9,5 @@ class BuilderFreeExtend : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - std::optional<glm::vec3> p1; + std::optional<Position3D> p1; }; diff --git a/ui/builders/straight.cpp b/ui/builders/straight.cpp index 4fa9585..9b262bb 100644 --- a/ui/builders/straight.cpp +++ b/ui/builders/straight.cpp @@ -47,7 +47,7 @@ BuilderStraight::click(Network * network, const GeoData * geoData, const SDL_Mou } void -BuilderStraight::create(Network * network, glm::vec3 p1, glm::vec3 p2) const +BuilderStraight::create(Network * network, Position3D p1, Position3D p2) const { network->addStraight(p1, p2); } diff --git a/ui/builders/straight.h b/ui/builders/straight.h index 1cde2b0..cf99a1d 100644 --- a/ui/builders/straight.h +++ b/ui/builders/straight.h @@ -9,7 +9,7 @@ class BuilderStraight : public EditNetwork::Builder { void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override; void move(Network * network, const GeoData * geoData, const SDL_MouseMotionEvent & e, const Ray & ray) override; - void create(Network * network, glm::vec3 p1, glm::vec3 p2) const; + void create(Network * network, Position3D p1, Position3D p2) const; - std::optional<glm::vec3> p1; + std::optional<Position3D> p1; }; diff --git a/ui/editNetwork.h b/ui/editNetwork.h index eb1677e..e1aaa61 100644 --- a/ui/editNetwork.h +++ b/ui/editNetwork.h @@ -21,7 +21,7 @@ public: void render(const SceneShader &) const override; void render(const UIShader & shader, const UIComponent::Position & pos) const override; - using NetworkClickPos = std::variant<glm::vec3, Node::Ptr>; + using NetworkClickPos = std::variant<Position3D, Node::Ptr>; class Builder { public: diff --git a/ui/gameMainSelector.cpp b/ui/gameMainSelector.cpp index 6c6935c..a451ee1 100644 --- a/ui/gameMainSelector.cpp +++ b/ui/gameMainSelector.cpp @@ -8,15 +8,16 @@ #include <game/selectable.h> #include <game/worldobject.h> // IWYU pragma: keep #include <gfx/gl/camera.h> +#include <math.h> #include <optional> #include <span> #include <stream_support.h> #include <typeinfo> #include <vector> -GameMainSelector::GameMainSelector(const Camera * c, glm::vec2 size) : UIComponent {{{}, size}}, camera {c} { } +GameMainSelector::GameMainSelector(const Camera * c, ScreenAbsCoord size) : UIComponent {{{}, size}}, camera {c} { } -constexpr glm::vec2 TargetPos {5, 45}; +constexpr ScreenAbsCoord TargetPos {5, 45}; void GameMainSelector::render(const UIShader & shader, const Position & parentPos) const @@ -41,7 +42,7 @@ bool GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) { const auto getRay = [this](const auto & e) { - const auto mouse = glm::vec2 {e.x, e.y} / position.size; + const auto mouse = ScreenRelCoord {e.x, e.y} / position.size; return camera->unProject(mouse); }; if (target) { @@ -72,8 +73,8 @@ GameMainSelector::handleInput(const SDL_Event & e, const Position & parentPos) void GameMainSelector::defaultClick(const Ray & ray) { - glm::vec2 baryPos {}; - float distance; + Position2D baryPos {}; + float distance {}; if (const auto selected = gameState->world.applyOne<Selectable>(&Selectable::intersectRay, ray, &baryPos, &distance); diff --git a/ui/gameMainSelector.h b/ui/gameMainSelector.h index 98cdf53..88db34b 100644 --- a/ui/gameMainSelector.h +++ b/ui/gameMainSelector.h @@ -1,6 +1,7 @@ #pragma once #include "SDL_events.h" +#include "config/types.h" #include "special_members.h" #include "uiComponent.h" #include "worldOverlay.h" @@ -26,7 +27,7 @@ public: virtual void render(const SceneShader &) const; }; - GameMainSelector(const Camera * c, glm::vec2 size); + GameMainSelector(const Camera * c, ScreenAbsCoord size); void render(const UIShader & shader, const Position & pos) const override; void render(const SceneShader & shader) const override; diff --git a/ui/gameMainWindow.cpp b/ui/gameMainWindow.cpp index b94accd..d71c74a 100644 --- a/ui/gameMainWindow.cpp +++ b/ui/gameMainWindow.cpp @@ -31,8 +31,8 @@ public: GameMainWindow::GameMainWindow(size_t w, size_t h) : Window {w, h, "I Like Trains", SDL_WINDOW_OPENGL}, SceneRenderer {Window::size, 0} { - uiComponents.create<ManualCameraController>(glm::vec2 {-1150, -1150}); - auto gms = uiComponents.create<GameMainSelector>(&camera, glm::vec2 {w, h}); + uiComponents.create<ManualCameraController>(glm::vec2 {315'000'000, 495'000'000}); + auto gms = uiComponents.create<GameMainSelector>(&camera, ScreenAbsCoord {w, h}); uiComponents.create<GameMainToolbar>(gms.get()); } diff --git a/ui/manualCameraController.cpp b/ui/manualCameraController.cpp index 8e52b0e..ef26e81 100644 --- a/ui/manualCameraController.cpp +++ b/ui/manualCameraController.cpp @@ -59,12 +59,12 @@ ManualCameraController::handleInput(const SDL_Event & e, const Position &) pitch = std::clamp(pitch - 0.01F * static_cast<float>(e.motion.yrel), 0.1F, half_pi); } else { - focus += rotate_flat(-direction) * glm::vec2 {-e.motion.xrel, e.motion.yrel}; + focus += rotate_flat(-direction) * (Position2D {-e.motion.xrel, e.motion.yrel} * dist / 2.0F); } } return true; case SDL_MOUSEWHEEL: - dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 4.F, 5.F, 200.F); + dist = std::clamp(dist - static_cast<float>(e.wheel.y) * 400.F, 5.F, 200000.F); break; } return false; @@ -78,6 +78,6 @@ ManualCameraController::render(const UIShader &, const Position &) const void ManualCameraController::updateCamera(Camera * camera) const { - const auto forward = glm::normalize(sincosf(direction) ^ -sin(pitch)); - camera->setView(!focus - forward * 3.F * std::pow(dist, 1.3F), forward); + const auto forward = glm::normalize(sincosf(direction) || -sin(pitch)); + camera->setView((focus || 0.F) - forward * 3.F * std::pow(dist, 1.3F), forward); } diff --git a/ui/manualCameraController.h b/ui/manualCameraController.h index d15fa76..1efaee1 100644 --- a/ui/manualCameraController.h +++ b/ui/manualCameraController.h @@ -11,7 +11,7 @@ class Camera; class ManualCameraController : public CameraController, public UIComponent { public: - explicit ManualCameraController(glm::vec2 f) : UIComponent {{}}, focus {f} { } + explicit ManualCameraController(Position2D f) : UIComponent {{}}, focus {f} { } bool handleInput(const SDL_Event & e, const Position &) override; void render(const UIShader &, const Position & parentPos) const override; @@ -20,7 +20,7 @@ public: private: bool ctrl {false}, mrb {false}; - glm::vec2 focus; + Position2D focus; float direction {quarter_pi}; - float dist {40}, pitch {quarter_pi}; + float dist {4000}, pitch {quarter_pi}; }; diff --git a/ui/window.h b/ui/window.h index 183a65a..8f2b70b 100644 --- a/ui/window.h +++ b/ui/window.h @@ -36,7 +36,7 @@ protected: GLInitHelper(); }; - const glm::ivec2 size; + const ScreenAbsCoord size; SDL_WindowPtr m_window; SDL_GLContextPtr glContext; GLInitHelper glInithelper; |