mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-31 16:59:06 +01:00
Put the editor viewport into a top-down orthographic plan view
Opening the Plan tool now switches the whole colour pass to an orthographic projection and pins the camera looking straight down, so the plan is drawn against the loaded scenery rather than in a window of its own. Closing the tool hands the camera's orientation back; leaving the editor clears the view outright. The wheel changes how much ground fits on screen instead of moving the camera, which with no perspective would change nothing but the clipping. Both configured backends follow: the experimental renderer swaps the pass projection (and fits its shadow cascades to it), the modern GL renderer uses its existing ortho helpers. Everything reading the pass projection - the mouse ray, the frustum test - picks the change up on its own. The experimental renderer also publishes its colour pass camera now, which it previously left at the interface defaults, so overlays can place world points on screen.
This commit is contained in:
@@ -1307,10 +1307,41 @@ void editor_mode::render_gizmo()
|
||||
}
|
||||
}
|
||||
|
||||
void editor_mode::on_scroll(double const Xoffset, double const Yoffset)
|
||||
{
|
||||
if (false == Global.editor_ortho)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// in the plan view the wheel decides how much ground fits on screen; the camera itself stays put,
|
||||
// because with no perspective its height changes nothing but the clipping
|
||||
Global.editor_ortho_extent = std::clamp(Global.editor_ortho_extent * std::pow(0.85f, static_cast<float>(Yoffset)), 5.0f, 20000.0f);
|
||||
}
|
||||
|
||||
void editor_mode::update_camera(double const Deltatime)
|
||||
{
|
||||
Camera.Update();
|
||||
|
||||
// the plan view looks straight down. the camera keeps its ground position, so panning works just
|
||||
// as it does in the perspective view, but the orientation is pinned and handed back on the way out
|
||||
if (Global.editor_ortho)
|
||||
{
|
||||
if (false == m_orthoactive)
|
||||
{
|
||||
m_orthoangle = Camera.Angle;
|
||||
m_orthoactive = true;
|
||||
}
|
||||
Camera.Angle.x = glm::radians(-90.0f);
|
||||
Camera.Angle.z = 0.0f;
|
||||
// high enough to clear anything the scenery may have under the cursor
|
||||
Camera.Pos.y = std::max(Camera.Pos.y, 500.0);
|
||||
}
|
||||
else if (m_orthoactive)
|
||||
{
|
||||
Camera.Angle = m_orthoangle;
|
||||
m_orthoactive = false;
|
||||
}
|
||||
|
||||
// focus animation runs after Camera.Update() so it overrides any residual velocity/rotation;
|
||||
// it smoothly drives both position and orientation toward the framed object
|
||||
if (m_focus_active)
|
||||
@@ -1391,6 +1422,7 @@ void editor_mode::enter()
|
||||
void editor_mode::exit()
|
||||
{
|
||||
EditorModeFlag = false;
|
||||
Global.editor_ortho = false; // the plan view must not follow us out of the editor
|
||||
Global.ControlPicking = m_statebackup.picking;
|
||||
FreeFlyModeFlag = m_statebackup.freefly;
|
||||
Global.pCamera = m_statebackup.camera;
|
||||
|
||||
@@ -39,10 +39,7 @@ class editor_mode : public application_mode
|
||||
void on_key(int Key, int Scancode, int Action, int Mods) override;
|
||||
void on_cursor_pos(double Horizontal, double Vertical) override;
|
||||
void on_mouse_button(int Button, int Action, int Mods) override;
|
||||
void on_scroll(double const Xoffset, double const Yoffset) override
|
||||
{
|
||||
;
|
||||
}
|
||||
void on_scroll(double const Xoffset, double const Yoffset) override;
|
||||
void on_window_resize(int w, int h) override
|
||||
{
|
||||
;
|
||||
@@ -108,6 +105,10 @@ class editor_mode : public application_mode
|
||||
editormode_input m_input;
|
||||
static TCamera Camera;
|
||||
|
||||
// camera orientation from before the plan view took over, to be handed back when it is left
|
||||
bool m_orthoactive{false};
|
||||
glm::vec3 m_orthoangle{0.0f};
|
||||
|
||||
// focus (smooth camera fly-to) state
|
||||
static bool m_focus_active;
|
||||
glm::dvec3 m_focus_start_pos{0.0,0.0,0.0};
|
||||
|
||||
@@ -83,8 +83,19 @@ plan_panel::plan_panel(std::string const &Name, bool const Isopen) : ui_panel(Na
|
||||
solve();
|
||||
}
|
||||
|
||||
void plan_panel::update()
|
||||
{
|
||||
// the plan belongs on the scenery itself, so opening the tool puts the viewport into the
|
||||
// distortion-free view from above and closing it hands the camera back
|
||||
Global.editor_ortho = is_open;
|
||||
}
|
||||
|
||||
void plan_panel::render_contents()
|
||||
{
|
||||
ImGui::Text("view: top-down, %.0f m across", Global.editor_ortho_extent * 2.0f);
|
||||
ImGui::SameLine();
|
||||
ImGui::TextDisabled("(wheel over the scenery zooms it)");
|
||||
|
||||
render_toolbar();
|
||||
render_canvas();
|
||||
render_gaps();
|
||||
|
||||
@@ -24,6 +24,7 @@ class plan_panel : public ui_panel
|
||||
public:
|
||||
plan_panel(std::string const &Name, bool const Isopen);
|
||||
|
||||
void update() override;
|
||||
void render_contents() override;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user