From 8c61fd4fc7044c4ec0fd008173947b5b4bc00c6f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 16 Sep 2016 12:42:03 +0300 Subject: [PATCH] Change the mutability of StereoView members --- source/stereoview.cpp | 42 ++++++++++++++++++++++-------------------- source/stereoview.h | 8 ++++---- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/source/stereoview.cpp b/source/stereoview.cpp index 459abba..d9f5822 100644 --- a/source/stereoview.cpp +++ b/source/stereoview.cpp @@ -7,24 +7,23 @@ using namespace std; namespace Msp { namespace VR { -StereoView::StereoView(const GL::Camera &c, const GL::Renderable &r, const StereoCombiner &m): - base_camera(c), - renderable(r), - combiner(0) +StereoView::StereoView(const StereoCombiner &c, const GL::Camera &a): + combiner(c), + base_camera(a), + content(0) { - set_combiner(m); + unsigned w = combiner.get_target_width(); + unsigned h = combiner.get_target_height(); + left.create_target(w, h); + right.create_target(w, h); + set_eye_spacing(0.064); set_strabismus(Geometry::Angle::zero()); } -void StereoView::set_combiner(const StereoCombiner &c) +void StereoView::set_content(const GL::Renderable *r) { - combiner = &c; - - unsigned w = combiner->get_target_width(); - unsigned h = combiner->get_target_height(); - left.create_target(w, h); - right.create_target(w, h); + content = r; } void StereoView::set_eye_spacing(float s) @@ -42,15 +41,15 @@ void StereoView::setup_frame() const GL::Vector3 offset_axis = normalize(cross(base_camera.get_look_direction(), base_camera.get_up_direction()))*0.5f; EyeParams params; - params.fov = combiner->get_field_of_view(); + params.fov = combiner.get_field_of_view(); if(params.fov==Geometry::Angle::zero()) params.fov = base_camera.get_field_of_view(); - params.aspect = combiner->get_render_aspect(); + params.aspect = combiner.get_render_aspect(); params.near_clip = base_camera.get_near_clip(); params.far_clip = base_camera.get_far_clip(); - float frustum_skew = combiner->get_frustum_skew(); + float frustum_skew = combiner.get_frustum_skew(); float halfw = tan(params.fov/2.0f)*params.aspect; frustum_skew = tan(Geometry::atan(frustum_skew*halfw)+strabismus)/halfw; @@ -61,11 +60,14 @@ void StereoView::setup_frame() const void StereoView::render() const { setup_frame(); - renderable.setup_frame(); - left.render(renderable); - right.render(renderable); - renderable.finish_frame(); - combiner->render(left.target->color, right.target->color); + if(content) + { + content->setup_frame(); + left.render(*content); + right.render(*content); + content->finish_frame(); + } + combiner.render(left.target->color, right.target->color); } diff --git a/source/stereoview.h b/source/stereoview.h index 911f5f8..c1421f8 100644 --- a/source/stereoview.h +++ b/source/stereoview.h @@ -45,18 +45,18 @@ private: void render(const GL::Renderable &) const; }; + const StereoCombiner &combiner; const GL::Camera &base_camera; - const GL::Renderable &renderable; - const StereoCombiner *combiner; + const GL::Renderable *content; Eye left; Eye right; float eye_spacing; Geometry::Angle strabismus; public: - StereoView(const GL::Camera &, const GL::Renderable &, const StereoCombiner &); + StereoView(const StereoCombiner &, const GL::Camera &); - void set_combiner(const StereoCombiner &); + void set_content(const GL::Renderable *); void set_eye_spacing(float); void set_strabismus(const Geometry::Angle &); -- 2.45.2