]> git.tdb.fi Git - libs/vr.git/blobdiff - source/stereoview.cpp
Add strabismus correction
[libs/vr.git] / source / stereoview.cpp
index c52802309ef5119677e2451ddc81c9a63717a1cb..95eb847d1b27a862b6d8513f3f122edd0f227058 100644 (file)
@@ -15,15 +15,16 @@ StereoView::StereoView(unsigned w, unsigned h, const GL::Camera &c, const GL::Re
        combiner(0)
 {
        set_combiner(m);
-       set_eye_spacing(0.07);
+       set_eye_spacing(0.064);
+       set_strabismus(Geometry::Angle<float>::zero());
 }
 
 void StereoView::set_combiner(const StereoCombiner &c)
 {
        combiner = &c;
 
-       unsigned w = width/combiner->get_width_divisor()*combiner->get_oversize();
-       unsigned h = height/combiner->get_height_divisor()*combiner->get_oversize();
+       unsigned w = width*combiner->get_width_factor();
+       unsigned h = height*combiner->get_height_factor();
        left.create_target(w, h);
        right.create_target(w, h);
 }
@@ -33,6 +34,11 @@ void StereoView::set_eye_spacing(float s)
        eye_spacing = s;
 }
 
+void StereoView::set_strabismus(const Geometry::Angle<float> &s)
+{
+       strabismus = s;
+}
+
 void StereoView::setup_frame() const
 {
        offset_axis = normalize(cross(base_camera.get_look_direction(), base_camera.get_up_direction()))*0.5f;
@@ -42,15 +48,16 @@ void StereoView::setup_frame() const
        if(params.fov==Geometry::Angle<float>::zero())
                params.fov = base_camera.get_field_of_view();
 
-       params.aspect = base_camera.get_aspect();
-       if(!combiner->is_aspect_kept())
-               params.aspect = params.aspect*combiner->get_height_divisor()/combiner->get_width_divisor();
-
+       params.aspect = base_camera.get_aspect()*combiner->get_aspect_factor();
        params.near_clip = base_camera.get_near_clip();
        params.far_clip = base_camera.get_far_clip();
 
-       left.setup_frame(base_camera, offset_axis*-eye_spacing, params);
-       right.setup_frame(base_camera, offset_axis*eye_spacing, params);
+       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;
+
+       left.setup_frame(base_camera, offset_axis*-eye_spacing, frustum_skew, params);
+       right.setup_frame(base_camera, offset_axis*eye_spacing, -frustum_skew, params);
 
        renderable.setup_frame();
 }
@@ -98,7 +105,7 @@ void StereoView::Eye::create_target(unsigned w, unsigned h)
        target = new RenderTarget(w, h);
 }
 
-void StereoView::Eye::setup_frame(const GL::Camera &base_camera, const GL::Vector3 &offset, const EyeParams &params) const
+void StereoView::Eye::setup_frame(const GL::Camera &base_camera, const GL::Vector3 &offset, float frustum_skew, const EyeParams &params) const
 {
        camera.set_position(base_camera.get_position()+offset);
        camera.set_up_direction(base_camera.get_up_direction());
@@ -107,6 +114,7 @@ void StereoView::Eye::setup_frame(const GL::Camera &base_camera, const GL::Vecto
        camera.set_field_of_view(params.fov);
        camera.set_aspect(params.aspect);
        camera.set_depth_clip(params.near_clip, params.far_clip);
+       camera.set_frustum_axis(frustum_skew, 0);
 }
 
 void StereoView::Eye::render(const GL::Renderable &renderable, const GL::Tag &tag) const