From 109dd9823caabc9ca4e04504cf68b5e122441f13 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 14 Nov 2019 00:27:59 +0100 Subject: [PATCH] simplified ddspin/iddspin/cellgfxdist, replaced cellrelmatrix with adj/iadj --- asonov.cpp | 2 ++ cell.cpp | 2 ++ geometry2.cpp | 48 ++++++++++++++++++++++++++++++++++++++++-------- graph.cpp | 22 ---------------------- nonisotropic.cpp | 2 ++ raycaster.cpp | 7 ++----- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/asonov.cpp b/asonov.cpp index ed81654a..350d786f 100644 --- a/asonov.cpp +++ b/asonov.cpp @@ -145,6 +145,8 @@ struct hrmap_asonov : hrmap { return child; } + transmatrix adj(cell *c, int i) override { return adjmatrix(i); } + virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override { for(int a=0; amove(a)) return adjmatrix(a); return Id; diff --git a/cell.cpp b/cell.cpp index cdb6d0b5..b9b20b19 100644 --- a/cell.cpp +++ b/cell.cpp @@ -34,6 +34,8 @@ struct hrmap { virtual struct transmatrix relative_matrix(cell *c2, cell *c1, const struct hyperpoint& point_hint) { return relative_matrix(c2->master, c1->master); } + virtual struct transmatrix adj(cell *c, int i); + virtual struct transmatrix iadj(cell *c, int i) { return adj(c->cmove(i), c->c.spin(i)); } virtual void draw() { printf("undrawable\n"); } diff --git a/geometry2.cpp b/geometry2.cpp index 4ecb22a2..02f6c762 100644 --- a/geometry2.cpp +++ b/geometry2.cpp @@ -260,10 +260,7 @@ void virtualRebase_cell(cell*& base, T& at, const U& check) { while(true) { cell *newbase = NULL; forCellIdCM(c2, i, base) { - transmatrix V2 = - nil ? nilv::adjmatrix(base->c.spin(i)) : - asonov::in() ? asonov::adjmatrix(base->c.spin(i)) : - calc_relative_matrix(base, c2, C0); + transmatrix V2 = currentmap->iadj(base, i); T cand_at = V2 * at; horo_distance newz(check(cand_at)); if(newz < currz) { @@ -420,17 +417,50 @@ EX void virtualRebaseSimple(heptagon*& base, transmatrix& at) { } } +EX bool no_easy_spin() { + return NONSTDVAR || archimedean || WDIM == 3 || binarytiling || penrose; + } + +double hexshiftat(cell *c) { + if(binarytiling) return 0; + if(ctof(c) && S7==6 && S3 == 4 && BITRUNCATED) return cgi.hexshift + 2*M_PI/S7; + if(ctof(c) && (S7==8 || S7 == 4) && S3 == 3 && BITRUNCATED) return cgi.hexshift + 2*M_PI/S7; + if(cgi.hexshift && ctof(c)) return cgi.hexshift; + return 0; + } + +EX transmatrix ddspin(cell *c, int d, ld bonus IS(0)) { + if(no_easy_spin()) { + if(hybri) return PIU( ddspin(c, d, bonus) ); + transmatrix T = rspintox(tC0(currentmap->adj(c, d))); + if(WDIM == 3) return T * cspin(2, 0, bonus); + return T * spin(bonus); + } + return spin(displayspin(c, d) + bonus - hexshiftat(c)); + } + +EX transmatrix iddspin(cell *c, int d, ld bonus IS(0)) { + if(no_easy_spin()) { + if(hybri) return PIU( iddspin(c, d, bonus) ); + transmatrix T = spintox(tC0(currentmap->iadj(c, d))); + if(WDIM == 3) return T * cspin(2, 0, bonus); + return T * spin(bonus); + } + return spin(hexshiftat(c) - displayspin(c, d) + bonus); + } + EX double cellgfxdist(cell *c, int i) { - if(euclid && !penrose && !archimedean) { + if(no_easy_spin()) + return hdist0(tC0(currentmap->adj(c, i))); + if(euclid) { if(c->type == 8 && (i&1)) return cgi.crossf * sqrt(2); return cgi.crossf; } - if(NONSTDVAR || archimedean || WDIM == 3 || binarytiling || penrose) return hdist0(tC0(calc_relative_matrix(c->move(i), c, i))); return !BITRUNCATED ? cgi.tessf : (c->type == 6 && (i&1)) ? cgi.hexhexdist : cgi.crossf; } -EX transmatrix cellrelmatrix(cell *c, int i) { - if(NONSTDVAR || archimedean || penrose) return calc_relative_matrix(c->move(i), c, i); +transmatrix hrmap::adj(cell *c, int i) { + if(no_easy_spin()) return calc_relative_matrix(c->move(i), c, i); double d = cellgfxdist(c, i); transmatrix T = ddspin(c, i) * xpush(d); if(c->c.mirror(i)) T = T * Mirror; @@ -439,6 +469,8 @@ EX transmatrix cellrelmatrix(cell *c, int i) { return T; } +EX transmatrix cellrelmatrix(cell *c, int i) { return currentmap->adj(c, i); } + EX double randd() { return (rand() + .5) / (RAND_MAX + 1.); } EX hyperpoint randomPointIn(int t) { diff --git a/graph.cpp b/graph.cpp index 19017910..c60758af 100644 --- a/graph.cpp +++ b/graph.cpp @@ -345,28 +345,6 @@ EX ld displayspin(cell *c, int d) { return M_PI - d * 2 * M_PI / c->type; } -double hexshiftat(cell *c) { - if(binarytiling) return 0; - if(ctof(c) && S7==6 && S3 == 4 && BITRUNCATED) return cgi.hexshift + 2*M_PI/S7; - if(ctof(c) && (S7==8 || S7 == 4) && S3 == 3 && BITRUNCATED) return cgi.hexshift + 2*M_PI/S7; - if(cgi.hexshift && ctof(c)) return cgi.hexshift; - return 0; - } - -EX transmatrix ddspin(cell *c, int d, ld bonus IS(0)) { - if(hybri) return PIU( ddspin(c, d, bonus) ); - if(WDIM == 3 && d < c->type) return rspintox(tC0(calc_relative_matrix(c->cmove(d), c, C0))) * cspin(2, 0, bonus); - if(WDIM == 2 && (binarytiling || penrose) && d < c->type) return spin(bonus) * rspintox(nearcorner(c, d)); - return spin(displayspin(c, d) + bonus - hexshiftat(c)); - } - -EX transmatrix iddspin(cell *c, int d, ld bonus IS(0)) { - if(hybri) return PIU( iddspin(c, d, bonus) ); - if(WDIM == 3 && d < c->type) return cspin(0, 2, bonus) * spintox(tC0(calc_relative_matrix(c->cmove(d), c, C0))); - if(WDIM == 2 && (binarytiling || penrose) && d < c->type) return spin(bonus) * spintox(nearcorner(c, d)); - return spin(hexshiftat(c) - displayspin(c, d) + bonus); - } - #define UNTRANS (GDIM == 3 ? 0x000000FF : 0) EX void drawPlayerEffects(const transmatrix& V, cell *c, bool onplayer) { diff --git a/nonisotropic.cpp b/nonisotropic.cpp index 231d78d2..44a62122 100644 --- a/nonisotropic.cpp +++ b/nonisotropic.cpp @@ -821,6 +821,8 @@ EX namespace nilv { return child; } + transmatrix adj(cell *c, int i) override { return adjmatrix(i); } + virtual transmatrix relative_matrix(heptagon *h2, heptagon *h1) override { for(int a=0; amove(a)) return adjmatrix(a); return nisot::translate(mvec_to_point(coords[h1].inverse() * coords[h2])); diff --git a/raycaster.cpp b/raycaster.cpp index 7f531eed..1bbec120 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -857,10 +857,7 @@ EX void cast() { GLERR("uniform IPD"); vector ms; - for(int j=0; jrelative_matrix(cwt.at, cwt.at->cmove(j), Hypc) : currentmap->relative_matrix(cwt.at->master, cwt.at->cmove(j)->master)); + for(int j=0; jiadj(cwt.at, j)); if(prod) ms.push_back(Id); if(prod) ms.push_back(Id); @@ -924,7 +921,7 @@ EX void cast() { connections[u][2] = (S7+.5) / 1024.; continue; } - transmatrix T = (asonov::in() || nil) ? Id : (prod ? currentmap->relative_matrix(c, c1, C0) : currentmap->relative_matrix(c->master, c1->master)) * inverse(ms[i]); + transmatrix T = currentmap->iadj(c, i) * inverse(ms[i]); for(int k=0; k<=isize(ms); k++) { if(k < isize(ms) && !eqmatrix(ms[k], T)) continue; if(k == isize(ms)) ms.push_back(T);