]> git.tdb.fi Git - libs/vr.git/commitdiff
Change the mutability of StereoView members
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 09:42:03 +0000 (12:42 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 09:45:41 +0000 (12:45 +0300)
source/stereoview.cpp
source/stereoview.h

index 459abba7417c64128b645d15c0fa4f10caeaf134..d9f5822a4913204e3f9b8bb7997ba46f65e97b74 100644 (file)
@@ -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<float>::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<float>::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<float>(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);
 }
 
 
index 911f5f8f1ffd922984d4c705782f07c7af9cdc7f..c1421f81422fc9d2034da8ebf0832cf6c0c8dfd7 100644 (file)
@@ -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<float> 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<float> &);