X-Git-Url: http://git.tdb.fi/?p=libs%2Fvr.git;a=blobdiff_plain;f=source%2Fovr%2Foculusriftcombiner.cpp;h=2d40ea95c1ff0e00b2231c94d812874f675ba11e;hp=b9515edcddb9ff8b9161dac229b62d080862d983;hb=dca13ee66628568631f502dfc79847c7368c7bb1;hpb=735148a3ecf7e753f520f22668b771583185f72f diff --git a/source/ovr/oculusriftcombiner.cpp b/source/ovr/oculusriftcombiner.cpp index b9515ed..2d40ea9 100644 --- a/source/ovr/oculusriftcombiner.cpp +++ b/source/ovr/oculusriftcombiner.cpp @@ -1,4 +1,3 @@ -#include #include #include #include "oculusriftcombiner.h" @@ -76,6 +75,12 @@ void create_distortion_mesh(Msp::GL::Mesh &mesh, ovrHmd hmd, ovrEyeType eye, con namespace Msp { namespace VR { +struct OculusRiftCombiner::Frustum: StereoCombiner::Frustum +{ + Frustum(const ovrFovPort &); +}; + + OculusRiftCombiner::OculusRiftCombiner(OculusRiftDevice &d, GL::View &v): device(d), view(v), @@ -87,17 +92,13 @@ OculusRiftCombiner::OculusRiftCombiner(OculusRiftDevice &d, GL::View &v): ovrFovPort left_fov = hmd->DefaultEyeFov[ovrEye_Left]; ovrFovPort right_fov = hmd->DefaultEyeFov[ovrEye_Right]; - float vertical = max(max(left_fov.UpTan, left_fov.DownTan), max(right_fov.UpTan, right_fov.DownTan)); - fov = Geometry::atan(vertical)*2.0f; + configure_eye_frustums(Frustum(left_fov), Frustum(right_fov)); - float inner = max(left_fov.RightTan, right_fov.LeftTan); - float outer = max(left_fov.LeftTan, right_fov.RightTan); - frustum_skew = (inner-outer)/(inner+outer); - - left_fov.UpTan = right_fov.UpTan = vertical; - left_fov.DownTan = right_fov.DownTan = vertical; - left_fov.RightTan = right_fov.LeftTan = inner; - left_fov.LeftTan = right_fov.RightTan = outer; + left_fov.UpTan = left_fov.DownTan = tan(fov/2.0f); + left_fov.LeftTan = left_fov.UpTan*render_aspect*(1-frustum_skew); + left_fov.RightTan = left_fov.UpTan*render_aspect*(1+frustum_skew); + right_fov = left_fov; + swap(right_fov.LeftTan, right_fov.RightTan); create_distortion_mesh(left_mesh, hmd, ovrEye_Left, left_fov); create_distortion_mesh(right_mesh, hmd, ovrEye_Right, right_fov); @@ -105,7 +106,6 @@ OculusRiftCombiner::OculusRiftCombiner(OculusRiftDevice &d, GL::View &v): ovrSizei tex_size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, left_fov, 1.0); target_width = tex_size.w; target_height = tex_size.h; - render_aspect = (inner+outer)/(vertical*2); left_shdata.uniform("texture", 0); right_shdata.uniform("texture", 0); @@ -167,5 +167,10 @@ void OculusRiftCombiner::render(const GL::Texture2D &left, const GL::Texture2D & device.end_frame(); } + +OculusRiftCombiner::Frustum::Frustum(const ovrFovPort &fov): + StereoCombiner::Frustum(-fov.LeftTan, fov.RightTan, -fov.DownTan, fov.UpTan) +{ } + } // namespace VR } // namespace Msp