feat(editor): scroll wheel zoom, clickable minimap navigation

- Scroll wheel now zooms camera (moves along look direction) instead
  of adjusting speed. Much more intuitive for terrain editing.
- Shift+scroll adjusts camera speed (old behavior preserved)
- Click on minimap to teleport camera to that location on the terrain
- Zoom speed scales with current camera speed for consistent feel
This commit is contained in:
Kelsi 2026-05-05 05:44:24 -07:00
parent f891bd02a5
commit 12acbfb2d5
4 changed files with 23 additions and 4 deletions

View file

@ -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);
}
}

View file

@ -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) {

View file

@ -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);

View file

@ -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;