diff --git a/tools/editor/editor_app.cpp b/tools/editor/editor_app.cpp index 4b9630de..d542000c 100644 --- a/tools/editor/editor_app.cpp +++ b/tools/editor/editor_app.cpp @@ -206,6 +206,7 @@ void EditorApp::processEvents() { auto sc = event.key.keysym.scancode; if (sc == SDL_SCANCODE_F3) setWireframe(!isWireframe()); if (sc == SDL_SCANCODE_F5) saveBookmark(""); + if (sc == SDL_SCANCODE_HOME) centerOnTerrain(); // Number keys switch modes (when not typing in ImGui) if (!io.WantCaptureKeyboard) { if (sc == SDL_SCANCODE_1) setMode(EditorMode::Sculpt); @@ -788,6 +789,15 @@ void EditorApp::flyToSelected() { } } +void EditorApp::centerOnTerrain() { + if (!terrain_.isLoaded()) return; + float centerX = (32.0f - loadedTileY_) * 533.33333f - 8.0f * 533.33333f / 16.0f; + float centerY = (32.0f - loadedTileX_) * 533.33333f - 8.0f * 533.33333f / 16.0f; + camera_.setPosition(glm::vec3(centerX, centerY, terrain_.chunks[0].position[2] + 300.0f)); + camera_.setYawPitch(0.0f, -45.0f); + showToast("Camera centered on terrain"); +} + void EditorApp::snapSelectedToGround() { auto* sel = objectPlacer_.getSelected(); if (!sel || !terrain_.isLoaded()) return; diff --git a/tools/editor/editor_app.hpp b/tools/editor/editor_app.hpp index 3321c06a..9cf06874 100644 --- a/tools/editor/editor_app.hpp +++ b/tools/editor/editor_app.hpp @@ -73,6 +73,7 @@ public: void setSkyPreset(int preset); // 0=day, 1=dusk, 2=night void snapSelectedToGround(); void flyToSelected(); + void centerOnTerrain(); // Multi-tile support void addAdjacentTile(int offsetX, int offsetY); diff --git a/tools/editor/editor_ui.cpp b/tools/editor/editor_ui.cpp index 7d1d6719..619a5df2 100644 --- a/tools/editor/editor_ui.cpp +++ b/tools/editor/editor_ui.cpp @@ -148,6 +148,7 @@ void EditorUI::renderMenuBar(EditorApp& app) { bool wf = app.isWireframe(); if (ImGui::MenuItem("Wireframe", "F3", &wf)) app.setWireframe(wf); if (ImGui::MenuItem("Reset Camera")) app.resetCamera(); + if (ImGui::MenuItem("Center on Terrain", "Home")) app.centerOnTerrain(); ImGui::Separator(); if (ImGui::BeginMenu("Sky / Lighting")) { if (ImGui::MenuItem("Day")) app.setSkyPreset(0);