1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 01:00:25 +00:00

fake geometry in 2D

This commit is contained in:
Zeno Rogue 2020-05-31 03:30:14 +02:00
parent 8c796e64c4
commit 4a830f469b
3 changed files with 75 additions and 30 deletions

View File

@ -73,20 +73,17 @@ EX namespace fake {
});
if(WDIM == 2) {
hyperpoint a1, a2, b1, b2;
in_underlying([c, d, &a1, &a2, &b1, &b2] {
a1 = get_corner_position(c, d);
a2 = get_corner_position(c, (d+1) % c->type);
auto c1 = c->move(d);
auto d1 = c->c.spin(d);
b1 = get_corner_position(c1, d1);
b2 = get_corner_position(c1, (d1+1) % c1->type);
ld dist;
in_underlying([c, d, &dist] {
dist = currentmap->spacedist(c, d);
});
cgi.adjcheck = hdist0(mid(befake(a1), befake(a2))) + hdist0(mid(befake(b1), befake(b2)));
auto& u = *underlying_cgip;
if(dist == u.tessf) cgi.adjcheck = cgi.tessf;
else if(dist == u.crossf) cgi.adjcheck = cgi.crossf;
else if(dist == u.hexhexdist) cgi.adjcheck = cgi.hexhexdist;
else cgi.adjcheck = dist * scale;
}
return S1 * xpush(cgi.adjcheck) * S2;
@ -159,7 +156,7 @@ EX namespace fake {
// for(int i=0; i<S6; i++) queuepoly(ggmatrix(cwt.at), shWall3D[i], 0xFF0000FF);
if(pmodel == mdDisk && WDIM == 2) {
if(pmodel == mdDisk && WDIM == 2 && false) {
draw_recursive(centerover, cview(), -1, -1, nullptr, 0);
return;
}
@ -181,7 +178,7 @@ EX namespace fake {
drawcell(c, V);
if(in_wallopt() && isWall3(c) && isize(dq::drawqueue_c) > 1000) continue;
for(int i=0; i<S7; i++) if(c->move(i)) {
for(int i=0; i<c->type; i++) if(c->move(i)) {
enqueue(c->move(i), V * adj(c, i));
}
}
@ -290,8 +287,10 @@ EX ld around;
/** @brief the value of 'around' which makes the tiling Euclidean */
EX ld compute_euclidean() {
if(WDIM == 2) return 4 / (S7-2.) + 2;
int middle = get_middle();
return M_PI / asin(cos(M_PI/middle) / sin(M_PI/underlying_cgip->face));
}
@ -302,11 +301,12 @@ EX void compute_scale() {
if(around < 0) around = good;
if(abs(good - around) < 1e-6) good = around;
int s3 = WDIM == 2 ? S3 : underlying_cgip->loop;
multiple = false;
for(int k=1; k<10; k++)
if(abs(around - underlying_cgip->loop) < 1e-6)
multiple = true;
int mcount = int(around / s3 + .5);
multiple = abs(around - mcount * s3) < 1e-6;
if(around == good) {
ginf[gFake].g = WDIM == 3 ? giEuclid3 : giEuclid2;
@ -322,7 +322,11 @@ EX void compute_scale() {
ld around_ideal = 1/(1/2. - 1./get_middle());
if(euclid) scale = 1;
if(WDIM == 2) {
ginf[gFake].tiling_name = lalign(0, "{", S7, ",", around, "}");
return;
}
else if(euclid) scale = 1;
else if(abs(around_ideal - around) < 1e-6) {
hyperpoint h0 = underlying_cgip->cellshape[0];
auto s = kleinize(h0);
@ -385,13 +389,17 @@ EX void change_around() {
ld range = sightranges[geometry];
if(!fake::in()) {
if(around == cgi.loop) return; /* do nothing */
if(around == (WDIM == 2 ? S3 : cgi.loop)) return; /* do nothing */
set_gfake(around);
}
else {
compute_scale();
ray::reset_raycaster();
/* to compute scale */
if(WDIM == 2)
cgi.prepare_basics();
}
println(hlog, "scale = ", t, " -> ", scale, " range = ", range);

View File

@ -480,6 +480,8 @@ void geometry_information::prepare_basics() {
ld ALPHA = 2 * M_PI / S7;
ld fmin, fmax;
ld s3, beta;
if(arcm::in() && !prod)
ginf[gArchimedean].cclass = gcHyperbolic;
@ -507,12 +509,17 @@ void geometry_information::prepare_basics() {
hexhexdist = 0.566256;
goto finish;
}
s3 = S3;
if(fake::in()) s3 = fake::around;
beta = (S3 >= OINF && !fake::in()) ? 0 : 2*M_PI/s3;
tessf = euclid ? 1 : edge_of_triangle_with_angles(S3 >= OINF ? 0 : 2*M_PI/S3, M_PI/S7, M_PI/S7);
tessf = euclid ? 1 : edge_of_triangle_with_angles(beta, M_PI/S7, M_PI/S7);
if(elliptic && S7 == 4) tessf = M_PI/2;
if(elliptic && S7 == 4 && !fake::in()) tessf = M_PI/2;
hcrossf = euclid ? (S3 == 3 ? sqrt(3)/3 : sqrt(2)/2) : edge_of_triangle_with_angles(M_PI/2, M_PI/S7, M_PI/S3);
hcrossf = euclid ? tessf / 2 / sin(M_PI/s3) : edge_of_triangle_with_angles(M_PI/2, M_PI/S7, beta/2);
crossf = BITRUNCATED ? hcrossf : tessf;
@ -523,6 +530,22 @@ void geometry_information::prepare_basics() {
hyperpoint H1 = spin(2*M_PI/S7) * H;
hyperpoint H2 = xpush0(tessf-f);
ld v1 = intval(H, H1), v2 = intval(H, H2);
if(fake::in() && WDIM == 2) {
hexvdist = hdist(xpush0(f), xspinpush0(ALPHA/2, hcrossf));
v2 = hdist(
spin(M_PI/2/S3) * xpush0(hexvdist),
spin(-M_PI/2/S3) * xpush0(hexvdist)
);
v1 = hdist(
spin(M_PI/S7) * xpush0(f),
spin(-M_PI/S7) * xpush0(f)
);
println(hlog, f, " : ", tie(v1, v2));
}
if(v1 < v2) fmin = f; else fmax = f;
}
hexf = fmin;
@ -546,10 +569,12 @@ void geometry_information::prepare_basics() {
for(int d=0; d<S7; d++) invhexmove[d] = inverse(hexmove[d]);
hexhexdist = hdist(xpush0(crossf), xspinpush0(M_PI*2/S7, crossf));
hexvdist = hdist(xpush0(hexf), xspinpush0(ALPHA/2, hcrossf));
hexhexdist = fake::in() ?
2 * hdist0(mid(xspinpush0(M_PI/S6, hexvdist), xspinpush0(-M_PI/S6, hexvdist)))
: hdist(xpush0(crossf), xspinpush0(M_PI*2/S7, crossf));
DEBB(DF_GEOM | DF_POLY,
(format("S7=%d S6=%d hexf = " LDF" hcross = " LDF" tessf = " LDF" hexshift = " LDF " hexhex = " LDF " hexv = " LDF "\n", S7, S6, hexf, hcrossf, tessf, hexshift,
hexhexdist, hexvdist)));
@ -588,7 +613,18 @@ void geometry_information::prepare_basics() {
scalefactor = crossf / hcrossf7;
orbsize = crossf;
if(fake::in()) {
if(fake::in() && WDIM == 2) {
auto& u = *fake::underlying_cgip;
geometry = fake::underlying;
ld orig = xpush0(u.hcrossf)[0] / xpush0(u.hcrossf)[WDIM];
geometry = gFake;
ld our = xpush0(hcrossf)[0] / xpush0(hcrossf)[WDIM];
fake::scale = our / orig;
// if(debugflags & DF_GEOM)
println(hlog, "scale set to ", fake::scale);
}
if(fake::in() && WDIM == 3) {
auto& u = fake::underlying_cgip;
crossf = u->crossf * fake::scale;
scalefactor = u->scalefactor * fake::scale;
@ -596,6 +632,7 @@ void geometry_information::prepare_basics() {
hexf = u->hexf * fake::scale;
rhexf = u->rhexf * fake::scale;
hexvdist = u->hexvdist * fake::scale;
hcrossf = u->hcrossf * fake::scale;
}
if(arb::in()) {
@ -960,9 +997,9 @@ EX string cgi_string() {
V("VAR", its(int(variation)));
if(fake::in()) {
if(hyperbolic) V("H", fts(fake::scale));
if(euclid) V("E", fts(fake::scale));
if(sphere) V("S", fts(fake::scale));
if(hyperbolic) V("H", fts(fake::around));
if(euclid) V("E", fts(fake::around));
if(sphere) V("S", fts(fake::around));
V("G", FPIU(cgi_string()));
return s;
}

View File

@ -839,7 +839,7 @@ EX namespace patterns {
if(IRREGULAR || arcm::in() || bt::in() || arb::in() || WDIM == 3) si.symmetries = 1;
else if(a46) val46(c, si, sub, pat);
else if(a38) val38(c, si, sub, pat);
else if(sphere && S3 == 3) valSibling(c, si, sub, pat);
else if(S7 < 6 && S3 == 3) valSibling(c, si, sub, pat);
else if(euc::in(2,4)) valEuclid4(c, si, sub);
else if(euc::in(2,6)) valEuclid6(c, si, sub);
else if(a4) val457(c, si, sub);