diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index 1b7c0464..4b9630de 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -382,7 +382,7 @@ void EditorApp::processEvents() { } if (event.type == SDL_MOUSEWHEEL && !io.WantCaptureMouse) - camera_.processMouseWheel(event.wheel.y); + camera_.processMouseWheel(event.wheel.y, (SDL_GetModState() & KMOD_SHIFT) != 0); } } diff --git a/tools/editor/editor_camera.cpp b/tools/editor/editor_camera.cpp index 2a1aeeca..5a8badbe 100644 --- a/tools/editor/editor_camera.cpp +++ b/tools/editor/editor_camera.cpp @@ -43,8 +43,14 @@ void EditorCamera::processMouseMotion(int dx, int dy) { camera_.setRotation(yaw_, pitch_); } -void EditorCamera::processMouseWheel(float delta) { - speed_ = std::clamp(speed_ + delta * 20.0f, 10.0f, 2000.0f); +void EditorCamera::processMouseWheel(float delta, bool shiftHeld) { + if (shiftHeld) { + speed_ = std::clamp(speed_ + delta * 20.0f, 10.0f, 2000.0f); + } else { + glm::vec3 pos = camera_.getPosition(); + pos += camera_.getForward() * delta * speed_ * 0.3f; + camera_.setPosition(pos); + } } void EditorCamera::processKeyEvent(const SDL_KeyboardEvent& event) { diff --git a/tools/editor/editor_camera.hpp b/tools/editor/editor_camera.hpp index 23d33c1f..926c1fb3 100644 --- a/tools/editor/editor_camera.hpp +++ b/tools/editor/editor_camera.hpp @@ -13,7 +13,7 @@ public: void update(float deltaTime); void processMouseMotion(int dx, int dy); - void processMouseWheel(float delta); + void processMouseWheel(float delta, bool shiftHeld); void processKeyEvent(const SDL_KeyboardEvent& event); void processMouseButton(const SDL_MouseButtonEvent& event); diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index 5ef50197..414fe13e 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -1134,6 +1134,19 @@ void EditorUI::renderMinimap(EditorApp& app) { } ImGui::Dummy(ImVec2(avail.x, 16 * cellH)); + // Click minimap to move camera + if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(0)) { + ImVec2 mousePos = ImGui::GetMousePos(); + float mu = (mousePos.y - origin.y) / (16 * cellH); + float mv = (mousePos.x - origin.x) / avail.x; + if (mu >= 0 && mu <= 1 && mv >= 0 && mv <= 1) { + float wx = tileNW_X - mu * 533.33333f; + float wy = tileNW_Y - mv * 533.33333f; + app.getEditorCamera().setPosition(glm::vec3(wx, wy, + app.getEditorCamera().getCamera().getPosition().z)); + } + } + // Camera indicator as white cross auto camPos = app.getEditorCamera().getCamera().getPosition(); float camU = (tileNW_X - camPos.x) / 533.33333f;