mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 22:44:59 +01:00
feat(editor): the wheel held and dragged pans the perspective view too, the ground under the cursor going along with it
Pressing the mouse wheel and dragging pans the top view; now it pans the perspective view as well. The camera moves over the ground, its height and its turn kept, by as much of the ground as the cursor crosses where it was pressed: metres to a pixel taken from the distance to what is under the cursor, and a pixel up the screen counted as more of the ground than one across as the camera looks down less steeply. With nothing under the cursor (the sky) it doesn't start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
This commit is contained in:
@@ -4978,8 +4978,10 @@ void editor_mode::ortho_pan_to(double const Horizontal, double const Vertical)
|
||||
auto const dx{Horizontal - m_ortho_pan_cursor.x};
|
||||
auto const dy{Vertical - m_ortho_pan_cursor.y};
|
||||
m_ortho_pan_cursor = {Horizontal, Vertical};
|
||||
auto const scale{2.0 * static_cast<double>(Global.EditorOrthoExtent) / static_cast<double>(io.DisplaySize.y)};
|
||||
auto const world{RotateY(glm::dvec3{dx * scale, 0.0, dy * scale}, static_cast<double>(Camera.Angle.y))};
|
||||
auto const scale{Global.EditorOrtho ? 2.0 * static_cast<double>(Global.EditorOrthoExtent) / static_cast<double>(io.DisplaySize.y) : m_pan_metres};
|
||||
// looked at from the side, a pixel up the screen is more of the ground than one across
|
||||
auto const along{Global.EditorOrtho ? 1.0 : 1.0 / std::max(0.25, std::abs(std::sin(static_cast<double>(Camera.Angle.x))))};
|
||||
auto const world{RotateY(glm::dvec3{dx * scale, 0.0, dy * scale * along}, static_cast<double>(Camera.Angle.y))};
|
||||
Camera.Pos.x -= world.x;
|
||||
Camera.Pos.z -= world.z;
|
||||
Camera.Velocity = {};
|
||||
@@ -5724,7 +5726,7 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
|
||||
// game-engine style look: hide & grab the cursor while flying, restore it on release
|
||||
Application.set_cursor(is_press(Action) ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
else if (Button == GLFW_MOUSE_BUTTON_MIDDLE && Global.EditorOrtho)
|
||||
else if (Button == GLFW_MOUSE_BUTTON_MIDDLE)
|
||||
{
|
||||
if (is_press(Action))
|
||||
{
|
||||
@@ -5732,6 +5734,17 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
|
||||
m_ortho_pan_cursor = m_input.mouse.position();
|
||||
m_focus_active = false;
|
||||
Camera.Velocity = {};
|
||||
// in the perspective view the ground under the cursor goes along with it: metres of it to a pixel there, as far as it is
|
||||
m_pan_metres = 0.0;
|
||||
if (false == Global.EditorOrtho)
|
||||
{
|
||||
auto const &io{ImGui::GetIO()};
|
||||
auto const distance{glm::length(GfxRenderer->Mouse_Position())};
|
||||
if (io.DisplaySize.y > 0.0f && distance > 0.5 && distance < 20000.0)
|
||||
m_pan_metres = 2.0 * distance * std::tan(glm::radians(Global.FieldOfView / Global.ZoomFactor) * 0.5) / static_cast<double>(io.DisplaySize.y);
|
||||
else
|
||||
m_ortho_pan = false; // nothing under the cursor to hold
|
||||
}
|
||||
}
|
||||
else if (is_release(Action))
|
||||
ortho_pan_stop();
|
||||
|
||||
Reference in New Issue
Block a user