From a59dc8be58ac45b5edc7781549d926acd7f7a9ba Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 16 Sep 2019 10:38:42 +0200 Subject: [PATCH] fixed binocular vision (isotropic only for now) --- basegraph.cpp | 12 +++++++++--- shaders.cpp | 13 ++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 8d8ef557..f44711a6 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -246,6 +246,7 @@ EX void start_projection(int ed, bool perspective) { } EX void eyewidth_translate(int ed) { + glhr::using_eyeshift = false; if(ed) glhr::projection_multiply(glhr::translate(-ed * current_display->eyewidth(), 0, 0)); } @@ -439,11 +440,16 @@ void display_data::set_projection(int ed) { GLfloat sc = current_display->radius / (cd->ysize/2.); glhr::projection_multiply(glhr::scale(sc, -sc, -1)); } - if(ed) { - if(pers3) - glhr::projection_multiply(glhr::tmtogl(xpush(vid.ipd * ed/2))); + if(pers3) { + if(anyshiftclick) + glhr::projection_multiply(glhr::tmtogl(xpush(vid.ipd * ed/2))); + else { + glhr::using_eyeshift = true; + glhr::eyeshift = glhr::tmtogl(xpush(vid.ipd * ed/2)); + } + } else glhr::projection_multiply(glhr::translate(vid.ipd * ed/2, 0, 0)); } diff --git a/shaders.cpp b/shaders.cpp index ae155606..2c69b66a 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -436,6 +436,9 @@ bool operator != (const glmatrix& m1, const glmatrix& m2) { bool uses_mvp(shader_projection sp) { return among(sp, shader_projection::standard, shader_projection::flatten); } +EX glmatrix eyeshift; +EX bool using_eyeshift; + EX void set_modelview(const glmatrix& modelview) { #if CAP_NOSHADER if(noshaders) { @@ -446,7 +449,15 @@ EX void set_modelview(const glmatrix& modelview) { #endif if(!current) return; if(!uses_mvp(current_shader_projection)) { - if(modelview != current_modelview) { + if(using_eyeshift) { + glmatrix mvp = modelview * eyeshift; + #if MINIMIZE_GL_CALLS + if(mvp == current_matrix) return; + current_matrix = mvp; + #endif + glUniformMatrix4fv(current->uMV, 1, 0, mvp.as_array()); + } + else if(modelview != current_modelview) { current_modelview = modelview; glUniformMatrix4fv(current->uMV, 1, 0, modelview.as_array()); }