From b8f53c4582ef5fb5192a06f9232cc76248b1327f Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 29 Jan 2020 20:12:49 +0700 Subject: [PATCH] camera modes for viewports --- .../enduro2d/high/systems/camera_system.cpp | 30 ++++++++++--------- .../enduro2d/high/systems/render_system.cpp | 3 +- .../render_system_drawer.cpp | 1 - .../render_system_drawer.hpp | 7 ++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/sources/enduro2d/high/systems/camera_system.cpp b/sources/enduro2d/high/systems/camera_system.cpp index 12ceebb6..c5f74e52 100644 --- a/sources/enduro2d/high/systems/camera_system.cpp +++ b/sources/enduro2d/high/systems/camera_system.cpp @@ -25,19 +25,21 @@ namespace camera.zfar(), camera.znear() + math::default_precision()); - const v2f target_size = camera.target() - ? camera.target()->size().cast_to() - : window.real_size().cast_to(); - const v2f virtual_size = window.virtual_size().cast_to(); + const v2u target_size = camera.target() + ? camera.target()->size() + : window.real_size(); - if ( math::is_near_zero(math::length_squared(target_size), 0.f) || - math::is_near_zero(math::length_squared(virtual_size), 0.f) ) + const v2f virtual_size = window.virtual_size().cast_to(); + const v2f viewport_size = target_size.cast_to() * camera.viewport().size; + + if ( math::is_near_zero(math::length_squared(virtual_size), 0.f) || + math::is_near_zero(math::length_squared(viewport_size), 0.f) ) { return camera.projection(); } - const f32 target_aspect = target_size.x / target_size.y; const f32 virtual_aspect = virtual_size.x / virtual_size.y; + const f32 viewport_aspect = viewport_size.x / viewport_size.y; switch ( camera.mode() ) { case camera::modes::manual: @@ -49,21 +51,21 @@ namespace ortho_zfar); case camera::modes::flexible: return math::make_orthographic_lh_matrix4( - target_size, + viewport_size, ortho_znear, ortho_zfar); case camera::modes::fixed_fit: return math::make_orthographic_lh_matrix4( - target_aspect < virtual_aspect - ? v2f(virtual_size.x, virtual_size.y * (virtual_aspect / target_aspect)) - : v2f(virtual_size.x * (target_aspect / virtual_aspect), virtual_size.y), + viewport_aspect < virtual_aspect + ? v2f(virtual_size.x, virtual_size.y * (virtual_aspect / viewport_aspect)) + : v2f(virtual_size.x * (viewport_aspect / virtual_aspect), virtual_size.y), ortho_znear, ortho_zfar); case camera::modes::fixed_crop: return math::make_orthographic_lh_matrix4( - virtual_aspect < target_aspect - ? v2f(virtual_size.x, virtual_size.y * (virtual_aspect / target_aspect)) - : v2f(virtual_size.x * (target_aspect / virtual_aspect), virtual_size.y), + virtual_aspect < viewport_aspect + ? v2f(virtual_size.x, virtual_size.y * (virtual_aspect / viewport_aspect)) + : v2f(virtual_size.x * (viewport_aspect / virtual_aspect), virtual_size.y), ortho_znear, ortho_zfar); default: diff --git a/sources/enduro2d/high/systems/render_system.cpp b/sources/enduro2d/high/systems/render_system.cpp index 0c57c0ce..06f43843 100644 --- a/sources/enduro2d/high/systems/render_system.cpp +++ b/sources/enduro2d/high/systems/render_system.cpp @@ -56,12 +56,11 @@ namespace e2d ~internal_state() noexcept = default; void process_render(const ecs::const_entity& cam_e, ecs::registry& owner) { - if ( !cam_e.valid() || !ecs::exists_all()(cam_e) ) { + if ( !cam_e.valid() || !cam_e.exists_component() ) { return; } drawer_.with( cam_e.get_component(), - cam_e.get_component().node(), [&owner](drawer::context& ctx){ for_all_scenes(ctx, owner); }); diff --git a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp index f4e48ab6..52543879 100644 --- a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp +++ b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.cpp @@ -42,7 +42,6 @@ namespace e2d::render_system_impl drawer::context::context( const camera& cam, - const const_node_iptr& cam_n, engine& engine, render& render, window& window, diff --git a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.hpp b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.hpp index 6c00c6d2..d3b50b03 100644 --- a/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.hpp +++ b/sources/enduro2d/high/systems/render_system_impl/render_system_drawer.hpp @@ -33,7 +33,6 @@ namespace e2d::render_system_impl public: context( const camera& cam, - const const_node_iptr& cam_n, engine& engine, render& render, window& window, @@ -66,7 +65,7 @@ namespace e2d::render_system_impl drawer(engine& e, debug& d, render& r, window& w); template < typename F > - void with(const camera& cam, const const_node_iptr& cam_n, F&& f); + void with(const camera& cam, F&& f); private: engine& engine_; render& render_; @@ -78,8 +77,8 @@ namespace e2d::render_system_impl namespace e2d::render_system_impl { template < typename F > - void drawer::with(const camera& cam, const const_node_iptr& cam_n, F&& f) { - context ctx{cam, cam_n, engine_, render_, window_, batcher_}; + void drawer::with(const camera& cam, F&& f) { + context ctx{cam, engine_, render_, window_, batcher_}; std::forward(f)(ctx); ctx.flush(); }