17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 05:09:20 +02:00

refactor(editor): one place for the orthographic projection of the editor view

This commit is contained in:
maj00r
2026-10-04 00:52:14 +02:00
parent 7d87fef7a0
commit fc195880e1
2 changed files with 14 additions and 14 deletions

View File

@@ -1518,6 +1518,17 @@ glm::mat4 opengl33_renderer::ortho_frustumtest_projection(float l, float r, floa
return glm::ortho(l, r, b, t, znear, zfar); return glm::ortho(l, r, b, t, znear, zfar);
} }
// the main viewport of the editor in the orthographic view replaces the perspective projection
void opengl33_renderer::editor_ortho_projection(viewport_config const &Viewport, float const Zfar, glm::mat4 &Projection, glm::mat4 &Frustum)
{
if (false == (EditorModeFlag && Global.EditorOrtho && Viewport.main))
return;
auto const height{Global.EditorOrthoExtent};
auto const width{height * Global.window_size.x / std::max(1.f, static_cast<float>(Global.window_size.y))};
Projection = ortho_projection(-width, width, -height, height, -Zfar, Zfar);
Frustum = ortho_frustumtest_projection(-width, width, -height, height, -Zfar, Zfar);
}
void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config &Config, rendermode const Mode, void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config &Config, rendermode const Mode,
float const Znear, float const Zfar, bool const Ignoredebug) float const Znear, float const Zfar, bool const Ignoredebug)
{ {
@@ -1593,13 +1604,7 @@ void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config
auto const znear = ( Znear > 1.f ? Znear : Znear > 0.f ? Znear * zfar : 0.1f * Global.ZoomFactor); auto const znear = ( Znear > 1.f ? Znear : Znear > 0.f ? Znear * zfar : 0.1f * Global.ZoomFactor);
camera.projection() = perspective_projection(Viewport.projection, znear, zfar, frustumtest_proj); camera.projection() = perspective_projection(Viewport.projection, znear, zfar, frustumtest_proj);
if (EditorModeFlag && Global.EditorOrtho && Viewport.main) editor_ortho_projection(Viewport, zfar, camera.projection(), frustumtest_proj);
{
auto const height{Global.EditorOrthoExtent};
auto const width{height * Global.window_size.x / std::max(1.f, static_cast<float>(Global.window_size.y))};
camera.projection() = ortho_projection(-width, width, -height, height, -zfar, zfar);
frustumtest_proj = ortho_frustumtest_projection(-width, width, -height, height, -zfar, zfar);
}
break; break;
} }
case rendermode::shadows: case rendermode::shadows:
@@ -1699,13 +1704,7 @@ void opengl33_renderer::setup_pass(viewport_config &Viewport, renderpass_config
} }
camera.projection() = perspective_projection(proj, znear, zfar, frustumtest_proj); camera.projection() = perspective_projection(proj, znear, zfar, frustumtest_proj);
if (EditorModeFlag && Global.EditorOrtho && Viewport.main) editor_ortho_projection(Viewport, zfar, camera.projection(), frustumtest_proj);
{
auto const height{Global.EditorOrthoExtent};
auto const width{height * Global.window_size.x / std::max(1.f, static_cast<float>(Global.window_size.y))};
camera.projection() = ortho_projection(-width, width, -height, height, -zfar, zfar);
frustumtest_proj = ortho_frustumtest_projection(-width, width, -height, height, -zfar, zfar);
}
break; break;
} }
case rendermode::reflections: case rendermode::reflections:

View File

@@ -399,6 +399,7 @@ class opengl33_renderer : public gfx_renderer {
glm::mat4 perspective_projection(const viewport_proj_config &c, float n, float f, glm::mat4 &frustum); glm::mat4 perspective_projection(const viewport_proj_config &c, float n, float f, glm::mat4 &frustum);
glm::mat4 ortho_projection(float left, float right, float bottom, float top, float z_near, float z_far); glm::mat4 ortho_projection(float left, float right, float bottom, float top, float z_near, float z_far);
glm::mat4 ortho_frustumtest_projection(float left, float right, float bottom, float top, float z_near, float z_far); glm::mat4 ortho_frustumtest_projection(float left, float right, float bottom, float top, float z_near, float z_far);
void editor_ortho_projection(viewport_config const &Viewport, float const Zfar, glm::mat4 &Projection, glm::mat4 &Frustum);
std::vector<std::function<void(TSubModel const *, glm::vec2)>> m_control_pick_requests; std::vector<std::function<void(TSubModel const *, glm::vec2)>> m_control_pick_requests;
std::vector<std::function<void(scene::basic_node *)>> m_node_pick_requests; std::vector<std::function<void(scene::basic_node *)>> m_node_pick_requests;