18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-21 07:24:57 +01:00

feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu (#312)

* feat(editor): ~ shows or hides the orthophoto, Ctrl+~ downloads what the camera sees first; the speed of the camera in the View menu

~ (the key left of 1) turns the orthophoto on and off. Ctrl+~ finds what of the ground the camera sees (rays through a grid
over the screen down to the level of the ground under the camera, or as far as 2.5 km where they don't come down to it) and
puts those tiles at the front of the queue of the downloads, the ones which failed tried again at once; the status line
tells how many. Tab is not used, the laying and the switches have it.

View > Camera speed: the speed of the free camera of the editor (x0.05 to x10, 1 as it was), how many times faster Ctrl makes
it (1 to 30, 30 as it was), and in the top view as fast as the view is zoomed, so the map crosses the screen at the same pace
zoomed in or out. Kept in the settings of the editor; the camera of the cab and of the free fly outside the editor unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): Ctrl+~ in the top view, over a scenery with no terrain under the camera and with the orthophoto off; "As it was" without the speed going with the zoom

In the top view the box is the view itself, its corners on the ground. The ground under the camera is the terrain, else the
scenery, else the rays go as far as the reach. The tile of the camera is taken anew by hurry(), it isn't followed while the
layer is off. The top view is as fast zoomed in as out by default, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): the corners of the top view on the ground put where the camera is (the view matrix is camera-relative)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* i18n(editor): Polish for the orthophoto keys and the camera speed, on top of the master's own translations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ

* fix(editor): Ctrl+~ asks only for the tiles update() would ask for; the tooltip of "Track colours" back in its place

After the reviews of #312:
- hurry() skips the tiles outside the download area set and marks the ones outside the area the service covers
  as empty, as update() does, so Ctrl+~ no longer queues downloads update() drops at once (and the workers took
  anyway, into the disk cache, against the area set), nor requests the service can't answer.
- A blank tile hurried takes the standard image first, as in update(); first_level() and outside_area() are
  shared by both loops, and the body of the loop of hurry() is hurry_tile().
- orthophoto_hurry() takes the level of the terrain only when it's below the camera, as the branch of the
  scenery already did: a camera under the terrain (a tunnel, under the heightmap) no longer flips the box of
  the view behind it.
- The "Camera speed" menu goes after the tooltip of "Track colours", which it had taken.
- #include <set> once in editorOrthophoto.hpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRgQ1K1Qu7TCsa74zsNURd

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
pol102
2026-11-20 03:55:34 +01:00
committed by GitHub
parent 7524cfbcc2
commit 6c94f9743b
9 changed files with 317 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
#include <iterator>
#include <fstream>
#include <regex>
#include <optional>
#include "application/editormode.h"
#include "application/editormodeshared.h"
#include "application/editorgestures.h"
@@ -4258,6 +4259,11 @@ void editor_mode::render_view_menu()
}
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("The tracks of the track mode coloured by their radius, speed or grade, with the legend in the corner"));
if (ImGui::BeginMenu(STR_C("Camera speed")))
{
render_camera_settings();
ImGui::EndMenu();
}
ImGui::MenuItem(STR_C("Track labels in the top view"), nullptr, &m_track_labels);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("Zoomed in from above, the curves get their radius and length and the switches their name and type, as on a plan; where they'd crowd, some are left out"));
@@ -6989,6 +6995,8 @@ void editor_mode::enter()
simulation::Blackbox.close();
// the cursor drawn into the picture is the editor's: back on when it comes back, if it was chosen
ui_layer::draw_cursor(m_draw_cursor);
apply_camera_settings();
Global.EditorCameraOn = true;
if (simulation::Region != nullptr)
{
@@ -7090,6 +7098,7 @@ void editor_mode::exit()
track_sleepers::lay_in_background(true);
// the driver's view has no menu to switch the drawn cursor off: the system one there
ui_layer::draw_cursor(false);
Global.EditorCameraOn = false;
Global.editor_tracks = false;
EditorModeFlag = false;
Global.ControlPicking = m_statebackup.picking;
@@ -7489,6 +7498,22 @@ void editor_mode::on_key(int const Key, int const Scancode, int const Action, in
lay_switch_mode();
break;
case GLFW_KEY_GRAVE_ACCENT:
// ~ (left of 1): the orthophoto shown or hidden; with Ctrl what the camera sees downloaded before anything else
if (false == is_press(Action) || ImGui::GetIO().WantTextInput)
break;
if (Mods & GLFW_MOD_CONTROL)
{
orthophoto_hurry();
break;
}
if (false == anyModifier)
{
m_orthophoto.enabled(false == m_orthophoto.enabled());
ui()->set_status(m_orthophoto.enabled() ? STR("Orthophoto on (~)") : STR("Orthophoto off (~)"));
}
break;
case GLFW_KEY_BACKSPACE:
// the switch being clicked off the view: the last point taken back
if (m_switch_designer.open && m_switch_designer.picking)
@@ -8094,3 +8119,113 @@ void editor_mode::render_top_tracks_choice(bool const Combo)
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("The colour of the rails, to stand out on the imagery and the map"));
}
void editor_mode::apply_camera_settings()
{
auto const &camera{EditorSettings.camera()};
Global.EditorCameraSpeed = camera.speed;
Global.EditorCameraFast = camera.fast;
Global.EditorCameraZoomed = camera.zoomed;
}
void editor_mode::render_camera_settings()
{
auto &camera{EditorSettings.camera()};
auto changed{false};
auto release{false};
ImGui::PushItemWidth(180.0f * Global.ui_scale);
auto speed{static_cast<float>(camera.speed)};
if (ImGui::SliderFloat(STR_C("Speed of the camera"), &speed, 0.05f, 10.0f, "x %.2f", ImGuiSliderFlags_Logarithmic))
{
camera.speed = speed;
changed = true;
}
release |= ImGui::IsItemDeactivatedAfterEdit();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("How fast the arrows or WSAD move the camera, Shift a bit faster; 1 as it was"));
auto fast{static_cast<float>(camera.fast)};
if (ImGui::SliderFloat(STR_C("Ctrl speeds it up"), &fast, 1.0f, 30.0f, "x %.1f", ImGuiSliderFlags_Logarithmic))
{
camera.fast = fast;
changed = true;
}
release |= ImGui::IsItemDeactivatedAfterEdit();
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("How many times faster the camera goes with Ctrl held, Ctrl+Shift too; 30 as it was"));
ImGui::PopItemWidth();
if (ImGui::Checkbox(STR_C("In the top view as fast as the view is zoomed"), &camera.zoomed))
changed = release = true;
if (ImGui::IsItemHovered())
ImGui::SetTooltip("%s", STR_C("Zoomed in the map moves slowly, zoomed out fast: across the screen at the same pace whatever the zoom"));
ImGui::Separator();
if (ImGui::MenuItem(STR_C("As it was")))
{
camera = {};
changed = release = true;
}
if (changed)
apply_camera_settings();
if (release)
EditorSettings.save();
}
void editor_mode::orthophoto_hurry()
{
if (false == m_orthophoto.enabled())
m_orthophoto.enabled(true);
// what the camera sees of the ground: rays through a grid over the screen to the level of the ground under the camera, or as far
// as the reach of the orthophoto along it where they don't come down to it (the sky)
ImGuiIO const &io = ImGui::GetIO();
if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f)
return;
auto const inverse = glm::inverse(editor_mode::projection_matrix(io.DisplaySize.x / io.DisplaySize.y) * GfxRenderer->Camera_View_Matrix());
auto const camera{GfxRenderer->Camera_Position()};
// the level of the ground under the camera: the terrain, else the scenery; with neither the rays go as far as the reach
std::optional<double> level;
// only a level below the camera: one above it (in a tunnel, or flown under the terrain) would put the hits behind it
if (double ground{0.0}; m_streamer.active() && m_streamer.height_at(camera.x, camera.z, ground) && ground < camera.y)
level = ground;
else if (std::vector<char> found; Global.EditorOrtho == false)
{
auto const heights{ground_heights({camera}, true, &found)};
if (false == found.empty() && found.front() != 0 && heights.front() < camera.y)
level = heights.front();
}
double constexpr reach{2500.0};
glm::dvec2 low{camera.x, camera.z};
glm::dvec2 high{camera.x, camera.z};
for (int j = 0; j <= 6; ++j)
for (int i = 0; i <= 6; ++i)
{
glm::vec2 const ndc{static_cast<float>(i) / 3.0f - 1.0f, static_cast<float>(j) / 3.0f - 1.0f};
auto const point = [&inverse, &ndc](float const Depth) {
auto const clip = inverse * glm::vec4(ndc, Depth, 1.0f);
return glm::dvec3{glm::vec3{clip} / clip.w};
};
if (Global.EditorOrtho)
{
// the view straight down: the corners of the screen are where it reaches on the ground
auto const corner{camera + point(0.0f)}; // the view matrix is camera-relative
low = glm::min(low, glm::dvec2{corner.x, corner.z});
high = glm::max(high, glm::dvec2{corner.x, corner.z});
continue;
}
auto direction = point(0.5f) - point(0.0f);
if (glm::length(direction) < 1e-9)
continue;
direction = glm::normalize(direction);
glm::dvec2 flat{direction.x, direction.z};
auto distance{reach};
if (level && direction.y < -1e-6)
distance = std::min(reach, (camera.y - *level) / -direction.y * glm::length(flat));
if (glm::length(flat) < 1e-6)
continue;
flat = glm::normalize(flat) * distance;
glm::dvec2 const hit{camera.x + flat.x, camera.z + flat.y};
low = glm::min(low, hit);
high = glm::max(high, hit);
}
auto const count{m_orthophoto.hurry(low, high, camera)};
ui()->set_status(count > 0 ? format(STR_C("Orthophoto: %zu tiles of the view downloaded first (Ctrl+~)"), count)
: std::string{STR("Orthophoto: the view is all shown already (Ctrl+~)")});
}