2018-02-08 23:40:26 +00:00
|
|
|
// Hyperbolic Rogue -- hyperbolic graphics
|
2019-08-10 11:43:24 +00:00
|
|
|
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
|
|
|
|
|
|
|
|
/** \file hypgraph.cpp
|
|
|
|
* \brief mapping hyperpoints to the screen, and related functions
|
|
|
|
*/
|
2018-02-08 23:40:26 +00:00
|
|
|
|
2018-06-10 23:58:31 +00:00
|
|
|
namespace hr {
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
ld ghx, ghy, ghgx, ghgy;
|
|
|
|
hyperpoint ghpm = C0;
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
#if HDR
|
2019-08-15 13:05:43 +00:00
|
|
|
inline bool sphereflipped() { return sphere && vid.alpha > 1.1 && GDIM == 3; }
|
2019-08-09 21:39:36 +00:00
|
|
|
#endif
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void ghcheck(hyperpoint &ret, const hyperpoint &H) {
|
|
|
|
if(hypot(ret[0]-ghx, ret[1]-ghy) < hypot(ghgx-ghx, ghgy-ghy)) {
|
|
|
|
ghpm = H; ghgx = ret[0]; ghgy = ret[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void camrotate(ld& hx, ld& hy) {
|
2018-11-08 17:18:25 +00:00
|
|
|
ld cam = vid.camera_angle * degree;
|
2017-07-10 18:47:38 +00:00
|
|
|
GLfloat cc = cos(cam);
|
|
|
|
GLfloat ss = sin(cam);
|
|
|
|
ld ux = hx, uy = hy * cc + ss, uz = cc - ss * hy;
|
|
|
|
hx = ux / uz, hy = uy / uz;
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
hyperpoint perspective_to_space(hyperpoint h, ld alpha = vid.alpha, eGeometryClass geo = ginf[geometry].cclass);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool non_spatial_model() {
|
2018-12-05 18:57:35 +00:00
|
|
|
if(among(pmodel, mdRotatedHyperboles, mdJoukowsky, mdJoukowskyInverted, mdPolygonal, mdPolynomial))
|
|
|
|
return true;
|
|
|
|
if(pmodel == mdSpiral && euclid)
|
|
|
|
return true;
|
|
|
|
return vid.consider_shader_projection && shaderside_projection && pmodel;
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
hyperpoint perspective_to_space(hyperpoint h, ld alpha, eGeometryClass gc) {
|
|
|
|
ld hx = h[0], hy = h[1];
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
if(gc == gcEuclid)
|
2019-02-22 19:58:40 +00:00
|
|
|
return hpxy(hx * (1 + alpha), hy * (1 + alpha));
|
2018-02-20 10:15:08 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
ld hr = hx*hx+hy*hy;
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
if(hr > .9999 && gc == gcHyperbolic) return Hypc;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
ld A, B, C;
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ld curv = gc == gcSphere ? 1 : -1;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
A = 1+curv*hr;
|
2018-02-03 12:41:49 +00:00
|
|
|
B = 2*hr*vid.alpha*-curv;
|
|
|
|
C = 1 - curv*hr*vid.alpha*vid.alpha;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
B /= A; C /= A;
|
|
|
|
|
|
|
|
ld rootsign = 1;
|
2018-11-06 14:53:50 +00:00
|
|
|
if(gc == gcSphere && vid.alpha > 1) rootsign = -1;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
ld hz = B / 2 + rootsign * sqrt(C + B*B/4);
|
|
|
|
|
|
|
|
hyperpoint H;
|
2018-02-03 12:41:49 +00:00
|
|
|
H[0] = hx * (hz+vid.alpha);
|
|
|
|
H[1] = hy * (hz+vid.alpha);
|
2019-08-17 21:28:41 +00:00
|
|
|
H[LDIM] = hz;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
return H;
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint space_to_perspective(hyperpoint z, ld alpha = vid.alpha);
|
|
|
|
|
|
|
|
hyperpoint space_to_perspective(hyperpoint z, ld alpha) {
|
2019-08-17 21:28:41 +00:00
|
|
|
ld s = 1 / (alpha + z[LDIM]);
|
2018-11-06 14:53:50 +00:00
|
|
|
z[0] *= s;
|
|
|
|
z[1] *= s;
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) {
|
2019-03-20 01:10:53 +00:00
|
|
|
z[2] *= s;
|
|
|
|
z[3] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
z[2] = 0;
|
2018-11-06 14:53:50 +00:00
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX hyperpoint gethyper(ld x, ld y) {
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2018-11-17 18:24:02 +00:00
|
|
|
ld hx = (x - current_display->xcenter) / current_display->radius;
|
|
|
|
ld hy = (y - current_display->ycenter) / current_display->radius / vid.stretch;
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
if(pmodel) {
|
|
|
|
ghx = hx, ghy = hy;
|
|
|
|
return ghpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.camera_angle) camrotate(hx, hy);
|
|
|
|
|
2019-02-22 19:58:40 +00:00
|
|
|
return perspective_to_space(hpxyz(hx, hy, 0));
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ballmodel(hyperpoint& ret, double alpha, double d, double zl) {
|
2019-05-29 14:27:24 +00:00
|
|
|
hyperpoint H = ypush(vid.camera) * xpush(d) * ypush(zl) * C0;
|
2019-08-17 21:28:41 +00:00
|
|
|
ld tzh = vid.ballproj + H[LDIM];
|
2017-07-10 18:47:38 +00:00
|
|
|
ld ax = H[0] / tzh;
|
|
|
|
ld ay = H[1] / tzh;
|
|
|
|
|
|
|
|
ld ca = cos(alpha), sa = sin(alpha);
|
2018-10-25 17:58:38 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
ret[0] = ax * ca;
|
2018-10-25 17:58:38 +00:00
|
|
|
ret[1] = ay;
|
|
|
|
ret[2] = ax * sa;
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_ball(ret[2], ret[1]);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:41:49 +00:00
|
|
|
void apply_depth(hyperpoint &f, ld z) {
|
|
|
|
if(vid.usingGL)
|
|
|
|
f[2] = z;
|
|
|
|
else {
|
2018-11-17 18:24:02 +00:00
|
|
|
z = z * current_display->radius;
|
|
|
|
ld mul = current_display->scrdist / (current_display->scrdist + z);
|
2018-02-03 12:41:49 +00:00
|
|
|
f[0] = f[0] * mul;
|
|
|
|
f[1] = f[1] * mul;
|
2018-11-17 18:24:02 +00:00
|
|
|
f[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius + vid.ipd * mul / 2;
|
2018-02-03 12:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
bool hypot_zlev(ld zlev, ld& d, ld& df, ld& zf) {
|
|
|
|
if(zlev == 1) {
|
2018-03-27 02:01:30 +00:00
|
|
|
df = 1; zf = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// (0,0,1) -> (0, sin z, cos z) -> (sin d cos z, sin z, cos d cos z)
|
|
|
|
ld z = geom3::factor_to_lev(zlev);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2018-03-27 02:01:30 +00:00
|
|
|
ld tz = sin_auto(z);
|
|
|
|
ld td = sin_auto(abs(d)) * cos_auto(z);
|
|
|
|
ld h = hypot(td, tz);
|
2018-11-06 14:53:50 +00:00
|
|
|
zf = tz / h, df = td / h;
|
|
|
|
|
2018-03-27 02:01:30 +00:00
|
|
|
if(d > 0)
|
|
|
|
d = hypot_auto(d, z);
|
|
|
|
else
|
|
|
|
d = -hypot_auto(d, z);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 10:18:33 +00:00
|
|
|
int twopoint_sphere_flips;
|
|
|
|
bool twopoint_do_flips;
|
2018-03-27 02:01:30 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ld find_zlev(hyperpoint& H) {
|
|
|
|
|
2018-12-05 18:57:35 +00:00
|
|
|
if(spatial_graphics) {
|
2018-11-06 14:53:50 +00:00
|
|
|
ld zlev = zlevel(H);
|
|
|
|
if(zlev > 1-1e-6 && zlev < 1+1e-6) return 1;
|
|
|
|
H /= zlev;
|
|
|
|
return zlev;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld get_tz(hyperpoint H) {
|
2019-08-17 21:28:41 +00:00
|
|
|
ld tz = euclid ? (1+vid.alpha) : vid.alpha+H[LDIM];
|
2017-11-03 18:20:54 +00:00
|
|
|
if(tz < BEHIND_LIMIT && tz > -BEHIND_LIMIT) tz = BEHIND_LIMIT;
|
2018-11-06 14:53:50 +00:00
|
|
|
return tz;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX ld atan2(hyperpoint h) {
|
2018-11-06 14:53:50 +00:00
|
|
|
return atan2(h[1], h[0]);
|
|
|
|
}
|
|
|
|
|
2019-03-20 01:10:53 +00:00
|
|
|
pair<ld, ld> move_z_to_y(hyperpoint& H) {
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 2) return make_pair(0, 0);
|
2019-03-20 01:10:53 +00:00
|
|
|
ld R = hypot(H[1], H[2]);
|
|
|
|
pair<ld, ld> res = { H[1] / R, H[2] / R };
|
|
|
|
H[1] = R; H[2] = 0;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void move_y_to_z(hyperpoint& H, pair<ld, ld> coef) {
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) {
|
2019-03-20 01:10:53 +00:00
|
|
|
H[2] = H[1] * coef.second;
|
|
|
|
H[1] = H[1] * coef.first;
|
|
|
|
H[3] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
template<class T> void makeband(hyperpoint H, hyperpoint& ret, const T& f) {
|
|
|
|
ld zlev = find_zlev(H);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(H[1], H[2]);
|
|
|
|
models::apply_orientation(H[0], H[1]);
|
2019-03-20 01:10:53 +00:00
|
|
|
auto r = move_z_to_y(H);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ld x, y, yf, zf=0;
|
|
|
|
y = asin_auto(H[1]);
|
2019-04-03 18:30:35 +00:00
|
|
|
x = asin_auto_clamp(H[0] / cos_auto(y));
|
2018-11-06 14:53:50 +00:00
|
|
|
if(sphere) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(H[LDIM] < 0 && x > 0) x = M_PI - x;
|
|
|
|
else if(H[LDIM] < 0 && x <= 0) x = -M_PI - x;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2019-04-03 18:30:35 +00:00
|
|
|
x += band_shift;
|
2018-11-06 14:53:50 +00:00
|
|
|
hypot_zlev(zlev, y, yf, zf);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
f(x, y);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ld yzf = y * zf; y *= yf;
|
2019-02-22 19:58:40 +00:00
|
|
|
ret = hpxyz(x / M_PI, y / M_PI, 0);
|
2019-03-20 01:10:53 +00:00
|
|
|
move_y_to_z(ret, r);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[1], ret[0]);
|
|
|
|
models::apply_orientation_yz(ret[2], ret[1]);
|
2018-11-17 18:24:02 +00:00
|
|
|
if(zlev != 1 && current_display->stereo_active())
|
2018-11-06 14:53:50 +00:00
|
|
|
apply_depth(ret, yzf / M_PI);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 18:08:57 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
void band_conformal(ld& x, ld& y) {
|
|
|
|
switch(cgclass) {
|
|
|
|
case gcSphere:
|
|
|
|
y = atanh(sin(y));
|
|
|
|
x *= 2; y *= 2;
|
|
|
|
break;
|
|
|
|
case gcHyperbolic:
|
|
|
|
y = 2 * atan(tanh(y/2));
|
|
|
|
x *= 2; y *= 2;
|
|
|
|
break;
|
|
|
|
case gcEuclid:
|
2019-07-23 13:08:07 +00:00
|
|
|
default:
|
2018-11-06 14:53:50 +00:00
|
|
|
// y = y;
|
|
|
|
y *= 2; x *= 2;
|
|
|
|
break;
|
2018-10-23 18:08:57 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
}
|
2018-10-23 18:08:57 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
void make_twopoint(ld& x, ld& y) {
|
|
|
|
auto p = vid.twopoint_param;
|
|
|
|
ld dleft = hypot_auto(x-p, y);
|
|
|
|
ld dright = hypot_auto(x+p, y);
|
|
|
|
if(sphere) {
|
|
|
|
int tss = twopoint_sphere_flips;
|
|
|
|
if(tss&1) { tss--;
|
|
|
|
dleft = 2*M_PI - 2*p - dleft;
|
|
|
|
dright = 2*M_PI - 2*p - dright;
|
|
|
|
swap(dleft, dright);
|
|
|
|
y = -y;
|
2018-10-23 18:08:57 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
while(tss) { tss -= 2;
|
|
|
|
dleft = 2*M_PI - 4*p + dleft;
|
|
|
|
dright = 2*M_PI - 4*p + dright;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2018-04-18 18:52:17 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
x = (dright*dright-dleft*dleft) / 4 / p;
|
|
|
|
y = (y>0?1:-1) * sqrt(dleft * dleft - (x-p)*(x-p) + 1e-9);
|
|
|
|
}
|
2018-04-18 18:52:17 +00:00
|
|
|
|
2018-11-07 06:20:36 +00:00
|
|
|
hyperpoint mobius(hyperpoint h, ld angle, ld scale = 1) {
|
|
|
|
h = perspective_to_space(h * scale, 1, gcSphere);
|
2019-08-09 21:59:32 +00:00
|
|
|
h = cspin(1, 2, angle * degree) * h;
|
2018-11-07 06:20:36 +00:00
|
|
|
return space_to_perspective(h, 1) / scale;
|
|
|
|
}
|
|
|
|
|
2019-07-12 21:10:01 +00:00
|
|
|
hyperpoint compute_hybrid(hyperpoint H, int rootid) {
|
|
|
|
auto& t = vid.twopoint_param;
|
|
|
|
hyperpoint Hl = xpush(+t) * H;
|
|
|
|
hyperpoint Hr = xpush(-t) * H;
|
|
|
|
ld g = (Hl[0] + 1e-7) / (Hl[1] + 1e-8);
|
|
|
|
ld d = hdist0(Hr);
|
|
|
|
|
|
|
|
hyperpoint spinned = spintox(Hl) * xpush0(2*t);
|
|
|
|
if(Hl[0] < 0) spinned = pispin * spinned;
|
|
|
|
|
|
|
|
ld y = asin_auto(spinned[1]);
|
|
|
|
ld x = asin_auto_clamp(spinned[0] / cos_auto(y));
|
|
|
|
|
|
|
|
int sign = (Hl[0] > 0 ? 1 : -1) * hdist0(Hl) < x ? -1 : 1;
|
|
|
|
|
|
|
|
switch(rootid & 3) {
|
|
|
|
case 1: sign = -sign; break;
|
|
|
|
case 2: sign = 1; break;
|
|
|
|
case 3: sign = -1; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (x + t) / g = y
|
|
|
|
// yy + (x-t)(x-t) = dd
|
|
|
|
// (x+t)*(x+t)/g*g + x*x + t*t - 2*x*t = dd
|
|
|
|
|
|
|
|
// x*x*(1+1/g*g) + t*t*(1+1/g*g) + 2xt (1/gg-1) = dd
|
|
|
|
// xx + 2xt (1/gg-1) / (1+1/gg) = dd / (1+1/gg) - tt
|
|
|
|
|
|
|
|
ld b = t*(1/g/g - 1) / (1+1/g/g);
|
|
|
|
ld c = d*d / (1+1/g/g) - t*t;
|
|
|
|
|
|
|
|
// xx + 2bx = c
|
|
|
|
// xx + 2bx + bb = c + bb
|
|
|
|
// (x+b)^2 = c+bb
|
|
|
|
// x = +/- sqrt(c+bb) - b
|
|
|
|
|
|
|
|
ld a = c+b*b;
|
|
|
|
|
|
|
|
hyperpoint ret;
|
|
|
|
ret[0] = (a > 0 ? sign * sqrt(a) : 0) - b;
|
|
|
|
ret[1] = (ret[0] + t) / g;
|
|
|
|
ret[2] = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-08-14 16:59:21 +00:00
|
|
|
EX ld signed_sqrt(ld x) { return x > 0 ? sqrt(x) : -sqrt(-x); };
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void applymodel(hyperpoint H, hyperpoint& ret) {
|
2019-02-21 17:46:53 +00:00
|
|
|
|
2019-02-06 21:41:45 +00:00
|
|
|
hyperpoint H_orig = H;
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
switch(pmodel) {
|
2019-03-20 01:10:53 +00:00
|
|
|
case mdPerspective: {
|
|
|
|
ld ratio = vid.xres / current_display->tanfov / current_display->radius / 2;
|
2019-08-06 10:00:46 +00:00
|
|
|
if(nisot::local_perspective_used()) H = nisot::local_perspective * H;
|
2019-03-20 01:10:53 +00:00
|
|
|
ret[0] = H[0]/H[2] * ratio;
|
|
|
|
ret[1] = H[1]/H[2] * ratio;
|
|
|
|
ret[2] = 1;
|
|
|
|
return;
|
|
|
|
}
|
2019-07-28 09:07:21 +00:00
|
|
|
|
2019-08-06 14:48:01 +00:00
|
|
|
case mdGeodesic: {
|
2019-08-06 10:00:46 +00:00
|
|
|
auto S = nisot::inverse_exp(H, nisot::iTable);
|
|
|
|
if(nisot::local_perspective_used()) S = nisot::local_perspective * S;
|
2019-07-28 09:07:21 +00:00
|
|
|
ld ratio = vid.xres / current_display->tanfov / current_display->radius / 2;
|
|
|
|
ret[0] = S[0]/S[2] * ratio;
|
|
|
|
ret[1] = S[1]/S[2] * ratio;
|
|
|
|
ret[2] = 1;
|
|
|
|
return;
|
|
|
|
}
|
2019-03-20 01:10:53 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdUnchanged:
|
2019-05-12 12:35:14 +00:00
|
|
|
case mdFlatten:
|
2018-11-17 18:24:02 +00:00
|
|
|
ret = H / current_display->radius;
|
2018-11-06 14:53:50 +00:00
|
|
|
return;
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdBall: {
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
|
2019-05-29 14:27:24 +00:00
|
|
|
ld zl = vid.depth-geom3::factor_to_lev(zlev);
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ballmodel(ret, atan2(H), hdist0(H), zl);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdDisk: {
|
2019-08-06 10:00:46 +00:00
|
|
|
if(nisot::local_perspective_used()) H = nisot::local_perspective * H;
|
2018-11-06 14:53:50 +00:00
|
|
|
ld tz = get_tz(H);
|
|
|
|
if(!vid.camera_angle) {
|
|
|
|
ret[0] = H[0] / tz;
|
|
|
|
ret[1] = H[1] / tz;
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) ret[2] = H[2] / tz;
|
2019-03-20 01:10:53 +00:00
|
|
|
else ret[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius - vid.ipd / tz / 2;
|
|
|
|
if(MAXMDIM == 4) ret[3] = 1;
|
2018-11-06 14:53:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ld tx = H[0];
|
|
|
|
ld ty = H[1];
|
2018-11-08 17:18:25 +00:00
|
|
|
ld cam = vid.camera_angle * degree;
|
2018-11-06 14:53:50 +00:00
|
|
|
GLfloat cc = cos(cam);
|
|
|
|
GLfloat ss = sin(cam);
|
|
|
|
ld ux = tx, uy = ty * cc - ss * tz, uz = tz * cc + ss * ty;
|
|
|
|
ret[0] = ux / uz;
|
|
|
|
ret[1] = uy / uz;
|
2018-11-17 18:24:02 +00:00
|
|
|
ret[2] = vid.xres * current_display->eyewidth() / 2 / current_display->radius - vid.ipd / uz / 2;
|
2018-03-27 02:01:30 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
return;
|
2019-07-03 02:53:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case mdCentralInversion: {
|
|
|
|
ld tz = get_tz(H);
|
2019-08-15 13:05:43 +00:00
|
|
|
for(int d=0; d<GDIM; d++) ret[d] = H[d] / tz;
|
2019-07-03 02:53:56 +00:00
|
|
|
ld r = 0;
|
2019-08-15 13:05:43 +00:00
|
|
|
for(int d=0; d<GDIM; d++) r += ret[d]*ret[d];
|
|
|
|
for(int d=0; d<GDIM; d++) ret[d] /= r;
|
2019-07-03 02:53:56 +00:00
|
|
|
return;
|
2018-03-26 17:06:47 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
case mdHalfplane: {
|
|
|
|
// Poincare to half-plane
|
|
|
|
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
H = space_to_perspective(H);
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(H[1], H[2]);
|
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
H[1] += 1;
|
2019-08-15 13:05:43 +00:00
|
|
|
double rad = sqhypot_d(GDIM, H);
|
2018-11-06 14:53:50 +00:00
|
|
|
H /= -rad;
|
|
|
|
H[1] += .5;
|
2018-10-23 14:58:19 +00:00
|
|
|
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) {
|
2019-03-20 17:32:03 +00:00
|
|
|
// a bit simpler when we do not care about 3D
|
2019-08-09 22:58:50 +00:00
|
|
|
H *= models::halfplane_scale;
|
2019-03-20 17:32:03 +00:00
|
|
|
ret[0] = -H[0];
|
|
|
|
ret[1] = 1 + H[1];
|
|
|
|
ret[2] = H[2];
|
|
|
|
ret[3] = 1;
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[1], ret[0]);
|
|
|
|
models::apply_orientation_yz(ret[2], ret[1]);
|
2019-03-20 17:32:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-07-30 15:44:11 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
H *= models::halfplane_scale;
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
ret[0] = -models::osin - H[0];
|
2018-11-06 14:53:50 +00:00
|
|
|
if(zlev != 1) {
|
2019-08-09 22:58:50 +00:00
|
|
|
if(abs(models::ocos) > 1e-5)
|
|
|
|
H[1] = H[1] * pow(zlev, models::ocos);
|
|
|
|
if(abs(models::ocos) > 1e-5 && models::osin)
|
|
|
|
H[1] += H[0] * models::osin * (pow(zlev, models::ocos) - 1) / models::ocos;
|
|
|
|
else if(models::osin)
|
|
|
|
H[1] += H[0] * models::osin * log(zlev);
|
2018-11-06 14:53:50 +00:00
|
|
|
}
|
2019-08-09 22:58:50 +00:00
|
|
|
ret[1] = models::ocos + H[1];
|
2019-08-15 13:05:43 +00:00
|
|
|
ret[2] = GDIM == 3 ? H[2] : 0;
|
2019-03-20 01:10:53 +00:00
|
|
|
if(MAXMDIM == 4) ret[3] = 1;
|
2018-11-17 18:24:02 +00:00
|
|
|
if(zlev != 1 && current_display->stereo_active())
|
2018-11-06 14:53:50 +00:00
|
|
|
apply_depth(ret, -H[1] * geom3::factor_to_lev(zlev));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdHemisphere: {
|
|
|
|
|
|
|
|
switch(cgclass) {
|
|
|
|
case gcHyperbolic: {
|
|
|
|
ld zl = zlevel(H);
|
|
|
|
ret = H / H[2];
|
2019-02-27 18:33:13 +00:00
|
|
|
ret[2] = sqrt(1 - sqhypot_d(2, ret));
|
2018-11-06 14:53:50 +00:00
|
|
|
ret = ret * (1 + (zl - 1) * ret[2]);
|
2018-07-30 15:44:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2019-07-23 13:08:07 +00:00
|
|
|
case gcEuclid: default: {
|
2018-11-06 14:53:50 +00:00
|
|
|
// stereographic projection to a sphere
|
|
|
|
auto hd = hdist0(H) / vid.euclid_to_sphere;
|
2019-02-22 19:58:40 +00:00
|
|
|
if(hd == 0) ret = hpxyz(0, 0, -1);
|
2018-11-06 14:53:50 +00:00
|
|
|
else {
|
|
|
|
ld x = 2 * hd / (1 + hd * hd);
|
|
|
|
ld y = x / hd;
|
|
|
|
ret = H * x / hd / vid.euclid_to_sphere;
|
|
|
|
ret[2] = (1 - y);
|
|
|
|
ret = ret * (1 + (H[2]-1) * y / vid.euclid_to_sphere);
|
2018-04-21 10:18:33 +00:00
|
|
|
}
|
2018-07-30 15:44:11 +00:00
|
|
|
break;
|
2018-04-21 10:18:33 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
case gcSphere: {
|
|
|
|
ret = H;
|
2018-03-26 17:06:47 +00:00
|
|
|
break;
|
2018-07-30 15:44:11 +00:00
|
|
|
}
|
2018-03-26 17:06:47 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
swap(ret[1], ret[2]);
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_ball(ret[2], ret[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
break;
|
2018-03-26 17:06:47 +00:00
|
|
|
}
|
2017-11-13 00:29:31 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdHyperboloidFlat:
|
|
|
|
case mdHyperboloid: {
|
2017-11-13 00:29:31 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
if(pmodel == mdHyperboloid) {
|
2019-08-09 22:58:50 +00:00
|
|
|
ld& topz = models::top_z;
|
2018-11-06 14:53:50 +00:00
|
|
|
if(H[2] > topz) {
|
2019-02-27 18:33:13 +00:00
|
|
|
ld scale = sqrt(topz*topz-1) / hypot_d(2, H);
|
2018-11-06 14:53:50 +00:00
|
|
|
H *= scale;
|
|
|
|
H[2] = topz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
H = space_to_perspective(H, vid.alpha);
|
|
|
|
H[2] = 1 - vid.alpha;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ret[0] = H[0] / 3;
|
|
|
|
ret[1] = (1 - H[2]) / 3;
|
|
|
|
ret[2] = H[1] / 3;
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_ball(ret[2], ret[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdFisheye: {
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
H = space_to_perspective(H);
|
2019-08-17 21:28:41 +00:00
|
|
|
H[LDIM] = zlev;
|
2019-08-15 13:05:43 +00:00
|
|
|
ret = H / sqrt(1 + sqhypot_d(GDIM+1, H));
|
2019-08-17 21:28:41 +00:00
|
|
|
if(GDIM == 3) ret[LDIM] = zlev;
|
2018-11-06 14:53:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2019-07-12 21:10:01 +00:00
|
|
|
case mdSimulatedPerspective: {
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(H[1], H[2]);
|
|
|
|
models::apply_orientation(H[0], H[1]);
|
2019-07-12 21:10:01 +00:00
|
|
|
auto yz = move_z_to_y(H);
|
|
|
|
hyperpoint Hl = xpush(-vid.twopoint_param) * H;
|
|
|
|
hyperpoint Hr = xpush(+vid.twopoint_param) * H;
|
|
|
|
ld lyx = (Hl[1] + 1e-7) / (Hl[0] + 1e-8);
|
|
|
|
ld ryx = (Hr[1] + 1e-7) / (Hr[0] + 1e-8);
|
|
|
|
// (r.x + t) * lyx = (r.x - t) * ryx = r.y
|
|
|
|
// r.x * lyx + t * lyx = r.x * ryx - t * ryx
|
|
|
|
// r.x * (lyx-ryx) = - t * (ryx + lyx)
|
|
|
|
// r.x = -t * (ryx+lyx) / (lyx-ryx)
|
|
|
|
// r.x = - 2 * t * lyx * ryx / lyx / ryx
|
|
|
|
|
|
|
|
ret[0] = -vid.twopoint_param * (ryx + lyx) / (lyx - ryx);
|
|
|
|
ret[1] = (ret[0] + vid.twopoint_param) * lyx;
|
|
|
|
ret[2] = 0;
|
|
|
|
|
|
|
|
move_y_to_z(ret, yz);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[0], ret[1]);
|
|
|
|
models::apply_orientation_yz(ret[2], ret[1]);
|
2019-07-12 21:10:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdTwoHybrid: {
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(H[1], H[2]);
|
|
|
|
models::apply_orientation(H[0], H[1]);
|
2019-07-12 21:10:01 +00:00
|
|
|
auto yz = move_z_to_y(H);
|
|
|
|
|
|
|
|
ret = compute_hybrid(H, whateveri[0]);
|
|
|
|
|
|
|
|
move_y_to_z(ret, yz);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[0], ret[1]);
|
|
|
|
models::apply_orientation_yz(ret[2], ret[1]);
|
2019-07-12 21:10:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdJoukowsky:
|
|
|
|
case mdJoukowskyInverted: {
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(H[1], H[2]);
|
|
|
|
models::apply_orientation(H[0], H[1]);
|
|
|
|
// with equal speed skiprope: models::apply_orientation(H[1], H[0]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
if(vid.skiprope) {
|
|
|
|
static ld last_skiprope = 0;
|
|
|
|
static transmatrix lastmatrix;
|
|
|
|
if(vid.skiprope != last_skiprope) {
|
2018-11-07 06:20:36 +00:00
|
|
|
ret = mobius(C0, -vid.skiprope, 2);
|
2018-11-06 14:53:50 +00:00
|
|
|
const cld c1(1, 0);
|
|
|
|
const cld c2(2, 0);
|
|
|
|
const cld c4(4, 0);
|
|
|
|
cld w(ret[0], ret[1]);
|
|
|
|
cld z = sqrt(c4*w*w-c1) + c2*w;
|
|
|
|
if(abs(z) > 1) z = c1 / z;
|
2019-02-22 19:58:40 +00:00
|
|
|
hyperpoint zr = hpxyz(real(z), imag(z), 0);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
hyperpoint inhyp = perspective_to_space(zr, 1, gcHyperbolic);
|
|
|
|
last_skiprope = vid.skiprope;
|
|
|
|
lastmatrix = rgpushxto0(inhyp);
|
|
|
|
}
|
|
|
|
H = lastmatrix * H;
|
|
|
|
}
|
|
|
|
|
|
|
|
H = space_to_perspective(H);
|
2019-03-20 01:10:53 +00:00
|
|
|
auto yz = move_z_to_y(H);
|
2019-02-27 18:33:13 +00:00
|
|
|
ld r = hypot_d(2, H);
|
2018-11-06 14:53:50 +00:00
|
|
|
ld c = H[0] / r;
|
|
|
|
ld s = H[1] / r;
|
2019-08-09 22:58:50 +00:00
|
|
|
ld& mt = models::model_transition;
|
2018-11-06 14:53:50 +00:00
|
|
|
ld a = 1 - .5 * mt, b = .5 * mt;
|
|
|
|
swap(a, b);
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
ret[0] = (a * r + b/r) * c / 2;
|
|
|
|
ret[1] = (a * r - b/r) * s / 2;
|
|
|
|
ret[2] = 0;
|
|
|
|
|
2018-11-07 06:20:36 +00:00
|
|
|
if(vid.skiprope)
|
|
|
|
ret = mobius(ret, vid.skiprope, 2);
|
2019-03-20 01:10:53 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
if(pmodel == mdJoukowskyInverted) {
|
2019-02-27 18:33:13 +00:00
|
|
|
ld r2 = sqhypot_d(2, ret);
|
2018-11-06 14:53:50 +00:00
|
|
|
ret[0] = ret[0] / r2;
|
|
|
|
ret[1] = -ret[1] / r2;
|
2019-03-20 01:10:53 +00:00
|
|
|
move_y_to_z(ret, yz);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[1], ret[0]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
ret[0] += 1;
|
|
|
|
ld alpha = atan2(ret[1], ret[0]);
|
|
|
|
ld mod = hypot(ret[0], ret[1]);
|
|
|
|
// ret[0] = cos(alpha/2) * sqrt(mod);
|
|
|
|
// ret[1] = sin(alpha/2) * sqrt(mod);
|
|
|
|
ret[0] = alpha;
|
|
|
|
ret[1] = log(mod); */
|
|
|
|
}
|
2019-03-20 01:10:53 +00:00
|
|
|
else {
|
|
|
|
move_y_to_z(ret, yz);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[0], ret[1]);
|
2019-03-20 01:10:53 +00:00
|
|
|
}
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation_yz(ret[2], ret[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
break;
|
2018-10-25 00:44:35 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdPolygonal: case mdPolynomial: {
|
2018-03-26 17:06:47 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
H = space_to_perspective(H);
|
2018-10-23 14:58:19 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
pair<long double, long double> p = polygonal::compute(H[0], H[1]);
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(p.second, p.first);
|
2018-11-06 14:53:50 +00:00
|
|
|
ret[0] = p.first;
|
|
|
|
ret[1] = p.second;
|
|
|
|
ret[2] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdBand:
|
2019-08-09 22:58:50 +00:00
|
|
|
if(models::model_transition != 1) {
|
|
|
|
ld& mt = models::model_transition;
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
H = space_to_perspective(H);
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
H[0] += 1;
|
|
|
|
double rad = H[0]*H[0] + H[1]*H[1];
|
|
|
|
H[1] /= rad;
|
|
|
|
H[0] /= rad;
|
|
|
|
H[0] -= .5;
|
|
|
|
|
|
|
|
ld phi = atan2(H);
|
2019-02-27 18:33:13 +00:00
|
|
|
ld r = hypot_d(2, H);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
r = pow(r, 1 - mt);
|
|
|
|
phi *= (1 - mt);
|
|
|
|
ret[0] = r * cos(phi);
|
|
|
|
ret[1] = r * sin(phi);
|
|
|
|
ret[2] = 0;
|
|
|
|
|
|
|
|
ret[0] -= pow(0.5, 1-mt);
|
|
|
|
ret[0] /= -(1-mt) * M_PI / 2;
|
|
|
|
ret[1] /= (1-mt) * M_PI / 2;
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(ret[1], ret[0]);
|
2018-11-06 14:53:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
makeband(H, ret, band_conformal);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mdTwoPoint:
|
|
|
|
makeband(H, ret, make_twopoint);
|
|
|
|
break;
|
|
|
|
|
2019-08-14 06:23:09 +00:00
|
|
|
case mdMollweide:
|
|
|
|
makeband(H, ret, [] (ld& x, ld& y) {
|
|
|
|
ld theta =
|
|
|
|
hyperbolic ? min(y / 2 + 0.572365, y * 0.78509) :
|
|
|
|
euclid ? y :
|
|
|
|
y > 0 ? max(y * 0.012/0.015, M_PI/2 - (M_PI/2-y) * 0.066262/0.015708) :
|
|
|
|
min(y * 0.012/0.015, -M_PI/2 + (M_PI/2+y) * 0.066262/0.015708);
|
|
|
|
|
|
|
|
if(sphere && abs(theta) >= M_PI/2 - 1e-6) ;
|
|
|
|
else {
|
|
|
|
for(int it=0; it<4; it++) {
|
|
|
|
auto a = (sin_auto(2*theta) +2*theta - M_PI * sin_auto(y));
|
|
|
|
auto b = (2 + 2 * cos_auto(2*theta));
|
|
|
|
theta = theta - a / b;
|
|
|
|
} }
|
|
|
|
y = M_PI * sin_auto(theta) / 2;
|
|
|
|
x = x * cos_auto(theta);
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
2019-08-14 15:13:20 +00:00
|
|
|
case mdCentralCyl:
|
2019-08-14 19:08:45 +00:00
|
|
|
makeband(H, ret, [] (ld& x, ld& y) { y = tan_auto(y); ld top = vid.yres * M_PI / current_display->radius; if(y>top) y=top; if(y<-top) y=-top; });
|
2019-08-14 15:13:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case mdCollignon:
|
2019-08-14 16:59:21 +00:00
|
|
|
find_zlev(H);
|
2019-08-14 15:13:20 +00:00
|
|
|
makeband(H, ret, [] (ld& x, ld& y) {
|
2019-08-14 16:59:21 +00:00
|
|
|
ld sgn = 1;
|
|
|
|
if(vid.collignon_reflected && y > 0) y = -y, sgn = -1;
|
|
|
|
y = signed_sqrt(sin_auto(y) + vid.collignon_parameter);
|
|
|
|
x *= y / 1.2;
|
|
|
|
y -= signed_sqrt(vid.collignon_parameter);
|
|
|
|
y *= sgn;
|
|
|
|
y *= M_PI;
|
2019-08-14 15:13:20 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdBandEquiarea:
|
|
|
|
makeband(H, ret, [] (ld& x, ld& y) { y = sin_auto(y); });
|
|
|
|
break;
|
2018-10-23 14:58:19 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdBandEquidistant:
|
|
|
|
makeband(H, ret, [] (ld& x, ld& y) { });
|
|
|
|
break;
|
2018-10-23 14:58:19 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdSinusoidal:
|
|
|
|
makeband(H, ret, [] (ld& x, ld& y) { x *= cos_auto(y); });
|
|
|
|
break;
|
2018-03-26 17:06:47 +00:00
|
|
|
|
2019-03-30 16:45:56 +00:00
|
|
|
case mdEquidistant: case mdEquiarea: case mdEquivolume: {
|
2019-08-14 18:44:31 +00:00
|
|
|
if(nonisotropic) {
|
|
|
|
H = nisot::inverse_exp(H, nisot::iTable, false);
|
|
|
|
if(nisot::local_perspective_used()) H = nisot::local_perspective * H;
|
|
|
|
ret = H; ret[3] = 1;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
|
2019-08-15 13:05:43 +00:00
|
|
|
ld rad = hypot_d(GDIM, H);
|
2018-11-06 14:53:50 +00:00
|
|
|
if(rad == 0) rad = 1;
|
|
|
|
ld d = hdist0(H);
|
|
|
|
ld df, zf;
|
|
|
|
hypot_zlev(zlev, d, df, zf);
|
|
|
|
|
|
|
|
// 4 pi / 2pi = M_PI
|
|
|
|
|
2019-03-30 16:45:56 +00:00
|
|
|
if(pmodel == mdEquivolume)
|
|
|
|
d = pow(volume_auto(d), 1/3.) * pow(M_PI / 2, 1/3.);
|
|
|
|
else if(pmodel == mdEquiarea && sphere)
|
2018-11-06 14:53:50 +00:00
|
|
|
d = sqrt(2*(1 - cos(d))) * M_PI / 2;
|
|
|
|
else if(pmodel == mdEquiarea && hyperbolic)
|
|
|
|
d = sqrt(2*(cosh(d) - 1)) / 1.5;
|
|
|
|
|
|
|
|
ret = H * (d * df / rad / M_PI);
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 2) ret[2] = 0;
|
2019-03-20 01:10:53 +00:00
|
|
|
if(MAXMDIM == 4) ret[3] = 1;
|
2018-11-17 18:24:02 +00:00
|
|
|
if(zlev != 1 && current_display->stereo_active())
|
2018-11-06 14:53:50 +00:00
|
|
|
apply_depth(ret, d * zf / M_PI);
|
|
|
|
|
|
|
|
break;
|
2018-03-25 13:27:42 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2018-11-06 23:52:48 +00:00
|
|
|
case mdRotatedHyperboles: {
|
|
|
|
// ld zlev = <- not implemented
|
2019-05-29 14:27:24 +00:00
|
|
|
find_zlev(H); // + vid.depth;
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-11-06 23:52:48 +00:00
|
|
|
|
|
|
|
ld y = asin_auto(H[1]);
|
|
|
|
ld x = asin_auto_clamp(H[0] / cos_auto(y));
|
|
|
|
// ld z = zlev == 1 ? 0 : geom3::factor_to_lev(zlev);
|
|
|
|
|
2019-05-29 14:27:24 +00:00
|
|
|
ld factor = geom3::lev_to_factor(y + vid.depth);
|
2018-11-06 23:52:48 +00:00
|
|
|
|
|
|
|
ret[0] = sinh(x) * factor;
|
|
|
|
ret[1] = cosh(x) * factor;
|
|
|
|
ret[2] = 0;
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
if(models::use_atan) {
|
2018-12-24 00:10:55 +00:00
|
|
|
ret[0] = atan(ret[0]);
|
|
|
|
ret[1] = atan(ret[1]);
|
|
|
|
}
|
2018-11-06 23:52:48 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdFormula: {
|
2019-08-09 22:58:50 +00:00
|
|
|
dynamicval<eModel> m(pmodel, models::basic_model);
|
2018-11-06 23:52:48 +00:00
|
|
|
applymodel(H, ret);
|
|
|
|
exp_parser ep;
|
|
|
|
ep.extra_params["z"] = cld(ret[0], ret[1]);
|
|
|
|
ep.extra_params["cx"] = ret[0];
|
|
|
|
ep.extra_params["cy"] = ret[1];
|
|
|
|
ep.extra_params["cz"] = ret[2];
|
2018-11-07 06:21:42 +00:00
|
|
|
ep.extra_params["ux"] = H[0];
|
|
|
|
ep.extra_params["uy"] = H[1];
|
|
|
|
ep.extra_params["uz"] = H[2];
|
2019-08-09 22:58:50 +00:00
|
|
|
ep.s = models::formula;
|
2018-11-06 23:52:48 +00:00
|
|
|
cld res = ep.parse();
|
|
|
|
ret[0] = real(res);
|
|
|
|
ret[1] = imag(res);
|
|
|
|
ret[2] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:15:00 +00:00
|
|
|
case mdSpiral: {
|
2018-11-10 15:56:08 +00:00
|
|
|
cld z;
|
2019-04-03 18:30:35 +00:00
|
|
|
if(hyperbolic || sphere) makeband(H, ret, band_conformal);
|
2018-11-10 15:56:08 +00:00
|
|
|
else ret = H;
|
2019-08-09 22:58:50 +00:00
|
|
|
z = cld(ret[0], ret[1]) * models::spiral_multiplier;
|
2018-12-21 13:42:59 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
if(models::spiral_cone < 360) {
|
|
|
|
ld alpha = imag(z) * 360 / models::spiral_cone;
|
2018-12-21 13:42:59 +00:00
|
|
|
ld r = real(z);
|
|
|
|
r = exp(r);
|
|
|
|
|
|
|
|
ret[0] = -sin(alpha) * r;
|
|
|
|
ret[1] = cos(alpha) * r;
|
2019-08-09 22:58:50 +00:00
|
|
|
ret[2] = (r-1) * sqrt( pow(360/models::spiral_cone, 2) - 1);
|
2018-12-21 13:42:59 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_ball(ret[2], ret[1]);
|
2018-12-21 13:42:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
z = exp(z);
|
|
|
|
ret[0] = real(z);
|
|
|
|
ret[1] = imag(z);
|
2018-11-09 13:15:00 +00:00
|
|
|
|
2018-12-21 13:42:59 +00:00
|
|
|
if(vid.skiprope)
|
|
|
|
ret = mobius(ret, vid.skiprope, 1);
|
|
|
|
}
|
2018-11-09 13:15:00 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:37:27 +00:00
|
|
|
case mdGUARD: case mdRug: break;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
2019-02-06 21:41:45 +00:00
|
|
|
ghcheck(ret,H_orig);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// game-related graphics
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix sphereflip; // on the sphere, flip
|
|
|
|
EX bool playerfound; // has player been found in the last drawing?
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
double q3 = sqrt(double(3));
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool outofmap(hyperpoint h) {
|
2019-05-09 15:02:50 +00:00
|
|
|
if(GDIM == 3)
|
|
|
|
return false;
|
|
|
|
else if(euclid)
|
2019-05-26 16:04:02 +00:00
|
|
|
return h[2] < .5; // false; // h[0] * h[0] + h[1] * h[1] > 15 * cgi.crossf;
|
2017-07-10 18:47:38 +00:00
|
|
|
else if(sphere)
|
|
|
|
return h[2] < .1 && h[2] > -.1 && h[1] > -.1 && h[1] < .1 && h[0] > -.1 && h[0] < .1;
|
|
|
|
else
|
|
|
|
return h[2] < .5;
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX hyperpoint mirrorif(const hyperpoint& V, bool b) {
|
2017-07-10 18:47:38 +00:00
|
|
|
if(b) return Mirror*V;
|
|
|
|
else return V;
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX transmatrix mirrorif(const transmatrix& V, bool b) {
|
2017-07-16 21:00:55 +00:00
|
|
|
if(b) return V*Mirror;
|
|
|
|
else return V;
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
// -1 if away, 0 if not away
|
|
|
|
int away(const transmatrix& V2) {
|
2017-10-06 22:33:32 +00:00
|
|
|
return (intval(C0, V2 * xpush0(.1)) > intval(C0, tC0(V2))) ? -1 : 0;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* double zgrad(double f1, double f2, int nom, int den) {
|
|
|
|
using namespace geom3;
|
|
|
|
ld fo1 = factor_to_lev(f1);
|
|
|
|
ld fo2 = factor_to_lev(f2);
|
|
|
|
return lev_to_factor(fo1 + (fo2-fo1) * nom / den);
|
|
|
|
} */
|
|
|
|
|
|
|
|
double zgrad0(double l1, double l2, int nom, int den) {
|
|
|
|
using namespace geom3;
|
|
|
|
return lev_to_factor(l1 + (l2-l1) * nom / den);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool behindsphere(const hyperpoint& h) {
|
2017-07-10 18:47:38 +00:00
|
|
|
if(!sphere) return false;
|
|
|
|
|
2018-04-22 09:11:47 +00:00
|
|
|
if(mdBandAny()) return false;
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
if(vid.alpha > 1) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(h[LDIM] > -1/vid.alpha) return true;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.alpha <= 1) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(h[LDIM] < .2-vid.alpha) return true;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-09 09:46:49 +00:00
|
|
|
ld to01(ld a0, ld a1, ld x) {
|
|
|
|
if(x < a0) return 0;
|
|
|
|
if(x > a1) return 1;
|
|
|
|
return (x-a0) / (a1-a0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ld spherity(const hyperpoint& h) {
|
|
|
|
if(!sphere) return 1;
|
|
|
|
|
|
|
|
if(vid.alpha > 1) {
|
|
|
|
return to01(1/vid.alpha, 1, -h[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.alpha <= 1) {
|
2017-11-03 18:20:54 +00:00
|
|
|
return to01(-1.5, 1, h[2]);
|
2017-10-09 09:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool behindsphere(const transmatrix& V) {
|
2017-07-10 18:47:38 +00:00
|
|
|
return behindsphere(tC0(V));
|
|
|
|
}
|
|
|
|
|
2017-10-09 09:46:49 +00:00
|
|
|
ld spherity(const transmatrix& V) {
|
|
|
|
return spherity(tC0(V));
|
|
|
|
}
|
|
|
|
|
2019-08-09 20:07:03 +00:00
|
|
|
EX bool confusingGeometry() {
|
2018-11-30 14:26:50 +00:00
|
|
|
return quotient;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 20:07:03 +00:00
|
|
|
EX ld master_to_c7_angle() {
|
2019-05-26 16:04:02 +00:00
|
|
|
ld alpha = 0;
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2019-05-26 16:04:02 +00:00
|
|
|
if(cgi.gpdata) alpha = cgi.gpdata->alpha;
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
return (!BITRUNCATED && !binarytiling && !archimedean) ? M_PI + alpha : 0;
|
2018-04-10 15:06:04 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 20:07:03 +00:00
|
|
|
EX transmatrix actualV(const heptspin& hs, const transmatrix& V) {
|
2019-05-08 16:33:08 +00:00
|
|
|
if(WDIM == 3) return V;
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_IRR
|
2018-08-28 15:17:34 +00:00
|
|
|
if(IRREGULAR)
|
2018-08-17 22:46:45 +00:00
|
|
|
return V * spin(M_PI + 2 * M_PI / S7 * (hs.spin + irr::periodmap[hs.at].base.spin));
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_ARCM
|
2018-08-20 00:02:45 +00:00
|
|
|
if(archimedean) return V * spin(-arcm::current.triangles[arcm::id_of(hs.at)][hs.spin].first);
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
|
|
|
#if CAP_BT
|
2018-08-14 07:16:30 +00:00
|
|
|
if(binarytiling) return V;
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2019-08-02 15:55:40 +00:00
|
|
|
if(penrose) return V;
|
2018-08-28 15:17:34 +00:00
|
|
|
return (hs.spin || !BITRUNCATED) ? V * spin(hs.spin*2*M_PI/S7 + master_to_c7_angle()) : V;
|
2017-12-16 08:03:50 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool point_behind(hyperpoint h) {
|
2019-07-31 14:14:01 +00:00
|
|
|
if(sphere) return false;
|
|
|
|
if(!in_perspective()) return false;
|
2019-08-06 14:48:01 +00:00
|
|
|
if(pmodel == mdGeodesic) h = nisot::inverse_exp(h, nisot::iLazy);
|
2019-08-06 10:00:46 +00:00
|
|
|
if(nisot::local_perspective_used()) h = nisot::local_perspective * h;
|
2019-02-21 17:46:53 +00:00
|
|
|
return h[2] < 0;
|
|
|
|
}
|
|
|
|
|
2019-05-29 18:21:19 +00:00
|
|
|
void raise_error() {
|
|
|
|
println(hlog, "something wrong");
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool invalid_matrix(const transmatrix T) {
|
2019-08-15 13:05:43 +00:00
|
|
|
for(int i=0; i<GDIM; i++) for(int j=0; j<GDIM; j++)
|
2019-05-29 18:21:19 +00:00
|
|
|
if(std::isnan(T[i][j]) || T[i][j] > 1e8 || T[i][j] < -1e8 || std::isinf(T[i][j]))
|
|
|
|
return true;
|
2019-08-17 21:28:41 +00:00
|
|
|
if(prod) {
|
|
|
|
for(int i=0; i<GDIM; i++) for(int j=0; j<GDIM; j++) if(abs(T[i][j]) > 1e-6) return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
for(int i=0; i<GDIM; i++) for(int j=0; j<GDIM; j++) if(T[i][j] > .5 || T[i][j] < -.5) return false;
|
2019-05-29 18:21:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool invalid_point(const hyperpoint h) {
|
2019-08-17 21:28:41 +00:00
|
|
|
return std::isnan(h[LDIM]) || h[LDIM] > 1e8 || std::isinf(h[LDIM]);
|
2018-12-04 21:40:29 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool in_smart_range(const transmatrix& T) {
|
2019-07-31 14:14:01 +00:00
|
|
|
hyperpoint h = tC0(T);
|
|
|
|
if(invalid_point(h)) return false;
|
2019-08-06 19:01:00 +00:00
|
|
|
if(nil) return true;
|
2019-08-06 14:48:01 +00:00
|
|
|
if(pmodel == mdGeodesic) return solv::in_table_range(h);
|
2019-03-21 18:13:45 +00:00
|
|
|
hyperpoint h1;
|
2019-07-31 14:14:01 +00:00
|
|
|
applymodel(h, h1);
|
|
|
|
if(invalid_point(h1)) return false;
|
2018-11-17 18:24:02 +00:00
|
|
|
ld x = current_display->xcenter + current_display->radius * h1[0];
|
|
|
|
ld y = current_display->ycenter + current_display->radius * h1[1] * vid.stretch;
|
2018-12-01 22:48:21 +00:00
|
|
|
|
2019-03-21 18:13:45 +00:00
|
|
|
if(x > current_display->xtop + current_display->xsize * 2) return false;
|
2018-12-01 22:48:21 +00:00
|
|
|
if(x < current_display->xtop - current_display->xsize * 1) return false;
|
2019-03-21 18:13:45 +00:00
|
|
|
if(y > current_display->ytop + current_display->ysize * 2) return false;
|
2018-12-01 22:48:21 +00:00
|
|
|
if(y < current_display->ytop - current_display->ysize * 1) return false;
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) {
|
2019-08-09 22:58:50 +00:00
|
|
|
if(-h1[2] < models::clip_min * 2 - models::clip_max) return false;
|
|
|
|
if(-h1[2] > models::clip_max * 2 - models::clip_min) return false;
|
2019-03-21 18:13:45 +00:00
|
|
|
}
|
2018-12-01 22:48:21 +00:00
|
|
|
|
2018-11-01 17:59:25 +00:00
|
|
|
ld epsilon = 0.01;
|
2019-03-21 18:13:45 +00:00
|
|
|
|
|
|
|
ld dx = 0, dy = 0, dz = 0, dh[MAXMDIM];
|
2019-08-15 13:05:43 +00:00
|
|
|
for(int i=0; i<GDIM; i++) {
|
2019-03-21 18:13:45 +00:00
|
|
|
hyperpoint h2;
|
|
|
|
applymodel(T * cpush0(i, epsilon), h2);
|
|
|
|
ld x1 = current_display->radius * abs(h2[0] - h1[0]) / epsilon;
|
|
|
|
ld y1 = current_display->radius * abs(h2[1] - h1[1]) * vid.stretch / epsilon;
|
|
|
|
dx = max(dx, x1); dy = max(dy, y1);
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) dz = max(dz, abs(h2[2] - h1[2]));
|
2019-03-21 18:13:45 +00:00
|
|
|
dh[i] = hypot(x1, y1);
|
|
|
|
}
|
|
|
|
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) {
|
2019-08-09 22:58:50 +00:00
|
|
|
if(-h1[2] + 2 * dz < models::clip_min || -h1[2] - 2 * dz > models::clip_max) return false;
|
2019-08-15 13:05:43 +00:00
|
|
|
sort(dh, dh+GDIM);
|
2019-05-26 16:04:02 +00:00
|
|
|
ld scale = sqrt(dh[1] * dh[2]) * cgi.scalefactor * hcrossf7;
|
2019-05-11 18:15:09 +00:00
|
|
|
if(scale <= (WDIM == 2 ? vid.smart_range_detail : vid.smart_range_detail_3)) return false;
|
2019-03-21 18:13:45 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-26 16:04:02 +00:00
|
|
|
ld scale = sqrt(dh[0] * dh[1]) * cgi.scalefactor * hcrossf7;
|
2019-03-21 18:13:45 +00:00
|
|
|
if(scale <= vid.smart_range_detail) return false;
|
|
|
|
}
|
|
|
|
|
2018-11-01 17:59:25 +00:00
|
|
|
return
|
2019-03-21 18:13:45 +00:00
|
|
|
x - 2 * dx < current_display->xtop + current_display->xsize &&
|
|
|
|
x + 2 * dx > current_display->xtop &&
|
|
|
|
y - 2 * dy < current_display->ytop + current_display->ysize &&
|
|
|
|
y + 2 * dy > current_display->ytop;
|
2018-11-01 17:59:25 +00:00
|
|
|
}
|
|
|
|
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_GP
|
2018-04-09 15:40:12 +00:00
|
|
|
namespace gp {
|
2018-04-03 21:39:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
void drawrec(cell *c, const transmatrix& V) {
|
|
|
|
if(dodrawcell(c))
|
|
|
|
drawcell(c, V, 0, false);
|
|
|
|
for(int i=0; i<c->type; i++) {
|
2018-08-17 22:46:45 +00:00
|
|
|
cell *c2 = c->move(i);
|
2018-04-03 21:39:18 +00:00
|
|
|
if(!c2) continue;
|
2018-08-17 22:46:45 +00:00
|
|
|
if(c2->move(0) != c) continue;
|
2018-04-03 21:39:18 +00:00
|
|
|
if(c2 == c2->master->c7) continue;
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V1 = V * ddspin(c, i) * xpush(cgi.crossf) * iddspin(c2, 0) * spin(M_PI);
|
2018-04-03 21:39:18 +00:00
|
|
|
drawrec(c2, V1);
|
|
|
|
}
|
|
|
|
} */
|
2018-05-04 00:47:14 +00:00
|
|
|
|
2018-11-19 17:58:09 +00:00
|
|
|
bool drawrec(cell *c, const transmatrix& V, gp::loc at, int dir, int maindir) {
|
|
|
|
bool res = false;
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V1 = V * cgi.gpdata->Tf[draw_li.last_dir][at.first&31][at.second&31][fixg6(dir)];
|
2018-11-23 22:45:16 +00:00
|
|
|
if(do_draw(c, V1)) {
|
2018-05-07 18:11:04 +00:00
|
|
|
/* auto li = get_local_info(c);
|
2019-08-09 12:12:33 +00:00
|
|
|
if((dir - li.total_dir) % S6) printf("totaldir %d/%d\n", dir, li.total_dir);
|
2018-04-05 22:40:53 +00:00
|
|
|
if(at != li.relative) printf("at %s/%s\n", disp(at), disp(li.relative));
|
|
|
|
if(maindir != li.last_dir) printf("ld %d/%d\n", maindir, li.last_dir); */
|
2018-05-04 00:46:44 +00:00
|
|
|
draw_li.relative = at;
|
2018-07-10 02:13:35 +00:00
|
|
|
draw_li.total_dir = fixg6(dir);
|
2018-11-10 13:26:49 +00:00
|
|
|
drawcell(c, V1, 0, false);
|
2018-11-19 17:58:09 +00:00
|
|
|
res = true;
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
for(int i=0; i<c->type; i++) {
|
2018-08-17 22:46:45 +00:00
|
|
|
cell *c2 = c->move(i);
|
2018-04-03 21:39:18 +00:00
|
|
|
if(!c2) continue;
|
2018-08-17 22:46:45 +00:00
|
|
|
if(c2->move(0) != c) continue;
|
2018-04-03 21:39:18 +00:00
|
|
|
if(c2 == c2->master->c7) continue;
|
2018-11-19 17:58:09 +00:00
|
|
|
res |= drawrec(c2, V, at + eudir(dir+i), dir + i + SG3, maindir);
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
2018-11-19 17:58:09 +00:00
|
|
|
return res;
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
|
2018-11-19 17:58:09 +00:00
|
|
|
bool drawrec(cell *c, const transmatrix& V) {
|
2018-05-04 00:46:44 +00:00
|
|
|
draw_li.relative = loc(0,0);
|
|
|
|
draw_li.total_dir = 0;
|
2018-05-07 18:13:56 +00:00
|
|
|
draw_li.last_dir = -1;
|
2018-11-19 17:58:09 +00:00
|
|
|
bool res = false;
|
2018-11-10 13:26:49 +00:00
|
|
|
if(do_draw(c, V))
|
2018-11-19 17:58:09 +00:00
|
|
|
drawcell(c, V, 0, false), res = true;
|
2018-04-03 21:39:18 +00:00
|
|
|
for(int i=0; i<c->type; i++) {
|
2018-08-17 22:46:45 +00:00
|
|
|
cell *c2 = c->move(i);
|
2018-04-03 21:39:18 +00:00
|
|
|
if(!c2) continue;
|
2018-08-17 22:46:45 +00:00
|
|
|
if(c2->move(0) != c) continue;
|
2018-04-03 21:39:18 +00:00
|
|
|
if(c2 == c2->master->c7) continue;
|
2018-05-04 00:46:44 +00:00
|
|
|
draw_li.last_dir = i;
|
2018-11-19 17:58:09 +00:00
|
|
|
res |= drawrec(c2, V, gp::loc(1,0), SG3, i);
|
2018-04-03 23:19:21 +00:00
|
|
|
}
|
2018-11-19 17:58:09 +00:00
|
|
|
return res;
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-04-11 11:16:40 +00:00
|
|
|
|
2018-11-23 22:45:16 +00:00
|
|
|
vector<tuple<heptspin, hstate, transmatrix, ld> > drawn_cells;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2019-04-03 18:30:35 +00:00
|
|
|
bool in_multi = false;
|
|
|
|
|
2019-03-08 21:38:44 +00:00
|
|
|
void hrmap_standard::draw() {
|
2019-04-03 18:30:35 +00:00
|
|
|
if(sphere && pmodel == mdSpiral && !in_multi) {
|
|
|
|
in_multi = true;
|
2019-08-09 22:58:50 +00:00
|
|
|
if(models::ring_not_spiral) {
|
|
|
|
int qty = ceil(1. / models::sphere_spiral_multiplier);
|
2019-04-03 18:30:35 +00:00
|
|
|
if(qty > 100) qty = 100;
|
|
|
|
for(int i=-qty; i < qty; i++) {
|
|
|
|
band_shift = 2 * M_PI * i;
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
draw();
|
|
|
|
if(vid.use_smart_range) for(int i=1;; i++) {
|
|
|
|
int drawn = cells_drawn;
|
|
|
|
band_shift = 2 * M_PI * i;
|
|
|
|
draw();
|
|
|
|
band_shift = -2 * M_PI * i;
|
|
|
|
draw();
|
|
|
|
if(drawn == cells_drawn) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in_multi = false;
|
|
|
|
return;
|
|
|
|
}
|
2018-11-23 22:45:16 +00:00
|
|
|
drawn_cells.clear();
|
|
|
|
drawn_cells.emplace_back(viewctr, hsOrigin, cview(), band_shift);
|
2018-11-30 16:17:06 +00:00
|
|
|
for(int i=0; i<isize(drawn_cells); i++) {
|
|
|
|
// prevent reallocation due to insertion
|
|
|
|
if(drawn_cells.capacity() < drawn_cells.size() + 16)
|
2018-12-13 13:54:26 +00:00
|
|
|
drawn_cells.reserve(max<size_t>(2 * drawn_cells.size(), 128));
|
2018-11-30 16:17:06 +00:00
|
|
|
|
2018-11-23 22:45:16 +00:00
|
|
|
const auto& dc = drawn_cells[i];
|
|
|
|
auto& hs = get<0>(dc);
|
|
|
|
auto& s = get<1>(dc);
|
|
|
|
auto& V = get<2>(dc);
|
|
|
|
dynamicval<ld> bs(band_shift, get<3>(dc));
|
2018-11-10 13:26:49 +00:00
|
|
|
|
2018-11-23 22:45:16 +00:00
|
|
|
cell *c = hs.at->c7;
|
|
|
|
|
|
|
|
transmatrix V10;
|
|
|
|
const transmatrix& V1 = hs.mirrored ? (V10 = V * Mirror) : V;
|
|
|
|
|
|
|
|
bool draw = false;
|
|
|
|
|
2019-02-17 17:28:20 +00:00
|
|
|
if(0) ;
|
|
|
|
|
|
|
|
#if CAP_GP
|
|
|
|
else if(GOLDBERG) {
|
2018-11-23 22:45:16 +00:00
|
|
|
draw = gp::drawrec(c, actualV(hs, V1));
|
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-11-23 22:45:16 +00:00
|
|
|
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_IRR
|
2018-11-23 22:45:16 +00:00
|
|
|
else if(IRREGULAR) {
|
|
|
|
auto& hi = irr::periodmap[hs.at];
|
|
|
|
transmatrix V0 = actualV(hs, V1);
|
|
|
|
auto& vc = irr::cells_of_heptagon[hi.base.at];
|
|
|
|
for(int i=0; i<isize(vc); i++) {
|
|
|
|
cell *c = hi.subcells[i];
|
|
|
|
transmatrix V1 = V0 * irr::cells[vc[i]].pusher;
|
|
|
|
if(do_draw(c, V1))
|
2018-11-10 13:26:49 +00:00
|
|
|
draw = true,
|
2018-11-23 22:45:16 +00:00
|
|
|
drawcell(hi.subcells[i], V0 * irr::cells[vc[i]].pusher, 0, false);
|
2018-04-11 11:16:40 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-11-23 22:45:16 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
if(do_draw(c, V1)) {
|
|
|
|
transmatrix V2 = actualV(hs, V1);
|
|
|
|
drawcell(c, V2, 0, hs.mirrored);
|
|
|
|
draw = true;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-11-23 22:45:16 +00:00
|
|
|
if(BITRUNCATED) for(int d=0; d<S7; d++) {
|
|
|
|
int ds = hs.at->c.fix(hs.spin + d);
|
|
|
|
// createMov(c, ds);
|
|
|
|
if(c->move(ds) && c->c.spin(ds) == 0) {
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix V2 = V1 * cgi.hexmove[d];
|
2018-11-23 22:45:16 +00:00
|
|
|
if(do_draw(c->move(ds), V2))
|
|
|
|
draw = true,
|
|
|
|
drawcell(c->move(ds), V2, 0, hs.mirrored ^ c->c.mirror(ds));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-03 18:30:35 +00:00
|
|
|
|
|
|
|
if(sphere) draw = true;
|
2018-11-23 22:45:16 +00:00
|
|
|
|
|
|
|
if(draw) for(int d=0; d<S7; d++) {
|
|
|
|
hstate s2 = transition(s, d);
|
|
|
|
if(s2 == hsError) continue;
|
|
|
|
heptspin hs2 = hs + d + wstep;
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix Vd = V * cgi.heptmove[d];
|
2018-11-23 22:45:16 +00:00
|
|
|
bandfixer bf(Vd);
|
|
|
|
drawn_cells.emplace_back(hs2, s2, Vd, band_shift);
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int mindx=-7, mindy=-7, maxdx=7, maxdy=7;
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX transmatrix eumove(ld x, ld y) {
|
2017-07-10 18:47:38 +00:00
|
|
|
transmatrix Mat = Id;
|
2019-08-17 21:28:41 +00:00
|
|
|
Mat[LDIM][LDIM] = 1;
|
2017-12-18 12:00:36 +00:00
|
|
|
|
|
|
|
if(a4) {
|
2019-08-17 21:28:41 +00:00
|
|
|
Mat[0][LDIM] += x * cgi.crossf;
|
|
|
|
Mat[1][LDIM] += y * cgi.crossf;
|
2017-12-18 12:00:36 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-08-17 21:28:41 +00:00
|
|
|
Mat[0][LDIM] += (x + y * .5) * cgi.crossf;
|
|
|
|
// Mat[LDIM][0] += (x + y * .5) * cgi.crossf;
|
|
|
|
Mat[1][LDIM] += y * q3 /2 * cgi.crossf;
|
|
|
|
// Mat[LDIM][1] += y * q3 /2 * cgi.crossf;
|
2017-12-18 12:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ld v = a4 ? 1 : q3;
|
|
|
|
|
2019-08-17 21:28:41 +00:00
|
|
|
while(Mat[0][LDIM] <= -16384 * cgi.crossf) Mat[0][LDIM] += 32768 * cgi.crossf;
|
|
|
|
while(Mat[0][LDIM] >= 16384 * cgi.crossf) Mat[0][LDIM] -= 32768 * cgi.crossf;
|
|
|
|
while(Mat[1][LDIM] <= -16384 * v * cgi.crossf) Mat[1][LDIM] += 32768 * v * cgi.crossf;
|
|
|
|
while(Mat[1][LDIM] >= 16384 * v * cgi.crossf) Mat[1][LDIM] -= 32768 * v * cgi.crossf;
|
2017-07-10 18:47:38 +00:00
|
|
|
return Mat;
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX transmatrix eumove(int vec) {
|
2017-12-28 15:46:10 +00:00
|
|
|
int x, y;
|
|
|
|
tie(x,y) = vec_to_pair(vec);
|
|
|
|
return eumove(x, y);
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX transmatrix eumovedir(int d) {
|
2017-12-18 12:00:36 +00:00
|
|
|
if(a4) {
|
|
|
|
d = d & 3;
|
|
|
|
switch(d) {
|
|
|
|
case 0: return eumove(1,0);
|
|
|
|
case 1: return eumove(0,1);
|
|
|
|
case 2: return eumove(-1,0);
|
|
|
|
case 3: return eumove(0,-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-08-09 12:12:33 +00:00
|
|
|
d = gmod(d, S6);
|
2017-12-18 12:00:36 +00:00
|
|
|
switch(d) {
|
|
|
|
case 0: return eumove(1,0);
|
|
|
|
case 1: return eumove(0,1);
|
|
|
|
case 2: return eumove(-1,1);
|
|
|
|
case 3: return eumove(-1,0);
|
|
|
|
case 4: return eumove(0,-1);
|
|
|
|
case 5: return eumove(1,-1);
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
return eumove(0,0);
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void spinEdge(ld aspd) {
|
2019-05-13 13:09:24 +00:00
|
|
|
ld downspin = 0;
|
2019-05-28 23:09:38 +00:00
|
|
|
if(dual::state == 2 && dual::currently_loaded != dual::main_side) {
|
2019-06-24 21:00:12 +00:00
|
|
|
transmatrix our = dual::get_orientation();
|
2019-05-28 23:09:38 +00:00
|
|
|
transmatrix their = dual::player_orientation[dual::main_side];
|
|
|
|
fixmatrix(our);
|
|
|
|
fixmatrix(their);
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 2) {
|
2019-05-28 23:09:38 +00:00
|
|
|
transmatrix T = their * inverse(our);
|
|
|
|
hyperpoint H = T * xpush0(1);
|
|
|
|
downspin = -atan2(H[1], H[0]);
|
|
|
|
}
|
|
|
|
else View = their * inverse(our) * View;
|
|
|
|
}
|
|
|
|
else if(playerfound && vid.fixed_facing) {
|
2019-01-17 13:09:00 +00:00
|
|
|
hyperpoint H = gpushxto0(playerV * C0) * playerV * xpush0(5);
|
|
|
|
downspin = atan2(H[1], H[0]);
|
|
|
|
downspin += vid.fixed_facing_dir * degree;
|
|
|
|
if(flipplayer) downspin += M_PI;
|
|
|
|
while(downspin < -M_PI) downspin += 2*M_PI;
|
|
|
|
while(downspin > +M_PI) downspin -= 2*M_PI;
|
|
|
|
aspd = (1 + 2 * abs(downspin)) * aspd;
|
|
|
|
}
|
2019-06-28 07:56:39 +00:00
|
|
|
else if(WDIM == 2 && GDIM == 3 && vid.fixed_yz && !CAP_ORIENTATION) {
|
2019-05-13 13:09:24 +00:00
|
|
|
aspd = 999999;
|
|
|
|
if(straightDownSeek) {
|
|
|
|
if(straightDownPoint[0])
|
2019-08-09 22:58:50 +00:00
|
|
|
downspin = models::rotation * degree - atan2(straightDownPoint[0], straightDownPoint[1]);
|
2019-05-13 13:09:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(View[0][2])
|
|
|
|
downspin = -atan2(View[0][2], View[1][2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(straightDownSeek) {
|
|
|
|
downspin = atan2(straightDownPoint[1], straightDownPoint[0]);
|
|
|
|
downspin -= M_PI/2;
|
2019-08-09 22:58:50 +00:00
|
|
|
downspin += models::rotation * degree;
|
2019-05-13 13:09:24 +00:00
|
|
|
while(downspin < -M_PI) downspin += 2*M_PI;
|
|
|
|
while(downspin > +M_PI) downspin -= 2*M_PI;
|
|
|
|
downspin = downspin * min(straightDownSpeed, (double)1);
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
if(downspin > aspd) downspin = aspd;
|
|
|
|
if(downspin < -aspd) downspin = -aspd;
|
2019-05-13 13:09:24 +00:00
|
|
|
View = spin(downspin) * View;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void centerpc(ld aspd) {
|
2018-12-04 17:10:36 +00:00
|
|
|
|
2019-03-09 15:20:06 +00:00
|
|
|
if(subscreens::split([=] () {centerpc(aspd);})) return;
|
2019-05-28 23:09:38 +00:00
|
|
|
if(dual::split([=] () { centerpc(aspd); })) return;
|
2019-03-09 15:20:06 +00:00
|
|
|
|
2019-02-17 17:28:20 +00:00
|
|
|
#if CAP_CRYSTAL
|
2018-12-04 17:10:36 +00:00
|
|
|
if(geometry == gCrystal)
|
|
|
|
crystal::centerrug(aspd);
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2019-05-11 21:55:02 +00:00
|
|
|
|
|
|
|
#if CAP_RACING
|
|
|
|
if(racing::on && racing::set_view()) return;
|
|
|
|
#endif
|
2019-02-25 13:51:51 +00:00
|
|
|
|
2019-05-10 01:16:40 +00:00
|
|
|
#if MAXMDIM >= 4
|
2019-08-15 13:05:43 +00:00
|
|
|
if(shmup::on && vid.sspeed > -5 && GDIM == 3) {
|
2019-03-09 15:20:06 +00:00
|
|
|
int id = subscreens::in ? subscreens::current_player : 0;
|
2019-05-15 07:34:40 +00:00
|
|
|
if(masterless) centerover = shmup::pc[id]->base;
|
|
|
|
else viewctr = shmup::pc[id]->base->master;
|
2019-05-09 23:03:53 +00:00
|
|
|
transmatrix T = shmup::pc[id]->at;
|
2019-05-15 07:34:40 +00:00
|
|
|
if(WDIM == 2 && !masterless) T = master_relative(shmup::pc[id]->base) * T;
|
2019-05-09 23:03:53 +00:00
|
|
|
int sl = snakelevel(cwt.at);
|
2019-05-26 16:04:02 +00:00
|
|
|
if(sl) T = T * zpush(cgi.SLEV[sl] - cgi.FLOOR);
|
2019-05-09 23:03:53 +00:00
|
|
|
View = inverse(T);
|
2019-05-09 19:55:17 +00:00
|
|
|
if(WDIM == 2) View = cspin(0, 1, M_PI) * cspin(2, 1, M_PI/2 + shmup::playerturny[id]) * spin(-M_PI/2) * View;
|
2018-11-17 18:30:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2018-12-04 17:10:36 +00:00
|
|
|
|
2018-07-23 03:14:19 +00:00
|
|
|
if(ors::mode == 2 && vid.sspeed < 5) return;
|
2017-07-10 18:47:38 +00:00
|
|
|
if(vid.sspeed >= 4.99) aspd = 1000;
|
2019-05-12 23:57:40 +00:00
|
|
|
DEBBI(DF_GRAPH, ("center pc"));
|
2018-07-23 03:14:19 +00:00
|
|
|
|
|
|
|
ors::unrotate(cwtV); ors::unrotate(View);
|
2019-05-30 15:47:45 +00:00
|
|
|
if(invalid_matrix(cwtV)) return;
|
2018-07-23 03:14:19 +00:00
|
|
|
|
2019-05-09 23:03:53 +00:00
|
|
|
transmatrix T = cwtV;
|
2019-05-10 01:16:40 +00:00
|
|
|
#if MAXMDIM >= 4
|
|
|
|
if(GDIM == 3 && WDIM == 2) {
|
2019-06-01 17:58:07 +00:00
|
|
|
geom3::do_auto_eye();
|
2019-05-10 01:16:40 +00:00
|
|
|
int sl = snakelevel(cwt.at);
|
2019-06-24 11:34:29 +00:00
|
|
|
if(isWorm(cwt.at->monst) && sl < 3) sl++;
|
2019-06-01 17:58:07 +00:00
|
|
|
if(sl || vid.eye) T = T * zpush(cgi.SLEV[sl] - cgi.FLOOR + vid.eye);
|
2019-05-10 01:16:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
2019-05-09 23:03:53 +00:00
|
|
|
hyperpoint H = inverse(actual_view_transform) * tC0(T);
|
2019-08-17 21:28:41 +00:00
|
|
|
ld R = (zero_d(GDIM, H) && !prod) ? 0 : hdist0(H);
|
2017-07-10 18:47:38 +00:00
|
|
|
if(R < 1e-9) {
|
2018-03-25 13:07:11 +00:00
|
|
|
// either already centered or direction unknown
|
2017-07-10 18:47:38 +00:00
|
|
|
/* if(playerfoundL && playerfoundR) {
|
|
|
|
|
|
|
|
} */
|
|
|
|
spinEdge(aspd);
|
|
|
|
fixmatrix(View);
|
2018-07-23 03:14:19 +00:00
|
|
|
ors::rerotate(cwtV); ors::rerotate(View);
|
2017-07-10 18:47:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(euclid) {
|
|
|
|
// Euclidean
|
|
|
|
aspd *= (2+3*R*R);
|
|
|
|
if(aspd > R) aspd = R;
|
|
|
|
|
2019-08-15 13:05:43 +00:00
|
|
|
for(int i=0; i<GDIM; i++)
|
2019-08-17 21:28:41 +00:00
|
|
|
View[i][LDIM] -= H[i] * aspd / R;
|
2017-11-03 19:55:18 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
aspd *= (1+R+(shmup::on?1:0));
|
2019-08-17 21:28:41 +00:00
|
|
|
|
|
|
|
if(prod) {
|
|
|
|
auto d = product_decompose(H);
|
|
|
|
ld dist = -d.first / R * aspd;
|
|
|
|
if(abs(dist) > abs(d.first)) dist = -d.first;
|
2019-08-18 11:05:47 +00:00
|
|
|
View = mscale(View, dist);
|
2019-08-17 21:28:41 +00:00
|
|
|
aspd *= sqrt(R*R - d.first * d.first) / R;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
if(R < aspd) {
|
2019-08-17 23:31:37 +00:00
|
|
|
View = solmul(gpushxto0(H), Id, View);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
else
|
2019-08-17 23:31:37 +00:00
|
|
|
View = solmul(rspintox(H) * xpush(-aspd) * spintox(H), Id, View);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
fixmatrix(View);
|
|
|
|
spinEdge(aspd);
|
|
|
|
}
|
2018-07-23 03:14:19 +00:00
|
|
|
|
|
|
|
ors::rerotate(cwtV); ors::rerotate(View);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void optimizeview() {
|
2018-11-17 18:30:50 +00:00
|
|
|
|
2019-03-09 15:20:06 +00:00
|
|
|
if(subscreens::split(optimizeview)) return;
|
2019-05-28 23:09:38 +00:00
|
|
|
if(dual::split(optimizeview)) return;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2019-08-17 21:28:41 +00:00
|
|
|
if(prod) {
|
|
|
|
ld z = zlevel(tC0(View));
|
2019-08-18 11:05:47 +00:00
|
|
|
View = mscale(View, -z);
|
2019-08-18 18:56:50 +00:00
|
|
|
product::in_underlying_map(optimizeview);
|
2019-08-18 19:16:27 +00:00
|
|
|
if(z > cgi.plevel / 2) { product::current_view_level--; z -= cgi.plevel; }
|
|
|
|
if(z < -cgi.plevel / 2) { product::current_view_level++; z += cgi.plevel; }
|
2019-08-18 11:05:47 +00:00
|
|
|
View = mscale(View, z);
|
2019-08-17 21:28:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-17 17:43:39 +00:00
|
|
|
#if CAP_ANIMATIONS
|
2018-09-23 21:55:03 +00:00
|
|
|
if(centerover.at && inmirror(centerover.at)) {
|
|
|
|
anims::reflect_view();
|
|
|
|
}
|
2019-02-17 17:43:39 +00:00
|
|
|
#endif
|
2018-09-23 21:55:03 +00:00
|
|
|
|
2019-05-12 23:57:40 +00:00
|
|
|
DEBBI(DF_GRAPH, ("optimize view"));
|
2017-07-10 18:47:38 +00:00
|
|
|
int turn = 0;
|
|
|
|
ld best = INF;
|
|
|
|
|
|
|
|
transmatrix TB = Id;
|
|
|
|
|
2019-08-17 21:28:41 +00:00
|
|
|
if(false) ;
|
2019-02-17 17:28:20 +00:00
|
|
|
|
2019-02-27 22:30:26 +00:00
|
|
|
#if CAP_BT || CAP_ARCM || MAXMDIM == 4
|
2019-07-25 10:24:02 +00:00
|
|
|
else if(binarytiling || archimedean || penrose || WDIM == 3) {
|
2019-02-24 21:12:32 +00:00
|
|
|
turn = -1, best = hdist0(tC0(View));
|
2019-07-25 10:24:02 +00:00
|
|
|
for(int i=0; i<viewctr.at->type; i++) {
|
|
|
|
if(penrose && euclid && (i < 4 || i >= 8)) continue;
|
2018-08-30 14:04:28 +00:00
|
|
|
int i1 = i * DUALMUL;
|
2018-08-30 00:11:43 +00:00
|
|
|
heptagon *h2 = createStep(viewctr.at, i1);
|
2019-03-08 21:38:44 +00:00
|
|
|
transmatrix T = currentmap->relative_matrix(h2, viewctr.at);
|
2019-05-06 23:08:49 +00:00
|
|
|
#if MAXMDIM >= 4
|
2019-05-15 07:38:11 +00:00
|
|
|
if(euclid && WDIM == 3)
|
2019-04-16 01:22:52 +00:00
|
|
|
T = euclid3::move_matrix(viewctr.at->c7, i);
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2018-08-09 17:28:53 +00:00
|
|
|
hyperpoint H = View * tC0(T);
|
2019-02-24 21:12:32 +00:00
|
|
|
ld quality = hdist0(H);
|
2018-08-30 00:11:43 +00:00
|
|
|
if(quality < best) best = quality, turn = i1, TB = T;
|
2018-08-09 17:28:53 +00:00
|
|
|
}
|
|
|
|
if(turn >= 0) {
|
|
|
|
View = View * TB;
|
|
|
|
fixmatrix(View);
|
2018-08-17 22:46:45 +00:00
|
|
|
viewctr.at = createStep(viewctr.at, turn);
|
2018-08-09 17:28:53 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2019-02-17 17:28:20 +00:00
|
|
|
#endif
|
2018-08-09 17:28:53 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
for(int i=-1; i<S7; i++) {
|
|
|
|
|
|
|
|
ld trot = -i * M_PI * 2 / (S7+.0);
|
2019-05-26 16:04:02 +00:00
|
|
|
transmatrix T = i < 0 ? Id : spin(trot) * xpush(cgi.tessf) * pispin;
|
2018-08-09 17:28:53 +00:00
|
|
|
hyperpoint H = View * tC0(T);
|
2019-08-17 21:28:41 +00:00
|
|
|
if(H[LDIM] < best) best = H[LDIM], turn = i, TB = T;
|
2018-08-09 17:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(turn >= 0) {
|
|
|
|
View = View * TB;
|
|
|
|
fixmatrix(View);
|
|
|
|
viewctr = viewctr + turn + wstep;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addball(ld a, ld b, ld c) {
|
|
|
|
hyperpoint h;
|
|
|
|
ballmodel(h, a, b, c);
|
2018-11-17 18:24:02 +00:00
|
|
|
for(int i=0; i<3; i++) h[i] *= current_display->radius;
|
2017-07-10 18:47:38 +00:00
|
|
|
curvepoint(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ballgeometry() {
|
2018-08-28 12:27:23 +00:00
|
|
|
queuereset(vid.usingGL ? mdDisk : mdUnchanged, PPR::CIRCLE);
|
2017-07-10 18:47:38 +00:00
|
|
|
for(int i=0; i<60; i++)
|
|
|
|
addball(i * M_PI/30, 10, 0);
|
|
|
|
for(double d=10; d>=-10; d-=.2)
|
|
|
|
addball(0, d, 0);
|
|
|
|
for(double d=-10; d<=10; d+=.2)
|
2019-05-29 14:27:24 +00:00
|
|
|
addball(0, d, vid.depth);
|
|
|
|
addball(0, 0, -vid.camera);
|
|
|
|
addball(0, 0, vid.depth);
|
|
|
|
addball(0, 0, -vid.camera);
|
2017-07-10 18:47:38 +00:00
|
|
|
addball(0, -10, 0);
|
2019-05-29 14:27:24 +00:00
|
|
|
addball(0, 0, -vid.camera);
|
2018-08-28 12:27:23 +00:00
|
|
|
queuecurve(darkena(0xFF, 0, 0x80), 0, PPR::CIRCLE);
|
|
|
|
queuereset(pmodel, PPR::CIRCLE);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void resetview() {
|
2019-05-12 23:57:40 +00:00
|
|
|
DEBBI(DF_GRAPH, ("reset view"));
|
2019-08-09 22:58:50 +00:00
|
|
|
View = models::rotmatrix();
|
2017-07-10 18:47:38 +00:00
|
|
|
// EUCLIDEAN
|
2018-08-18 15:35:39 +00:00
|
|
|
if(!masterless)
|
2018-08-17 22:46:45 +00:00
|
|
|
viewctr.at = cwt.at->master,
|
2017-07-10 18:47:38 +00:00
|
|
|
viewctr.spin = cwt.spin;
|
2017-12-28 15:46:10 +00:00
|
|
|
else centerover = cwt;
|
2019-06-13 15:03:32 +00:00
|
|
|
cwtV = View;
|
2019-08-17 23:31:37 +00:00
|
|
|
nisot::local_perspective = Id;
|
2019-08-18 11:05:47 +00:00
|
|
|
if(prod) product::current_view_level = product::get_where(cwt.at).second;
|
2017-07-10 18:47:38 +00:00
|
|
|
// SDL_LockSurface(s);
|
|
|
|
// SDL_UnlockSurface(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-09 20:07:03 +00:00
|
|
|
EX void panning(hyperpoint hf, hyperpoint ht) {
|
2017-07-10 18:47:38 +00:00
|
|
|
View =
|
|
|
|
rgpushxto0(hf) * rgpushxto0(gpushxto0(hf) * ht) * gpushxto0(hf) * View;
|
|
|
|
playermoved = false;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX int cells_drawn, cells_generated;
|
2018-11-01 17:59:25 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void fullcenter() {
|
2019-08-09 22:58:50 +00:00
|
|
|
history::path_for_lineanimation.clear();
|
2017-07-10 18:47:38 +00:00
|
|
|
if(playerfound && false) centerpc(INF);
|
|
|
|
else {
|
|
|
|
bfs();
|
|
|
|
resetview();
|
|
|
|
drawthemap();
|
|
|
|
centerpc(INF);
|
2018-08-21 16:23:31 +00:00
|
|
|
centerover = cwt.at;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
playermoved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix screenpos(ld x, ld y) {
|
|
|
|
transmatrix V = Id;
|
2018-11-17 18:24:02 +00:00
|
|
|
V[0][2] += (x - current_display->xcenter) / current_display->radius * (1+vid.alpha);
|
|
|
|
V[1][2] += (y - current_display->ycenter) / current_display->radius * (1+vid.alpha);
|
2017-07-10 18:47:38 +00:00
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX transmatrix atscreenpos(ld x, ld y, ld size) {
|
2017-07-10 18:47:38 +00:00
|
|
|
transmatrix V = Id;
|
2019-05-12 12:35:14 +00:00
|
|
|
|
|
|
|
if(pmodel == mdFlatten) {
|
|
|
|
V[0][3] += (x - current_display->xcenter);
|
|
|
|
V[1][3] += (y - current_display->ycenter);
|
2019-05-26 16:04:02 +00:00
|
|
|
V[0][0] = size * 2 * cgi.hcrossf / cgi.crossf;
|
|
|
|
V[1][1] = size * 2 * cgi.hcrossf / cgi.crossf;
|
2019-06-17 10:36:35 +00:00
|
|
|
if(WDIM == 3) V[2][2] = -1;
|
2019-05-12 12:35:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
V[0][2] += (x - current_display->xcenter);
|
|
|
|
V[1][2] += (y - current_display->ycenter);
|
2019-05-26 16:04:02 +00:00
|
|
|
V[0][0] = size * 2 * cgi.hcrossf / cgi.crossf;
|
|
|
|
V[1][1] = size * 2 * cgi.hcrossf / cgi.crossf;
|
2019-05-12 12:35:14 +00:00
|
|
|
V[2][2] = current_display->scrdist;
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
void circle_around_center(ld radius, color_t linecol, color_t fillcol, PPR prio) {
|
2019-02-17 17:41:40 +00:00
|
|
|
#if CAP_QUEUE
|
2018-11-11 11:21:37 +00:00
|
|
|
if(among(pmodel, mdDisk, mdEquiarea, mdEquidistant, mdFisheye) && !(pmodel == mdDisk && hyperbolic && vid.alpha <= -1) && vid.camera_angle == 0) {
|
2018-11-08 16:42:19 +00:00
|
|
|
hyperpoint ret;
|
|
|
|
applymodel(xpush0(radius), ret);
|
2019-02-27 18:33:13 +00:00
|
|
|
ld r = hypot_d(2, ret);
|
2018-11-17 18:24:02 +00:00
|
|
|
queuecircle(current_display->xcenter, current_display->ycenter, r * current_display->radius, linecol, prio, fillcol);
|
2018-11-08 16:42:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-02-17 17:41:40 +00:00
|
|
|
#endif
|
2019-02-17 18:39:44 +00:00
|
|
|
#if CAP_QUEUE
|
2018-11-08 17:18:25 +00:00
|
|
|
for(int i=0; i<=360; i++) curvepoint(xspinpush0(i * degree, 10));
|
2018-11-08 16:42:19 +00:00
|
|
|
auto& c = queuecurve(linecol, fillcol, prio);
|
|
|
|
if(pmodel == mdDisk && hyperbolic && vid.alpha <= -1)
|
|
|
|
c.flags |= POLY_FORCE_INVERTED;
|
|
|
|
if(pmodel == mdJoukowsky)
|
|
|
|
c.flags |= POLY_FORCE_INVERTED;
|
2018-11-08 18:44:08 +00:00
|
|
|
c.flags |= POLY_ALWAYS_IN;
|
2019-02-17 17:41:40 +00:00
|
|
|
#endif
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 21:39:36 +00:00
|
|
|
EX color_t periodcolor = 0x00FF0080;
|
|
|
|
EX color_t ringcolor = darkena(0xFF, 0, 0xFF);
|
|
|
|
EX color_t modelcolor = 0;
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-02-17 18:39:44 +00:00
|
|
|
#if CAP_QUEUE
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void draw_model_elements() {
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-07-13 12:37:30 +00:00
|
|
|
dynamicval<ld> lw(vid.linewidth, vid.linewidth * vid.multiplier_ring);
|
2018-11-08 18:39:55 +00:00
|
|
|
switch(pmodel) {
|
2018-12-24 00:19:52 +00:00
|
|
|
|
|
|
|
case mdRotatedHyperboles: {
|
|
|
|
queuechr(current_display->xcenter, current_display->ycenter + current_display->radius * vid.alpha, 0, vid.fsize, 'X', ringcolor, 1, 8);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-12 21:10:01 +00:00
|
|
|
|
|
|
|
case mdTwoHybrid: {
|
|
|
|
queuereset(mdUnchanged, PPR::CIRCLE);
|
|
|
|
|
|
|
|
for(int mode=0; mode<4; mode++) {
|
2019-07-13 12:37:47 +00:00
|
|
|
for(int s=-200; s<=200; s ++) {
|
|
|
|
ld p = tanh(s / 40.);
|
2019-07-12 21:10:01 +00:00
|
|
|
ld a = vid.twopoint_param * (1+p);
|
|
|
|
ld b = vid.twopoint_param * (1-p);
|
|
|
|
ld h = ((mode & 2) ? -1 : 1) * sqrt(asin_auto(tan_auto(a) * tan_auto(b)));
|
|
|
|
|
|
|
|
hyperpoint H = xpush(p * vid.twopoint_param) * ypush0(h);
|
|
|
|
|
|
|
|
hyperpoint res = compute_hybrid(H, 2 | mode);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(res[0], res[1]);
|
|
|
|
models::apply_orientation_yz(res[2], res[1]);
|
2019-07-12 21:10:01 +00:00
|
|
|
curvepoint(res * current_display->radius);
|
|
|
|
}
|
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
queuereset(pmodel, PPR::CIRCLE);
|
|
|
|
/* fallthrough */
|
|
|
|
}
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-07-12 21:10:01 +00:00
|
|
|
case mdTwoPoint: case mdSimulatedPerspective: {
|
2019-08-09 22:58:50 +00:00
|
|
|
ld a = -models::model_orientation * degree;
|
2018-11-08 18:39:55 +00:00
|
|
|
queuechr(xspinpush0(a, +vid.twopoint_param), vid.xres / 100, 'X', ringcolor >> 8);
|
|
|
|
queuechr(xspinpush0(a, -vid.twopoint_param), vid.xres / 100, 'X', ringcolor >> 8);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdBall: {
|
2018-11-17 18:24:02 +00:00
|
|
|
queuecircle(current_display->xcenter, current_display->ycenter, current_display->radius, ringcolor, PPR::OUTCIRCLE, modelcolor);
|
2018-11-08 18:39:55 +00:00
|
|
|
ballgeometry();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdHyperboloid: {
|
|
|
|
if(hyperbolic) {
|
2018-11-08 16:42:19 +00:00
|
|
|
#if CAP_QUEUE
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(0,0,1));
|
|
|
|
curvepoint(point3(0,0,-vid.alpha));
|
2018-11-08 18:39:55 +00:00
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
ld& tz = models::top_z;
|
2018-11-08 18:39:55 +00:00
|
|
|
ld z = acosh(tz);
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
hyperpoint a = xpush0(z);
|
2019-08-09 22:58:50 +00:00
|
|
|
ld cb = models::cos_ball;
|
|
|
|
ld sb = models::sin_ball;
|
2018-11-08 18:39:55 +00:00
|
|
|
|
|
|
|
a[1] = sb * a[2] / -cb;
|
|
|
|
a[0] = sqrt(-1 + a[2] * a[2] - a[1] * a[1]);
|
|
|
|
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(0,0,-vid.alpha));
|
2018-11-08 18:39:55 +00:00
|
|
|
curvepoint(a);
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(0,0,0));
|
2018-11-08 18:39:55 +00:00
|
|
|
a[0] = -a[0];
|
|
|
|
curvepoint(a);
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(0,0,-vid.alpha));
|
2018-11-08 18:39:55 +00:00
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(-1,0,0));
|
|
|
|
curvepoint(point3(1,0,0));
|
2018-11-08 18:39:55 +00:00
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
|
|
|
|
a[1] = sb * tz / -cb;
|
|
|
|
a[0] = sqrt(tz * tz - a[1] * a[1]);
|
|
|
|
a[2] = tz - vid.alpha;
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
curvepoint(a);
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(0,0,-vid.alpha));
|
2018-11-08 18:39:55 +00:00
|
|
|
a[0] = -a[0];
|
|
|
|
curvepoint(a);
|
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
2018-11-08 16:42:19 +00:00
|
|
|
#endif
|
2018-11-08 18:39:55 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
default: break;
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
2018-11-08 18:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void queuestraight(hyperpoint X, int style, color_t lc, color_t fc, PPR p) {
|
|
|
|
|
2019-08-17 11:53:24 +00:00
|
|
|
hyperpoint H0, H1;
|
|
|
|
applymodel(X, H0);
|
|
|
|
H0 *= current_display->radius;
|
|
|
|
ld mul0 = hypot(vid.xres, vid.yres) / hypot_d(2, H0);
|
2018-11-08 18:39:55 +00:00
|
|
|
|
2019-08-17 11:53:24 +00:00
|
|
|
if(style == 1) {
|
|
|
|
H1 = H0 * -mul0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
applymodel(pispin * X, H1);
|
|
|
|
H1 *= current_display->radius;
|
|
|
|
}
|
2018-11-08 18:39:55 +00:00
|
|
|
|
2019-08-17 11:53:24 +00:00
|
|
|
ld mul1 = hypot(vid.xres, vid.yres) / hypot_d(2, H1);
|
|
|
|
|
|
|
|
queuereset(mdUnchanged, p);
|
|
|
|
curvepoint(H0 + spin(M_PI/2) * H0 * mul0);
|
|
|
|
curvepoint(H0 - spin(M_PI/2) * H0 * mul0);
|
|
|
|
curvepoint(H1 + spin(M_PI/2) * H1 * mul1);
|
|
|
|
curvepoint(H1 - spin(M_PI/2) * H1 * mul1);
|
|
|
|
curvepoint(H0 + spin(M_PI/2) * H0 * mul0);
|
|
|
|
|
|
|
|
queuecurve(lc, fc, p).flags |= POLY_ALWAYS_IN | POLY_FORCEWIDE;
|
2018-11-08 18:39:55 +00:00
|
|
|
queuereset(pmodel, p);
|
|
|
|
/*
|
|
|
|
for(int i=0; i<1; i++) {
|
|
|
|
hyperpoint h = spin(i * 45 * degree) * X;
|
|
|
|
hyperpoint res;
|
|
|
|
applymodel(h, res);
|
|
|
|
if(hypot2(res) < 1000 && !std::isnan(res[0]) && !std::isnan(res[1]))
|
|
|
|
queuechr(h, 16, 'X', 0xFF0000 + i * 0x20);
|
|
|
|
} */
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX void draw_boundary(int w) {
|
2018-11-08 16:42:19 +00:00
|
|
|
|
|
|
|
if(w == 1) return;
|
2019-08-17 21:28:41 +00:00
|
|
|
if(nonisotropic || euclid || prod) return;
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-07-13 12:37:30 +00:00
|
|
|
dynamicval<ld> lw(vid.linewidth, vid.linewidth * vid.multiplier_ring);
|
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
color_t lc = ringcolor;
|
2018-11-08 18:39:55 +00:00
|
|
|
color_t fc = modelcolor;
|
2018-11-08 16:42:19 +00:00
|
|
|
PPR p = PPR::OUTCIRCLE;
|
|
|
|
|
|
|
|
if(haveaura()) lc = 0;
|
|
|
|
if(lc == 0 && fc == 0) return;
|
2018-12-24 00:19:52 +00:00
|
|
|
if(pmodel == mdRotatedHyperboles) return;
|
2018-11-08 18:39:55 +00:00
|
|
|
|
|
|
|
ld fakeinf = sphere ? M_PI-1e-5 : hyperbolic ? 10 : exp(10);
|
2018-12-13 16:03:39 +00:00
|
|
|
|
2018-12-15 14:17:06 +00:00
|
|
|
#if CAP_SVG
|
2018-12-13 16:03:39 +00:00
|
|
|
dynamicval<ld> dw(vid.linewidth, vid.linewidth * (svg::in ? svg::divby : 1));
|
2018-12-15 14:17:06 +00:00
|
|
|
#endif
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-08-17 11:53:24 +00:00
|
|
|
if(elliptic && !among(pmodel, mdBand, mdBandEquidistant, mdBandEquiarea, mdSinusoidal, mdMollweide, mdCollignon))
|
2018-11-08 18:39:55 +00:00
|
|
|
circle_around_center(M_PI/2, periodcolor, 0, PPR::CIRCLE);
|
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
switch(pmodel) {
|
|
|
|
|
|
|
|
case mdTwoPoint: {
|
2018-11-17 18:24:02 +00:00
|
|
|
if(twopoint_do_flips || current_display->stereo_active() || !sphere) return;
|
2018-11-08 16:42:19 +00:00
|
|
|
queuereset(vid.usingGL ? mdDisk : mdUnchanged, p);
|
|
|
|
|
|
|
|
for(int b=-1; b<=1; b+=2)
|
|
|
|
for(ld a=-90; a<=90+1e-6; a+=pow(.5, vid.linequality)) {
|
|
|
|
ld x = sin(a * vid.twopoint_param * b / 90);
|
|
|
|
ld y = 0;
|
|
|
|
ld z = -sqrt(1 - x*x);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(y, x);
|
2018-11-08 16:42:19 +00:00
|
|
|
hyperpoint h1;
|
2019-02-22 19:58:40 +00:00
|
|
|
applymodel(hpxyz(x,y,z), h1);
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(h1[0], h1[1]);
|
2018-11-08 16:42:19 +00:00
|
|
|
h1[1] = abs(h1[1]) * b;
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(h1[1], h1[0]);
|
2018-11-08 16:42:19 +00:00
|
|
|
curvepoint(h1);
|
|
|
|
}
|
|
|
|
|
2019-08-17 11:53:24 +00:00
|
|
|
queuecurve(lc, fc, p).flags |= POLY_FORCEWIDE;
|
2018-11-08 16:42:19 +00:00
|
|
|
queuereset(pmodel, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-14 15:13:20 +00:00
|
|
|
case mdBand: case mdBandEquidistant: case mdBandEquiarea: case mdSinusoidal: case mdMollweide: case mdCentralCyl: case mdCollignon: {
|
2019-08-15 13:05:43 +00:00
|
|
|
if(GDIM == 3) return;
|
2019-08-09 22:58:50 +00:00
|
|
|
if(pmodel == mdBand && models::model_transition != 1) return;
|
2019-08-17 11:53:24 +00:00
|
|
|
bool bndband = (among(pmodel, mdBand, mdCentralCyl) ? hyperbolic : sphere);
|
2019-08-09 22:58:50 +00:00
|
|
|
transmatrix T = spin(-models::model_orientation * degree);
|
2018-11-08 18:39:55 +00:00
|
|
|
ld right = M_PI/2 - 1e-5;
|
|
|
|
if(bndband)
|
|
|
|
queuestraight(T * ypush0(hyperbolic ? 10 : right), 2, lc, fc, p);
|
|
|
|
ld xperiod = elliptic ? fakeinf/2 : fakeinf;
|
|
|
|
if(sphere && !bndband) {
|
|
|
|
queuestraight(T * xpush0(xperiod), 2, periodcolor, 0, PPR::CIRCLE);
|
|
|
|
}
|
|
|
|
if(sphere && bndband) {
|
|
|
|
ld adegree = degree-1e-6;
|
|
|
|
for(ld a=-90; a<90+1e-6; a+=pow(.5, vid.linequality)) {
|
|
|
|
curvepoint(T * xpush(xperiod) * ypush0(a * adegree));
|
|
|
|
}
|
|
|
|
for(ld a=-90; a<90+1e-6; a+=pow(.5, vid.linequality)) {
|
|
|
|
curvepoint(T * xpush(-xperiod) * ypush0(-a * adegree));
|
|
|
|
}
|
|
|
|
curvepoint(T * xpush(xperiod) * ypush0(-90 * adegree));
|
2019-08-17 11:53:24 +00:00
|
|
|
queuecurve(periodcolor, 0, PPR::CIRCLE).flags |= POLY_FORCEWIDE;
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
2018-11-08 18:39:55 +00:00
|
|
|
return;
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
case mdHalfplane:
|
2019-08-15 13:05:43 +00:00
|
|
|
if(hyperbolic && GDIM == 2) {
|
2019-08-09 22:58:50 +00:00
|
|
|
queuestraight(xspinpush0(-models::model_orientation * degree - M_PI/2, fakeinf), 1, lc, fc, p);
|
2018-11-08 18:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2018-11-10 17:11:10 +00:00
|
|
|
|
2018-11-11 00:37:24 +00:00
|
|
|
case mdHemisphere: {
|
|
|
|
if(hyperbolic) {
|
|
|
|
queuereset(mdUnchanged, p);
|
|
|
|
for(int i=0; i<=360; i++) {
|
|
|
|
ld s = sin(i * degree);
|
2019-08-09 22:58:50 +00:00
|
|
|
curvepoint(point3(current_display->radius * cos(i * degree), current_display->radius * s * (models::cos_ball * s >= 0 - 1e-6 ? 1 : abs(models::sin_ball)), 0));
|
2018-11-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
queuereset(pmodel, p);
|
|
|
|
p = PPR::CIRCLE; fc = 0;
|
|
|
|
queuereset(mdUnchanged, p);
|
|
|
|
|
|
|
|
for(int i=0; i<=360; i++) {
|
|
|
|
ld s = sin(i * degree);
|
2019-08-09 22:58:50 +00:00
|
|
|
curvepoint(point3(current_display->radius * cos(i * degree), current_display->radius * s * models::sin_ball, 0));
|
2018-11-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
queuereset(pmodel, p);
|
|
|
|
}
|
|
|
|
if(euclid || sphere) {
|
|
|
|
queuereset(mdUnchanged, p);
|
|
|
|
for(int i=0; i<=360; i++) {
|
2019-02-21 17:46:53 +00:00
|
|
|
curvepoint(point3(current_display->radius * cos(i * degree), current_display->radius * sin(i * degree), 0));
|
2018-11-11 00:37:24 +00:00
|
|
|
}
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
queuereset(pmodel, p);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdHyperboloid: {
|
|
|
|
if(hyperbolic) {
|
2019-08-09 22:58:50 +00:00
|
|
|
ld& tz = models::top_z;
|
2018-11-11 00:37:24 +00:00
|
|
|
ld mz = acosh(tz);
|
2019-08-09 22:58:50 +00:00
|
|
|
ld cb = models::cos_ball;
|
|
|
|
ld sb = models::sin_ball;
|
2018-11-11 00:37:24 +00:00
|
|
|
|
|
|
|
if(abs(sb) <= abs(cb) + 1e-5) {
|
|
|
|
ld step = .01 / (1 << vid.linequality);
|
|
|
|
|
|
|
|
hyperpoint a;
|
|
|
|
|
|
|
|
for(ld t=-1; t<=1; t += step) {
|
|
|
|
|
|
|
|
a = xpush0(t * mz);
|
|
|
|
|
|
|
|
if(t != 0) {
|
|
|
|
a[1] = sb * a[2] / -cb;
|
|
|
|
ld v = -1 + a[2] * a[2] - a[1] * a[1];
|
|
|
|
if(v < 0) continue;
|
|
|
|
a[0] = sqrt(v);
|
|
|
|
if(t < 0) a[0] = -a[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
curvepoint(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
if((sb > 0) ^ (cb < 0)) {
|
|
|
|
ld alpha = M_PI - atan2(a[0], -a[1]);
|
|
|
|
|
|
|
|
for(ld t=-1; t<=1; t += step)
|
|
|
|
curvepoint(xspinpush0(-M_PI/2 - t * alpha, mz));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ld alpha = - atan2(a[0], -a[1]);
|
|
|
|
|
|
|
|
for(ld t=-1; t<=1; t += step)
|
|
|
|
curvepoint(xspinpush0(+M_PI/2 - t * alpha, mz));
|
|
|
|
}
|
|
|
|
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
fc = 0; p = PPR::CIRCLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(ld t=0; t<=360; t ++)
|
|
|
|
curvepoint(xspinpush0(t * degree, mz));
|
|
|
|
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-10 17:11:10 +00:00
|
|
|
case mdSpiral: {
|
|
|
|
if(euclid) return;
|
2019-08-09 22:58:50 +00:00
|
|
|
if(models::ring_not_spiral) return;
|
2018-11-10 17:32:29 +00:00
|
|
|
// if(p == PPR::CIRCLE) p = PPR::OUTCIRCLE;
|
2019-08-09 22:58:50 +00:00
|
|
|
auto& sm = models::spiral_multiplier;
|
2018-11-10 17:32:29 +00:00
|
|
|
ld u = hypot(1, imag(sm) / real(sm));
|
2018-11-10 17:11:10 +00:00
|
|
|
if(real(sm)) {
|
|
|
|
queuereset(mdUnchanged, p);
|
2018-11-10 17:32:29 +00:00
|
|
|
for(ld a=-10; a<=10; a+=0.01 / (1 << vid.linequality) / u) {
|
2018-11-10 17:11:10 +00:00
|
|
|
cld z = exp(cld(a, a * imag(sm) / real(sm) + M_PI));
|
2019-02-21 17:46:53 +00:00
|
|
|
hyperpoint ret = point2(real(z), imag(z));
|
2018-11-11 11:46:53 +00:00
|
|
|
ret = mobius(ret, vid.skiprope, 1);
|
2018-11-17 18:24:02 +00:00
|
|
|
ret *= current_display->radius;
|
2018-11-10 17:11:10 +00:00
|
|
|
curvepoint(ret);
|
|
|
|
}
|
2018-11-11 11:46:53 +00:00
|
|
|
queuecurve(ringcolor, 0, p).flags |= POLY_ALWAYS_IN;
|
2018-11-10 17:11:10 +00:00
|
|
|
queuereset(pmodel, p);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-11-08 18:39:55 +00:00
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2018-11-11 00:37:24 +00:00
|
|
|
if(sphere && pmodel == mdDisk && vid.alpha > 1) {
|
2018-11-17 18:24:02 +00:00
|
|
|
double rad = current_display->radius / sqrt(vid.alpha*vid.alpha - 1);
|
|
|
|
queuecircle(current_display->xcenter, current_display->ycenter, rad, lc, p, fc);
|
2018-11-08 16:42:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-11 00:37:24 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
if(sphere && !among(pmodel, mdEquidistant, mdEquiarea)) return;
|
|
|
|
circle_around_center(fakeinf, lc, fc, p);
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
2019-02-17 17:41:40 +00:00
|
|
|
#endif
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX ld band_shift = 0;
|
|
|
|
EX void fix_the_band(transmatrix& T) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(((mdinf[pmodel].flags & mf::uses_bandshift) && T[LDIM][LDIM] > 1e6) || (sphere && pmodel == mdSpiral)) {
|
2018-11-09 13:14:36 +00:00
|
|
|
hyperpoint H = tC0(T);
|
|
|
|
find_zlev(H);
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_orientation(H[0], H[1]);
|
2018-11-09 13:14:36 +00:00
|
|
|
|
|
|
|
ld y = asin_auto(H[1]);
|
|
|
|
ld x = asin_auto_clamp(H[0] / cos_auto(y));
|
2019-04-03 18:30:35 +00:00
|
|
|
if(sphere) {
|
2019-08-17 21:28:41 +00:00
|
|
|
if(H[LDIM] < 0 && x > 0) x = M_PI - x;
|
|
|
|
else if(H[LDIM] < 0 && x <= 0) x = -M_PI - x;
|
2019-04-03 18:30:35 +00:00
|
|
|
}
|
2018-11-09 13:14:36 +00:00
|
|
|
band_shift += x;
|
|
|
|
T = xpush(-x) * T;
|
|
|
|
fixmatrix(T);
|
|
|
|
// todo orientation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
#if HDR
|
|
|
|
struct bandfixer {
|
|
|
|
dynamicval<ld> bw;
|
|
|
|
bandfixer(transmatrix& T) : bw(band_shift, band_shift) { fix_the_band(T); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX namespace dq {
|
|
|
|
EX queue<tuple<heptagon*, transmatrix, ld>> drawqueue;
|
2018-11-10 13:26:49 +00:00
|
|
|
|
2019-08-09 20:37:11 +00:00
|
|
|
EX set<heptagon*> visited;
|
|
|
|
EX void enqueue(heptagon *h, const transmatrix& T) {
|
2018-11-10 13:26:49 +00:00
|
|
|
if(!h || visited.count(h)) { return; }
|
|
|
|
visited.insert(h);
|
|
|
|
drawqueue.emplace(h, T, band_shift);
|
|
|
|
}
|
|
|
|
|
2019-05-06 23:08:49 +00:00
|
|
|
#if MAXMDIM >= 4
|
2019-08-09 20:37:11 +00:00
|
|
|
EX set<int> visited_by_matrix;
|
|
|
|
EX void enqueue_by_matrix(heptagon *h, const transmatrix& T) {
|
2019-03-15 12:46:23 +00:00
|
|
|
if(!h) return;
|
|
|
|
int b = reg3::bucketer(tC0(T));
|
|
|
|
if(visited_by_matrix.count(b)) { return; }
|
|
|
|
visited_by_matrix.insert(b);
|
|
|
|
drawqueue.emplace(h, T, band_shift);
|
|
|
|
}
|
2019-05-06 23:08:49 +00:00
|
|
|
#endif
|
2019-08-09 20:37:11 +00:00
|
|
|
EX }
|
2018-11-10 13:26:49 +00:00
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool do_draw(cell *c) {
|
2018-11-10 13:26:49 +00:00
|
|
|
// do not display out of range cells, unless on torus
|
|
|
|
if(c->pathdist == PINFD && geometry != gTorus && vid.use_smart_range == 0)
|
|
|
|
return false;
|
2019-02-09 11:23:45 +00:00
|
|
|
// do not display not fully generated cells, unless changing range allowed
|
|
|
|
if(c->mpdist > 7 && !allowChangeRange()) return false;
|
2018-11-10 13:26:49 +00:00
|
|
|
// in the Yendor Challenge, scrolling back is forbidden
|
2019-04-29 15:16:55 +00:00
|
|
|
if(c->cpdist > 7 && (yendor::on || isHaunted(cwt.at->land)) && !cheater && !autocheat) return false;
|
2018-11-10 13:26:49 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX ld extra_generation_distance = 99;
|
2019-03-08 21:42:14 +00:00
|
|
|
|
2019-05-15 13:49:09 +00:00
|
|
|
// returns false if limited
|
|
|
|
bool limited_generation(cell *c) {
|
|
|
|
if(c->mpdist <= 7) return true;
|
|
|
|
if(cells_generated > vid.cells_generated_limit) return false;
|
|
|
|
setdist(c, 7, c);
|
|
|
|
cells_generated++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX bool do_draw(cell *c, const transmatrix& T) {
|
2019-07-28 09:17:25 +00:00
|
|
|
|
2019-08-18 19:31:09 +00:00
|
|
|
if(product::pmap) return product::in_actual([&] { return do_draw(product::get_at(c, product::current_view_level), T); });
|
2019-05-08 16:33:08 +00:00
|
|
|
if(WDIM == 3) {
|
2019-03-10 11:12:47 +00:00
|
|
|
if(cells_drawn > vid.cells_drawn_limit) return false;
|
2019-08-06 19:01:00 +00:00
|
|
|
if(nil && pmodel == mdGeodesic) {
|
|
|
|
ld dist = hdist0(nisot::inverse_exp(tC0(T), nisot::iLazy));
|
|
|
|
if(dist > sightranges[geometry] + (vid.sloppy_3d ? 0 : 0.9)) return false;
|
|
|
|
if(dist <= extra_generation_distance && !limited_generation(c)) return false;
|
2019-08-06 10:00:46 +00:00
|
|
|
}
|
2019-08-06 19:01:00 +00:00
|
|
|
else if(pmodel == mdGeodesic && !nil) {
|
2019-08-06 10:00:46 +00:00
|
|
|
if(!nisot::in_table_range(tC0(T))) return false;
|
2019-07-30 11:02:44 +00:00
|
|
|
if(!limited_generation(c)) return false;
|
|
|
|
}
|
2019-07-28 09:07:21 +00:00
|
|
|
else if(vid.use_smart_range) {
|
2019-03-21 18:13:45 +00:00
|
|
|
if(cells_drawn >= 50 && !in_smart_range(T)) return false;
|
2019-05-15 13:49:09 +00:00
|
|
|
if(!limited_generation(c)) return false;
|
2019-03-21 18:13:45 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ld dist = hdist0(tC0(T));
|
2019-05-26 16:04:02 +00:00
|
|
|
if(dist > sightranges[geometry] + (vid.sloppy_3d ? 0 : cgi.corner_bonus)) return false;
|
2019-05-15 13:49:09 +00:00
|
|
|
if(dist <= extra_generation_distance && !limited_generation(c)) return false;
|
2019-03-21 18:13:45 +00:00
|
|
|
}
|
2019-02-24 21:11:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-08 09:04:01 +00:00
|
|
|
if(just_gmatrix && sphere) return true;
|
2018-11-10 13:26:49 +00:00
|
|
|
if(!do_draw(c)) return false;
|
2018-11-10 15:56:08 +00:00
|
|
|
if(euclid && pmodel == mdSpiral) {
|
|
|
|
hyperpoint h = tC0(T);
|
|
|
|
cld z(h[0], h[1]);
|
2019-08-09 22:58:50 +00:00
|
|
|
z = z * models::spiral_multiplier;
|
2018-11-10 15:56:08 +00:00
|
|
|
ld iz = imag(z) + 1.14279e-2; // make it never fall exactly on PI
|
|
|
|
if(iz < -M_PI || iz >= M_PI) return false;
|
|
|
|
}
|
2019-08-09 22:58:50 +00:00
|
|
|
if(pmodel == mdSpiral && models::ring_not_spiral) {
|
2018-12-21 13:42:59 +00:00
|
|
|
cld z;
|
|
|
|
hyperpoint H = tC0(T);
|
|
|
|
hyperpoint ret;
|
|
|
|
makeband(H, ret, band_conformal);
|
2019-08-09 22:58:50 +00:00
|
|
|
z = cld(ret[0], ret[1]) * models::spiral_multiplier;
|
|
|
|
if(imag(z) < -models::spiral_cone_rad/2-1e-5 || imag(z) >= models::spiral_cone_rad/2-1e-5) return false;
|
2018-12-21 13:42:59 +00:00
|
|
|
}
|
2018-11-10 13:26:49 +00:00
|
|
|
if(cells_drawn > vid.cells_drawn_limit) return false;
|
2018-11-27 01:32:11 +00:00
|
|
|
bool usr = vid.use_smart_range || quotient || euwrap;
|
2019-05-16 15:50:28 +00:00
|
|
|
if(usr && cells_drawn >= 50 && !in_smart_range(T) && !(WDIM == 2 && GDIM == 3 && hdist0(tC0(T)) < 2.5)) return false;
|
2019-05-15 13:49:09 +00:00
|
|
|
if(vid.use_smart_range == 2 && !limited_generation(c)) return false;
|
2018-11-10 13:26:49 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-08-09 19:00:52 +00:00
|
|
|
EX int cone_side(const hyperpoint H) {
|
2018-12-21 13:42:59 +00:00
|
|
|
hyperpoint ret;
|
|
|
|
if(hyperbolic) makeband(H, ret, band_conformal);
|
|
|
|
else ret = H;
|
2019-08-09 22:58:50 +00:00
|
|
|
cld z = cld(ret[0], ret[1]) * models::spiral_multiplier;
|
2018-12-21 13:42:59 +00:00
|
|
|
|
|
|
|
auto zth = [&] (cld z) {
|
2019-08-09 22:58:50 +00:00
|
|
|
ld alpha = imag(z) * 360 / models::spiral_cone;
|
2018-12-21 13:42:59 +00:00
|
|
|
ld r = real(z);
|
|
|
|
r = exp(r);
|
|
|
|
|
|
|
|
hyperpoint ret;
|
|
|
|
|
|
|
|
ret[0] = -sin(alpha) * r;
|
|
|
|
ret[1] = cos(alpha) * r;
|
2019-08-09 22:58:50 +00:00
|
|
|
ret[2] = (r-1) * sqrt( pow(360/models::spiral_cone, 2) - 1);
|
2018-12-21 13:42:59 +00:00
|
|
|
|
2019-08-09 22:58:50 +00:00
|
|
|
models::apply_ball(ret[2], ret[1]);
|
2018-12-21 13:42:59 +00:00
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
hyperpoint ret0 = zth(z);
|
|
|
|
hyperpoint ret1 = zth(z + cld(1e-3, 0));
|
|
|
|
hyperpoint ret2 = zth(z + cld(0, 1e-3));
|
|
|
|
|
|
|
|
return (ret1[1] - ret0[1]) * (ret2[0] - ret0[0]) < (ret2[1] - ret0[1]) * (ret1[0] - ret0[0]) ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2018-06-10 23:58:31 +00:00
|
|
|
}
|