From 9a21401b9c82b28315b7c6c758c590c8cd7cfe51 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 12 May 2019 14:35:14 +0200 Subject: [PATCH] item/monster icons in 3d --- basegraph.cpp | 7 ++++--- classes.h | 2 +- graph.cpp | 2 +- hud.cpp | 7 +++++-- hyper.h | 2 +- hyperpoint.cpp | 5 ++++- hypgraph.cpp | 21 +++++++++++++++------ polygons.cpp | 13 ++++++++++++- shaders.cpp | 15 ++++++++++----- 9 files changed, 53 insertions(+), 21 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 272f4e04..d5f892bc 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -215,7 +215,7 @@ void display_data::set_projection(int ed) { DEBB(DF_GRAPH, (debugfile,"current_display->set_projection\n")); bool pers3 = false; - bool apply_models = !among(pmodel, mdUnchanged, mdRug); + bool apply_models = !among(pmodel, mdUnchanged, mdFlatten, mdRug); shaderside_projection = false; glhr::new_shader_projection = glhr::shader_projection::standard; @@ -242,13 +242,14 @@ void display_data::set_projection(int ed) { if(spherephase == 3) glhr::new_shader_projection = glhr::shader_projection::standardS33; } } + if(pmodel == mdFlatten) shaderside_projection = true, glhr::new_shader_projection = glhr::shader_projection::flatten; start_projection(ed, shaderside_projection); if(pmodel == mdRug) return; auto cd = current_display; - if(!shaderside_projection) { + if(!shaderside_projection || glhr::new_shader_projection == glhr::shader_projection::flatten) { if(DIM == 3 && apply_models) { glhr::projection_multiply(glhr::ortho(cd->xsize/2, -cd->ysize/2, 1)); glhr::id_modelview(); @@ -319,7 +320,7 @@ void display_data::set_projection(int ed) { } } - if(vid.camera_angle && !among(pmodel, mdUnchanged, mdRug)) { + if(vid.camera_angle && !among(pmodel, mdUnchanged, mdFlatten, mdRug)) { ld cam = vid.camera_angle * degree; GLfloat cc = cos(cam); diff --git a/classes.h b/classes.h index abd2e8bd..cf88f555 100644 --- a/classes.h +++ b/classes.h @@ -261,7 +261,7 @@ enum eModel { mdFisheye, mdJoukowsky, mdJoukowskyInverted, mdRotatedHyperboles, mdSpiral, mdPerspective, mdEquivolume, - mdGUARD, mdUnchanged, mdHyperboloidFlat, mdPolynomial, mdRug + mdGUARD, mdUnchanged, mdHyperboloidFlat, mdPolynomial, mdRug, mdFlatten }; typedef unsigned long long flagtype; diff --git a/graph.cpp b/graph.cpp index d184a433..ddf33069 100644 --- a/graph.cpp +++ b/graph.cpp @@ -771,7 +771,7 @@ bool drawItemType(eItem it, cell *c, const transmatrix& V, color_t icol, int pti #endif transmatrix Vit = V; - if(GDIM == 3 && WDIM == 2) Vit = mscale(V, geom3::STUFF); + if(GDIM == 3 && WDIM == 2 && c) Vit = mscale(V, geom3::STUFF); if(DIM == 3 && c) Vit = face_the_player(Vit); // V * cspin(0, 2, ptick(618, 0)); diff --git a/hud.cpp b/hud.cpp index 279df2eb..566a8677 100644 --- a/hud.cpp +++ b/hud.cpp @@ -162,7 +162,7 @@ int glyphflags(int gid) { } bool graphglyph() { - if(DIM == 3) return false; + // if(DIM == 3) return false; return vid.graphglyph == 2 || (vid.graphglyph == 1 && vid.monmode); } @@ -187,6 +187,9 @@ bool displayglyph(int cx, int cy, int buttonsize, char glyph, color_t color, int if(m == moKrakenT || m == moDragonTail) bsize /= 2; if(m == moSlime) bsize = (2*bsize+1)/3; transmatrix V = atscreenpos(cx+buttonsize/2, cy, bsize*zoom); + if(isWorm(m) && wormscale != 1) + for(int i=0; i> 2; drawMonsterType(m, NULL, V, mcol, glyphphase[id]/500.0); @@ -394,7 +397,7 @@ void drawStats() { bool h = hide_player(); { - dynamicval pm(pmodel, mdDisk); + dynamicval pm(pmodel, DIM == 3 ? mdFlatten : mdDisk); // dynamicval v(vid, vid); // vid.alpha = vid.scale = 1; dynamicval va(vid.alpha, 1); diff --git a/hyper.h b/hyper.h index 2edbc75f..af4fea8c 100644 --- a/hyper.h +++ b/hyper.h @@ -3950,7 +3950,7 @@ namespace glhr { enum class shader_projection { standard, band, halfplane, standardH3, standardR3, standardS30, standardS31, standardS32, standardS33, - ball, halfplane3, band3, + ball, halfplane3, band3, flatten, MAX }; diff --git a/hyperpoint.cpp b/hyperpoint.cpp index f2343a93..f3f06011 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -671,7 +671,10 @@ hyperpoint mscale(const hyperpoint& t, double fac) { } transmatrix mscale(const transmatrix& t, double fac) { - if(GDIM == 3) return t * cpush(2, fac); + if(GDIM == 3) { + if(pmodel == mdFlatten) { transmatrix u = t; u[2][DIM] += fac; return u; } + return t * cpush(2, fac); + } transmatrix res; for(int i=0; iradius; return; @@ -1288,12 +1289,20 @@ transmatrix screenpos(ld x, ld y) { transmatrix atscreenpos(ld x, ld y, ld size) { transmatrix V = Id; - - V[0][2] += (x - current_display->xcenter); - V[1][2] += (y - current_display->ycenter); - V[0][0] = size * 2 * hcrossf / crossf; - V[1][1] = size * 2 * hcrossf / crossf; - V[2][2] = current_display->scrdist; + + if(pmodel == mdFlatten) { + V[0][3] += (x - current_display->xcenter); + V[1][3] += (y - current_display->ycenter); + V[0][0] = size * 2 * hcrossf / crossf; + V[1][1] = size * 2 * hcrossf / crossf; + } + else { + V[0][2] += (x - current_display->xcenter); + V[1][2] += (y - current_display->ycenter); + V[0][0] = size * 2 * hcrossf / crossf; + V[1][1] = size * 2 * hcrossf / crossf; + V[2][2] = current_display->scrdist; + } return V; } diff --git a/polygons.cpp b/polygons.cpp index dc60db6f..068c53bc 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -441,6 +441,15 @@ void coords_to_poly() { } void addpoly(const transmatrix& V, const vector &tab, int ofs, int cnt) { + if(pmodel == mdFlatten) { + for(int i=ofs; i= 4 extern void make_3d_models(); #endif @@ -2854,7 +2865,7 @@ void buildpolys() { bshape(shPirateX, PPR::ITEM, scalefactor, 124); bshape(shTreat, PPR::ITEM, scalefactor, 253); - ld wormscale = WDIM == 3 ? 3 : 1; + wormscale = WDIM == 3 ? 3 : 1; // first layer monsters bshape(shTentacleX, PPR::TENTACLE0); diff --git a/shaders.cpp b/shaders.cpp index a4cb6331..d879ca89 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -305,9 +305,11 @@ bool operator != (const glmatrix& m1, const glmatrix& m2) { return !(m1 == m2); } +bool uses_mvp(shader_projection sp) { return among(sp, shader_projection::standard, shader_projection::flatten); } + void set_modelview(const glmatrix& modelview) { if(!current) return; - if(current_shader_projection != shader_projection::standard) { + if(!uses_mvp(current_shader_projection)) { if(modelview != current_modelview) { current_modelview = modelview; glUniformMatrix4fv(current->uMV, 1, 0, modelview.as_array()); @@ -331,7 +333,7 @@ void set_modelview(const glmatrix& modelview) { void id_modelview() { if(!current) return; - if(current_shader_projection != shader_projection::standard) { set_modelview(id); return; } + if(!uses_mvp(current_shader_projection)) { set_modelview(id); return; } #if MINIMIZE_GL_CALLS if(projection == current_matrix) return; current_matrix = projection; @@ -495,7 +497,7 @@ void init() { shader_projection sp = shader_projection(j); - bool mps = j != 0; + bool mps = !uses_mvp(sp); bool band = among(sp, shader_projection::band, shader_projection::band3); bool hp = among(sp, shader_projection::halfplane, shader_projection::halfplane3); bool sh3 = (sp == shader_projection::standardH3); @@ -510,6 +512,7 @@ void init() { bool dim3 = s3 || among(sp, shader_projection::ball, shader_projection::halfplane3, shader_projection::band3); bool dim2 = !dim3; bool ball = (sp == shader_projection::ball); + bool flatten = (sp == shader_projection::flatten); programs[i][j] = new GLprogram(stringbuilder( @@ -557,9 +560,11 @@ void init() { varcol, "vColor = aColor;", !varcol, "vColor = uColor;", lfog, "vColor = vColor * clamp(1.0 + aPosition.z * uFog, 0.0, 1.0);", - !mps, "gl_Position = uMVP * aPosition;", + !mps && !flatten, "gl_Position = uMVP * aPosition;", + !mps && flatten, "vec4 pos = aPosition; pos[3] = 1.0; gl_Position = uMVP * pos;", ball, "vec4 t = uMV * aPosition; t /= (t[3] + uAlpha); ", - mps&&!(band||hp||s3||ball),"gl_Position = uP * (uMV * aPosition);", + mps&&!(band||hp||s3||ball||flatten),"gl_Position = uP * (uMV * aPosition);", + mps&&flatten, "vec4 pos = aPosition; pos[3] = 1.0; gl_Position = uP * (uMV * pos);", band||hp, "vec4 t = uMV * aPosition;", (band||hp) && dim2, "float zlev = zlevel(t);",