mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-21 15:34:58 +01:00
Merge pull request #313 from miloszunio/pr/perspective-pan
feat(editor): the wheel held and dragged pans the perspective view too, the ground under the cursor going along with it
This commit is contained in:
@@ -4985,8 +4985,10 @@ void editor_mode::ortho_pan_to(double const Horizontal, double const Vertical)
|
|||||||
auto const dx{Horizontal - m_ortho_pan_cursor.x};
|
auto const dx{Horizontal - m_ortho_pan_cursor.x};
|
||||||
auto const dy{Vertical - m_ortho_pan_cursor.y};
|
auto const dy{Vertical - m_ortho_pan_cursor.y};
|
||||||
m_ortho_pan_cursor = {Horizontal, Vertical};
|
m_ortho_pan_cursor = {Horizontal, Vertical};
|
||||||
auto const scale{2.0 * static_cast<double>(Global.EditorOrthoExtent) / static_cast<double>(io.DisplaySize.y)};
|
auto const scale{Global.EditorOrtho ? 2.0 * static_cast<double>(Global.EditorOrthoExtent) / static_cast<double>(io.DisplaySize.y) : m_pan_metres};
|
||||||
auto const world{RotateY(glm::dvec3{dx * scale, 0.0, dy * scale}, static_cast<double>(Camera.Angle.y))};
|
// 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.x -= world.x;
|
||||||
Camera.Pos.z -= world.z;
|
Camera.Pos.z -= world.z;
|
||||||
Camera.Velocity = {};
|
Camera.Velocity = {};
|
||||||
@@ -5745,7 +5747,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
|
// 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);
|
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))
|
if (is_press(Action))
|
||||||
{
|
{
|
||||||
@@ -5753,6 +5755,17 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
|
|||||||
m_ortho_pan_cursor = m_input.mouse.position();
|
m_ortho_pan_cursor = m_input.mouse.position();
|
||||||
m_focus_active = false;
|
m_focus_active = false;
|
||||||
Camera.Velocity = {};
|
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 (GfxRenderer->Mouse_Hit() && 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))
|
else if (is_release(Action))
|
||||||
ortho_pan_stop();
|
ortho_pan_stop();
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ class editor_mode : public application_mode, private editor_track::observer
|
|||||||
double m_ortho_pitch{0.0};
|
double m_ortho_pitch{0.0};
|
||||||
bool m_ortho_pan{false};
|
bool m_ortho_pan{false};
|
||||||
glm::dvec2 m_ortho_pan_cursor{0.0};
|
glm::dvec2 m_ortho_pan_cursor{0.0};
|
||||||
|
double m_pan_metres{0.0}; // of the ground to a pixel, held by the panning in the perspective view
|
||||||
void ortho_pan_to(double const Horizontal, double const Vertical);
|
void ortho_pan_to(double const Horizontal, double const Vertical);
|
||||||
void ortho_pan_stop();
|
void ortho_pan_stop();
|
||||||
// camera fly-mode (right mouse button held); used to flush motion when it's released
|
// camera fly-mode (right mouse button held); used to flush motion when it's released
|
||||||
|
|||||||
Reference in New Issue
Block a user