diff --git a/basegraph.cpp b/basegraph.cpp index bcacfcbf..818c0c8c 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -182,45 +182,37 @@ void setcameraangle(bool b) { } } -void start_projection(int ed) { - glhr::new_projection(); - glhr::projection_multiply(glhr::translate((vid.xcenter*2.)/vid.xres - 1, 1 - (vid.ycenter*2.)/vid.yres, 0)); +bool using_perspective; - if(ed) { - if(stereo::mode == stereo::sLR) { - glhr::projection_multiply(glhr::translate(ed * (stereo::eyewidth() - .5) * 4, 0, 0)); - glhr::projection_multiply(glhr::scale(2, 1, 1)); - } - else { - glhr::projection_multiply(glhr::translate(-ed * stereo::eyewidth(), 0, 0)); - } - } +void start_projection(int ed, bool perspective) { + glhr::new_projection(); + using_perspective = perspective; + + if(ed && stereo::mode == stereo::sLR) { + glhr::projection_multiply(glhr::translate(ed, 0, 0)); + glhr::projection_multiply(glhr::scale(2, 1, 1)); + } + + glhr::projection_multiply(glhr::translate((vid.xcenter*2.)/vid.xres - 1, 1 - (vid.ycenter*2.)/vid.yres, 0)); + } + +void eyewidth_translate(int ed) { + if(ed) glhr::projection_multiply(glhr::translate(-ed * stereo::eyewidth(), 0, 0)); } void stereo::set_projection(int ed) { DEBB(DF_GRAPH, (debugfile,"stereo::set_projection\n")); - start_projection(ed); - - if(pmodel && !stereo::active()) { + start_projection(ed, pmodel == mdDisk && !spherespecial); + if(!using_perspective) { glhr::projection_multiply(glhr::ortho(vid.xres/2, -vid.yres/2, abs(stereo::scrdist) + 30000)); - } - else if(pmodel) { - - ld right = vid.xres/2 / stereo::scrdist; - ld left = -right; - ld top = -vid.yres/2 / stereo::scrdist; - ld bottom = -top; - - glhr::projection_multiply(glhr::frustum((right-left)/2, (top-bottom)/2)); - - if(ed) glhr::projection_multiply(glhr::translate(stereo::ipd * vid.radius * ed/2, 0, 0)); - - glhr::projection_multiply(glhr::scale(1, 1, -1)); - glhr::projection_multiply(glhr::translate(0, 0, stereo::scrdist)); - - stereo::scrdist_text = 0; + if(ed) { + glhr::glmatrix m = glhr::id; + m[2][0] -= ed; + glhr::projection_multiply(m); + } + glhr::id_modelview(); } else { @@ -233,6 +225,8 @@ void stereo::set_projection(int ed) { glhr::projection_multiply(glhr::scale(1,1,0)); } + eyewidth_translate(ed); + glhr::projection_multiply(glhr::frustum(vid.xres * 1. / vid.yres, 1)); GLfloat sc = vid.radius / (vid.yres/2.); @@ -323,6 +317,7 @@ void setGLProjection(int col) { GLERR("setGLProjection"); stereo::set_projection(0); + GLERR("after set_projection"); } diff --git a/config.cpp b/config.cpp index 652f133e..dafb1ef5 100644 --- a/config.cpp +++ b/config.cpp @@ -606,6 +606,8 @@ void showGraphConfig() { dialog::addSelItem(XLAT("line width"), fts(vid.linewidth), 'w'); // dialog::addBoolItem(XLAT("finer lines at the boundary"), vid.antialias & AA_LINEWIDTH, 'b'); } + else + dialog::addBreak(100); #if CAP_FRAMELIMIT dialog::addSelItem(XLAT("framerate limit"), its(vid.framelimit), 'l'); diff --git a/hud.cpp b/hud.cpp index 099e684d..0a5b1e48 100644 --- a/hud.cpp +++ b/hud.cpp @@ -377,13 +377,9 @@ void drawStats() { { dynamicval pm(pmodel, mdDisk); - dynamicval va(vid.alpha, 1); - dynamicval vax(vid.alpha, 1); dynamicval v(vid, vid); - calcparam(); -#if CAP_GL - stereo::set_projection(0); -#endif + vid.alpha = vid.scale = 1; + calcparam(); set_projection(0); if(haveMobileCompass()) { initquickqueue(); @@ -504,11 +500,7 @@ void drawStats() { } } } - - calcparam(); -#if CAP_GL - stereo::set_projection(0); -#endif + calcparam(); stereo::set_projection(0); string s0; if(!peace::on) { diff --git a/hyper.h b/hyper.h index 4629a192..fe156a10 100644 --- a/hyper.h +++ b/hyper.h @@ -3714,5 +3714,7 @@ extern ld hexshift; extern bool noshadow, bright, nohelp, dont_face_pc; extern void switchHardcore(); +extern bool using_perspective; + void generateAlts(heptagon *h, int levs = irr::on ? 1 : S3-3, bool link_cdata = true); } diff --git a/hypgraph.cpp b/hypgraph.cpp index 34d7b04c..d054f979 100644 --- a/hypgraph.cpp +++ b/hypgraph.cpp @@ -210,7 +210,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { if(!vid.camera_angle) { ret[0] = H[0] / tz; ret[1] = H[1] / tz; - ret[2] = vid.xres / vid.radius * stereo::eyewidth() / 2 - stereo::ipd / tz / 2; + ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / tz / 2; } else { ld tx = H[0]; @@ -221,7 +221,7 @@ void applymodel(hyperpoint H, hyperpoint& ret) { ld ux = tx, uy = ty * cc - ss * tz, uz = tz * cc + ss * ty; ret[0] = ux / uz; ret[1] = uy / uz; - ret[2] = vid.xres / vid.radius * stereo::eyewidth() / 2 - stereo::ipd / uz / 2; + ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / uz / 2; } return; } diff --git a/polygons.cpp b/polygons.cpp index d250bf20..f7b65711 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -149,7 +149,8 @@ int spherespecial, spherephase; void addpoint(const hyperpoint& H) { if(true) { hyperpoint Hscr; - applymodel(H, Hscr); + applymodel(H, Hscr); + for(int i=0; i<3; i++) Hscr[i] *= vid.radius; if(vid.alpha + H[2] <= BEHIND_LIMIT && pmodel == mdDisk) poly_flags |= POLY_BEHIND; if(spherespecial) { @@ -167,7 +168,6 @@ void addpoint(const hyperpoint& H) { Hscr[1] *= coef; } } - for(int i=0; i<3; i++) Hscr[i] *= vid.radius; add1(Hscr); } } @@ -254,23 +254,6 @@ void glapplymatrix(const transmatrix& V) { glhr::set_modelview(glhr::as_glmatrix(mat)); } -void setmatrix(int useV, const transmatrix& V) { - if(useV == 1) { - glapplymatrix(V); - } - else if(useV == 3) { - GLfloat mat[16] = { - 1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, GLfloat(stereo::mode ? -1 : 0), 0, - 0, 0, stereo::scrdist, 1 - }; - glhr::set_modelview(glhr::as_glmatrix(mat)); - } - else - glhr::id_modelview(); - } - #ifndef MINIMIZE_GL_CALLS #ifdef EMSCRIPTEN #define MINIMIZE_GL_CALLS 1 @@ -279,7 +262,7 @@ void setmatrix(int useV, const transmatrix& V) { #endif #endif -void gldraw(int useV, const transmatrix& V, const vector& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) { +void gldraw(const transmatrix& V, const vector& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) { if(tinf) { #if CAP_TEXTURE @@ -307,7 +290,8 @@ void gldraw(int useV, const transmatrix& V, const vector& v, int ps, i for(int ed = stereo::active() ? -1 : 0; ed<2; ed+=2) { if(ed) stereo::set_projection(ed), stereo::set_viewport(ed); bool draw = col; - setmatrix(useV, V); + + if(using_perspective) glapplymatrix(V); if(draw) { if((flags & POLY_VCONVEX) && MINIMIZE_GL_CALLS) { @@ -339,17 +323,18 @@ void gldraw(int useV, const transmatrix& V, const vector& v, int ps, i glStencilFunc( GL_NOTEQUAL, 1, 1); GLfloat xx = vid.xres; GLfloat yy = vid.yres; + GLfloat dist = using_perspective ? stereo::scrdist : 0; vector scr = { - make_array(-xx, -yy, stereo::scrdist), - make_array(+xx, -yy, stereo::scrdist), - make_array(+xx, +yy, stereo::scrdist), - make_array(-xx, +yy, stereo::scrdist) + make_array(-xx, -yy, dist), + make_array(+xx, -yy, dist), + make_array(+xx, +yy, dist), + make_array(-xx, +yy, dist) }; glhr::vertices(scr); glhr::id_modelview(); glDrawArrays(tinf ? GL_TRIANGLES : GL_TRIANGLE_FAN, 0, 4); glhr::vertices(v); - setmatrix(useV, V); + if(using_perspective) glapplymatrix(V); } else { glStencilOp( GL_ZERO, GL_ZERO, GL_ZERO); @@ -617,9 +602,9 @@ void drawpolyline(polytodraw& p) { } #if CAP_GL - if(vid.usingGL && pmodel == mdDisk && !spherespecial) { + if(vid.usingGL && using_perspective) { glLineWidth(linewidthat(tC0(pp.V), pp.minwidth)); - gldraw(1, pp.V, *pp.tab, pp.offset, pp.cnt, p.col, pp.outline, pp.flags &~ POLY_INVERSE, pp.tinf); + gldraw(pp.V, *pp.tab, pp.offset, pp.cnt, p.col, pp.outline, pp.flags &~ POLY_INVERSE, pp.tinf); return; } #endif @@ -718,11 +703,11 @@ void drawpolyline(polytodraw& p) { for(int i=0; itvertices[pp.offset+i]); swap(pp.tinf->tvertices, tv); - gldraw(3, Id, glcoords, 0, isize(glcoords), p.col, pp.outline, poly_flags, pp.tinf); + gldraw(Id, glcoords, 0, isize(glcoords), p.col, pp.outline, poly_flags, pp.tinf); swap(pp.tinf->tvertices, tv); } else - gldraw(3, Id, glcoords, 0, isize(glcoords), nofill ? 0 : p.col, pp.outline, poly_flags, nofill ? NULL : pp.tinf); + gldraw(Id, glcoords, 0, isize(glcoords), nofill ? 0 : p.col, pp.outline, poly_flags, nofill ? NULL : pp.tinf); continue; } #endif @@ -914,10 +899,11 @@ void sortquickqueue() { } void quickqueue() { - spherespecial = 0; + spherespecial = 0; stereo::set_projection(0); int siz = isize(ptds); setcameraangle(false); for(int i=0; i