mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-11-23 21:07:17 +00:00
rewritten the system to display 3D. This fixes the spherical display not working in stereo mode, and is more clean.
This commit is contained in:
parent
acd906d7c3
commit
4d2f79ba95
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
14
hud.cpp
14
hud.cpp
@ -377,13 +377,9 @@ void drawStats() {
|
||||
|
||||
{
|
||||
dynamicval<eModel> pm(pmodel, mdDisk);
|
||||
dynamicval<ld> va(vid.alpha, 1);
|
||||
dynamicval<ld> vax(vid.alpha, 1);
|
||||
dynamicval<videopar> 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) {
|
||||
|
2
hyper.h
2
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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
55
polygons.cpp
55
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<glvertex>& v, int ps, int pq, int col, int outline, int flags, textureinfo *tinf) {
|
||||
void gldraw(const transmatrix& V, const vector<glvertex>& 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<glvertex>& 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<glvertex>& 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<glvertex> scr = {
|
||||
make_array<GLfloat>(-xx, -yy, stereo::scrdist),
|
||||
make_array<GLfloat>(+xx, -yy, stereo::scrdist),
|
||||
make_array<GLfloat>(+xx, +yy, stereo::scrdist),
|
||||
make_array<GLfloat>(-xx, +yy, stereo::scrdist)
|
||||
make_array<GLfloat>(-xx, -yy, dist),
|
||||
make_array<GLfloat>(+xx, -yy, dist),
|
||||
make_array<GLfloat>(+xx, +yy, dist),
|
||||
make_array<GLfloat>(-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; i<pp.cnt; i++)
|
||||
tv.push_back(pp.tinf->tvertices[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<siz; i++) drawqueueitem(ptds[i]);
|
||||
ptds.clear();
|
||||
}
|
||||
|
||||
ld xintval(const hyperpoint& h) {
|
||||
@ -935,7 +921,7 @@ void drawqueue() {
|
||||
int siz = isize(ptds);
|
||||
|
||||
setcameraangle(true);
|
||||
|
||||
|
||||
#if CAP_GL
|
||||
if(vid.usingGL)
|
||||
glClear(GL_STENCIL_BUFFER_BIT);
|
||||
@ -1004,6 +990,8 @@ void drawqueue() {
|
||||
|
||||
spherespecial = 0;
|
||||
spherephase = 0;
|
||||
stereo::set_projection(0);
|
||||
|
||||
// on the sphere, parts on the back are drawn first
|
||||
if(sphere && pmodel == 0) {
|
||||
|
||||
@ -1015,6 +1003,8 @@ void drawqueue() {
|
||||
}
|
||||
|
||||
spherespecial = sphereflipped() ? 1 : -1;
|
||||
stereo::set_projection(0);
|
||||
|
||||
#ifndef STLSORT
|
||||
for(int p: {PPR_REDWALLs, PPR_REDWALLs2, PPR_REDWALLs3, PPR_WALL3s,
|
||||
PPR_LAKEWALL, PPR_INLAKEWALL, PPR_BELOWBOTTOM})
|
||||
@ -1039,6 +1029,7 @@ void drawqueue() {
|
||||
#endif
|
||||
spherespecial *= -1;
|
||||
spherephase = 1;
|
||||
stereo::set_projection(0);
|
||||
}
|
||||
for(int i=0; i<siz; i++) {
|
||||
GET_PTD(i);
|
||||
|
4
rug.cpp
4
rug.cpp
@ -1285,7 +1285,9 @@ void drawRugScene() {
|
||||
if(ed == 1 && stereo::mode == stereo::sAnaglyph)
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
start_projection(ed);
|
||||
start_projection(ed, true);
|
||||
eyewidth_translate(ed);
|
||||
|
||||
if(stereo::mode == stereo::sODS) {
|
||||
glhr::projection_multiply(glhr::ortho(M_PI, M_PI, 100)); // 2*M_PI));
|
||||
}
|
||||
|
@ -406,6 +406,7 @@ void switch_mode(eMode m) {
|
||||
mode = m;
|
||||
GLERR("after_switch_mode");
|
||||
current_vertices = NULL;
|
||||
id_modelview();
|
||||
}
|
||||
|
||||
void fog_max(ld fogmax) {
|
||||
|
Loading…
Reference in New Issue
Block a user