]> git.tdb.fi Git - libs/vr.git/commitdiff
Add strabismus correction
authorMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:18:53 +0000 (01:18 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 23:18:53 +0000 (01:18 +0200)
This used to be sort of possible in the previous implementation of
OculusRiftCombiner, but this way works for all combiners.

source/stereoview.cpp
source/stereoview.h

index 4586f29d97ee7966ab1fa9104c6c5ed762637ede..95eb847d1b27a862b6d8513f3f122edd0f227058 100644 (file)
@@ -16,6 +16,7 @@ StereoView::StereoView(unsigned w, unsigned h, const GL::Camera &c, const GL::Re
 {
        set_combiner(m);
        set_eye_spacing(0.064);
+       set_strabismus(Geometry::Angle<float>::zero());
 }
 
 void StereoView::set_combiner(const StereoCombiner &c)
@@ -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;
@@ -47,6 +53,8 @@ void StereoView::setup_frame() const
        params.far_clip = base_camera.get_far_clip();
 
        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);
index 5516823ccb1a219f7c689975514fc5fa85ffee08..b1e0473029fec0e05ceb848f1aefd5c9f0fbe700 100644 (file)
@@ -53,6 +53,7 @@ private:
        Eye left;
        Eye right;
        float eye_spacing;
+       Geometry::Angle<float> strabismus;
        mutable GL::Vector3 offset_axis;
 
 public:
@@ -60,6 +61,7 @@ public:
 
        void set_combiner(const StereoCombiner &);
        void set_eye_spacing(float);
+       void set_strabismus(const Geometry::Angle<float> &);
 
        virtual void setup_frame() const;
        virtual void finish_frame() const;