2018-02-08 23:40:26 +00:00
|
|
|
// Hyperbolic Rogue -- hyperbolic graphics
|
|
|
|
// Copyright (C) 2011-2018 Zeno Rogue, see 'hyper.cpp' for details
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
hyperpoint dhp(ld x, ld y, ld z) { return hpxyz(x, y, z); }
|
|
|
|
|
|
|
|
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)
|
|
|
|
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);
|
2017-07-10 18:47:38 +00:00
|
|
|
H[2] = hz;
|
|
|
|
|
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) {
|
|
|
|
ld s = 1 / (alpha + z[2]);
|
|
|
|
z[0] *= s;
|
|
|
|
z[1] *= s;
|
|
|
|
z[2] = 0;
|
|
|
|
return z;
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint gethyper(ld x, ld y) {
|
|
|
|
|
|
|
|
ld hx = (x - vid.xcenter) / vid.radius;
|
|
|
|
ld hy = (y - vid.ycenter) / vid.radius / vid.stretch;
|
|
|
|
|
|
|
|
if(pmodel) {
|
|
|
|
ghx = hx, ghy = hy;
|
|
|
|
return ghpm;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.camera_angle) camrotate(hx, hy);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
hyperpoint H = ypush(geom3::camera) * xpush(d) * ypush(zl) * C0;
|
|
|
|
ld tzh = vid.ballproj + H[2];
|
|
|
|
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;
|
|
|
|
|
|
|
|
conformal::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 {
|
|
|
|
z = z * vid.radius;
|
|
|
|
ld mul = stereo::scrdist / (stereo::scrdist + z);
|
|
|
|
f[0] = f[0] * mul;
|
|
|
|
f[1] = f[1] * mul;
|
|
|
|
f[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius + stereo::ipd * mul / 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
if(wmspatial || mmspatial) {
|
|
|
|
ld zlev = zlevel(H);
|
|
|
|
using namespace hyperpoint_vec;
|
|
|
|
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) {
|
2018-02-20 10:15:08 +00:00
|
|
|
ld tz = euclid ? (1+vid.alpha) : vid.alpha+H[2];
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld atan2(hyperpoint h) {
|
|
|
|
return atan2(h[1], h[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T> void makeband(hyperpoint H, hyperpoint& ret, const T& f) {
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
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]);
|
2018-11-09 13:14:36 +00:00
|
|
|
x = asin_auto_clamp(H[0] / cos_auto(y)) + band_shift;
|
2018-11-06 14:53:50 +00:00
|
|
|
if(sphere) {
|
|
|
|
if(H[2] < 0 && x > 0) x = M_PI - x;
|
|
|
|
else if(H[2] < 0 && x <= 0) x = -M_PI - x;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
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;
|
|
|
|
conformal::apply_orientation(y, x);
|
|
|
|
ret = hpxyz(x / M_PI, y / M_PI, 0);
|
|
|
|
if(zlev != 1 && stereo::active())
|
|
|
|
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:
|
|
|
|
// 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) {
|
|
|
|
using namespace hyperpoint_vec;
|
|
|
|
h = perspective_to_space(h * scale, 1, gcSphere);
|
2018-11-08 17:18:25 +00:00
|
|
|
h = rotmatrix(angle * degree, 1, 2) * h;
|
2018-11-07 06:20:36 +00:00
|
|
|
return space_to_perspective(h, 1) / scale;
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
void applymodel(hyperpoint H, hyperpoint& ret) {
|
2018-03-26 17:06:47 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
using namespace hyperpoint_vec;
|
|
|
|
|
|
|
|
switch(pmodel) {
|
|
|
|
case mdUnchanged:
|
|
|
|
ret = H / vid.radius;
|
|
|
|
return;
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdBall: {
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
|
|
|
|
ld zl = geom3::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: {
|
|
|
|
ld tz = get_tz(H);
|
|
|
|
if(!vid.camera_angle) {
|
|
|
|
ret[0] = H[0] / tz;
|
|
|
|
ret[1] = H[1] / tz;
|
|
|
|
ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / tz / 2;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
ret[2] = vid.xres * stereo::eyewidth() / 2 / vid.radius - stereo::ipd / uz / 2;
|
2018-03-27 02:01:30 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +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);
|
|
|
|
|
2018-10-23 14:58:19 +00:00
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
H[1] += 1;
|
|
|
|
double rad = sqhypot2(H);
|
|
|
|
H /= -rad;
|
|
|
|
H[1] += .5;
|
2018-10-23 14:58:19 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
2018-07-30 15:44:11 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
H *= conformal::halfplane_scale;
|
|
|
|
|
|
|
|
ret[0] = -conformal::osin - H[0];
|
|
|
|
if(zlev != 1) {
|
|
|
|
if(abs(conformal::ocos) > 1e-5)
|
|
|
|
H[1] = H[1] * pow(zlev, conformal::ocos);
|
|
|
|
if(abs(conformal::ocos) > 1e-5 && conformal::osin)
|
|
|
|
H[1] += H[0] * conformal::osin * (pow(zlev, conformal::ocos) - 1) / conformal::ocos;
|
|
|
|
else if(conformal::osin)
|
|
|
|
H[1] += H[0] * conformal::osin * log(zlev);
|
|
|
|
}
|
|
|
|
ret[1] = conformal::ocos + H[1];
|
|
|
|
ret[2] = 0;
|
|
|
|
if(zlev != 1 && stereo::active())
|
|
|
|
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];
|
|
|
|
ret[2] = sqrt(1 - sqhypot2(ret));
|
|
|
|
ret = ret * (1 + (zl - 1) * ret[2]);
|
2018-07-30 15:44:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
case gcEuclid: {
|
|
|
|
// stereographic projection to a sphere
|
|
|
|
auto hd = hdist0(H) / vid.euclid_to_sphere;
|
|
|
|
if(hd == 0) ret = hpxyz(0, 0, -1);
|
|
|
|
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]);
|
|
|
|
|
|
|
|
conformal::apply_ball(ret[2], ret[1]);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
ld& topz = conformal::top_z;
|
|
|
|
if(H[2] > topz) {
|
|
|
|
ld scale = sqrt(topz*topz-1) / hypot2(H);
|
|
|
|
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;
|
|
|
|
|
|
|
|
conformal::apply_ball(ret[2], ret[1]);
|
|
|
|
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);
|
|
|
|
H[2] = zlev;
|
|
|
|
ret = H / sqrt(1 + sqhypot3(H));
|
|
|
|
break;
|
|
|
|
}
|
2018-10-26 19:03:27 +00:00
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdJoukowsky:
|
|
|
|
case mdJoukowskyInverted: {
|
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
|
|
|
// with equal speed skiprope: conformal::apply_orientation(H[1], H[0]);
|
|
|
|
|
|
|
|
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;
|
|
|
|
hyperpoint zr = hpxyz(real(z), imag(z), 0);
|
|
|
|
|
|
|
|
hyperpoint inhyp = perspective_to_space(zr, 1, gcHyperbolic);
|
|
|
|
last_skiprope = vid.skiprope;
|
|
|
|
lastmatrix = rgpushxto0(inhyp);
|
|
|
|
}
|
|
|
|
H = lastmatrix * H;
|
|
|
|
}
|
|
|
|
|
|
|
|
H = space_to_perspective(H);
|
|
|
|
ld r = hypot2(H);
|
|
|
|
ld c = H[0] / r;
|
|
|
|
ld s = H[1] / r;
|
|
|
|
ld& mt = conformal::model_transition;
|
|
|
|
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);
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
if(pmodel == mdJoukowskyInverted) {
|
|
|
|
ld r2 = sqhypot2(ret);
|
|
|
|
ret[0] = ret[0] / r2;
|
|
|
|
ret[1] = -ret[1] / r2;
|
|
|
|
conformal::apply_orientation(ret[1], ret[0]);
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
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); */
|
|
|
|
}
|
|
|
|
else conformal::apply_orientation(ret[0], ret[1]);
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
|
|
|
|
|
|
|
pair<long double, long double> p = polygonal::compute(H[0], H[1]);
|
|
|
|
|
|
|
|
conformal::apply_orientation(p.second, p.first);
|
|
|
|
ret[0] = p.first;
|
|
|
|
ret[1] = p.second;
|
|
|
|
ret[2] = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdBand:
|
|
|
|
if(conformal::model_transition != 1) {
|
|
|
|
ld& mt = conformal::model_transition;
|
|
|
|
|
|
|
|
H = space_to_perspective(H);
|
|
|
|
|
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
|
|
|
|
|
|
|
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);
|
|
|
|
ld r = hypot2(H);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
conformal::apply_orientation(ret[1], ret[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
makeband(H, ret, band_conformal);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case mdTwoPoint:
|
|
|
|
makeband(H, ret, make_twopoint);
|
|
|
|
break;
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdEquidistant: case mdEquiarea: {
|
|
|
|
ld zlev = find_zlev(H);
|
|
|
|
|
|
|
|
ld rad = hypot2(H);
|
|
|
|
if(rad == 0) rad = 1;
|
|
|
|
ld d = hdist0(H);
|
|
|
|
ld df, zf;
|
|
|
|
hypot_zlev(zlev, d, df, zf);
|
|
|
|
|
|
|
|
// 4 pi / 2pi = M_PI
|
|
|
|
|
|
|
|
if(pmodel == mdEquiarea && sphere)
|
|
|
|
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);
|
|
|
|
ret[2] = 0;
|
|
|
|
if(zlev != 1 && stereo::active())
|
|
|
|
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
|
|
|
|
find_zlev(H); // + geom3::depth;
|
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ld factor = geom3::lev_to_factor(y + geom3::depth);
|
|
|
|
|
|
|
|
ret[0] = sinh(x) * factor;
|
|
|
|
ret[1] = cosh(x) * factor;
|
|
|
|
ret[2] = 0;
|
|
|
|
|
|
|
|
ret[0] = atan(ret[0]);
|
|
|
|
ret[1] = atan(ret[1]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdFormula: {
|
|
|
|
dynamicval<eModel> m(pmodel, conformal::basic_model);
|
|
|
|
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];
|
2018-11-06 23:52:48 +00:00
|
|
|
ep.s = conformal::formula;
|
|
|
|
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: {
|
|
|
|
makeband(H, ret, band_conformal);
|
|
|
|
|
|
|
|
cld z(ret[0], ret[1]);
|
|
|
|
z = z * cld(conformal::cos_spiral, conformal::sin_spiral) * M_PI * conformal::cos_spiral;
|
|
|
|
z = exp(z);
|
|
|
|
ret[0] = real(z);
|
|
|
|
ret[1] = imag(z);
|
|
|
|
|
|
|
|
if(vid.skiprope)
|
|
|
|
ret = mobius(ret, vid.skiprope, 1);
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:53:50 +00:00
|
|
|
case mdGUARD: break;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2018-11-06 14:53:50 +00:00
|
|
|
|
|
|
|
ghcheck(ret,H);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// game-related graphics
|
|
|
|
|
|
|
|
transmatrix View; // current rotation, relative to viewctr
|
2018-03-24 14:22:21 +00:00
|
|
|
transmatrix cwtV = Id; // player-relative view
|
2017-07-10 18:47:38 +00:00
|
|
|
transmatrix sphereflip; // on the sphere, flip
|
|
|
|
heptspin viewctr; // heptagon and rotation where the view is centered at
|
|
|
|
bool playerfound; // has player been found in the last drawing?
|
|
|
|
|
2017-10-29 16:12:40 +00:00
|
|
|
#define eurad crossf
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
double q3 = sqrt(double(3));
|
|
|
|
|
|
|
|
bool outofmap(hyperpoint h) {
|
|
|
|
if(euclid)
|
2017-11-07 13:17:13 +00:00
|
|
|
return h[2] < .5; // false; // h[0] * h[0] + h[1] * h[1] > 15 * eurad;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
hyperpoint mirrorif(const hyperpoint& V, bool b) {
|
|
|
|
if(b) return Mirror*V;
|
|
|
|
else return V;
|
|
|
|
}
|
|
|
|
|
2017-07-16 21:00:55 +00:00
|
|
|
transmatrix mirrorif(const transmatrix& V, bool b) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool behindsphere(const hyperpoint& h) {
|
|
|
|
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) {
|
|
|
|
if(h[2] > -1/vid.alpha) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vid.alpha <= 1) {
|
2018-04-22 09:11:47 +00:00
|
|
|
if(h[2] < .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;
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
bool behindsphere(const transmatrix& V) {
|
|
|
|
return behindsphere(tC0(V));
|
|
|
|
}
|
|
|
|
|
2017-10-09 09:46:49 +00:00
|
|
|
ld spherity(const transmatrix& V) {
|
|
|
|
return spherity(tC0(V));
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
bool confusingGeometry() {
|
2018-07-06 18:00:13 +00:00
|
|
|
return elliptic || quotient || torus;
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
2018-04-10 15:06:04 +00:00
|
|
|
ld master_to_c7_angle() {
|
2018-08-28 15:17:34 +00:00
|
|
|
return (!BITRUNCATED && !binarytiling && !archimedean) ? M_PI + gp::alpha : 0;
|
2018-04-10 15:06:04 +00:00
|
|
|
}
|
|
|
|
|
2017-12-16 08:03:50 +00:00
|
|
|
transmatrix actualV(const heptspin& hs, const transmatrix& V) {
|
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));
|
2018-08-20 00:02:45 +00:00
|
|
|
if(archimedean) return V * spin(-arcm::current.triangles[arcm::id_of(hs.at)][hs.spin].first);
|
2018-08-14 07:16:30 +00:00
|
|
|
if(binarytiling) 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
|
|
|
}
|
|
|
|
|
2018-04-06 21:20:04 +00:00
|
|
|
transmatrix applyspin(const heptspin& hs, const transmatrix& V) {
|
2018-08-14 07:16:30 +00:00
|
|
|
if(binarytiling) return V;
|
2018-08-20 00:02:45 +00:00
|
|
|
if(archimedean) return V * spin(arcm::current.triangles[arcm::id_of(hs.at)][hs.spin].first);
|
2018-04-21 12:01:54 +00:00
|
|
|
return hs.spin ? V * spin(hs.spin*2*M_PI/S7) : V;
|
2018-04-06 21:20:04 +00:00
|
|
|
}
|
|
|
|
|
2018-11-01 17:59:25 +00:00
|
|
|
bool in_smart_range(const transmatrix& T) {
|
|
|
|
hyperpoint h1, h2, h3;
|
|
|
|
applymodel(tC0(T), h1);
|
|
|
|
ld x = vid.xcenter + vid.radius * h1[0];
|
|
|
|
ld y = vid.ycenter + vid.radius * h1[1] * vid.stretch;
|
|
|
|
if(x > vid.xres * 2) return false;
|
|
|
|
if(x < -vid.xres) return false;
|
|
|
|
if(y > vid.yres * 2) return false;
|
|
|
|
if(y < -vid.yres) return false;
|
|
|
|
ld epsilon = 0.01;
|
|
|
|
applymodel(T * xpush0(epsilon), h2);
|
|
|
|
ld x1 = vid.radius * abs(h2[0] - h1[0]) / epsilon;
|
|
|
|
ld y1 = vid.radius * abs(h2[1] - h1[1]) * vid.stretch / epsilon;
|
|
|
|
applymodel(T * ypush(epsilon) * C0, h3);
|
|
|
|
ld x2 = vid.radius * abs(h3[0] - h1[0]) / epsilon;
|
|
|
|
ld y2 = vid.radius * abs(h3[1] - h1[1]) * vid.stretch / epsilon;
|
|
|
|
ld scale = sqrt(hypot(x1, y1) * hypot(x2, y2)) * scalefactor * hcrossf7;
|
|
|
|
return
|
|
|
|
scale > vid.smart_range_detail &&
|
|
|
|
x - 2 * max(x1, x2) < vid.xres &&
|
|
|
|
x + 2 * max(x1, x2) > 0 &&
|
|
|
|
y - 2 * max(y1, y2) < vid.yres &&
|
|
|
|
y + 2 * max(y1, y2) > 0;
|
|
|
|
}
|
|
|
|
|
2018-04-11 11:16:40 +00:00
|
|
|
// in hyperbolic quotient geometries, relying on pathdist is not sufficient
|
|
|
|
bool in_qrange(const transmatrix& V) {
|
2018-11-01 17:59:25 +00:00
|
|
|
if(!quotient || !hyperbolic || vid.use_smart_range) return true;
|
2018-04-11 11:16:40 +00:00
|
|
|
return V[2][2] < cosh(crossf * get_sightrange_ambush());
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
transmatrix V1 = V * ddspin(c, i) * xpush(crossf) * iddspin(c2, 0) * spin(M_PI);
|
|
|
|
drawrec(c2, V1);
|
|
|
|
}
|
|
|
|
} */
|
2018-05-04 00:47:14 +00:00
|
|
|
|
|
|
|
gp::local_info draw_li;
|
2018-04-03 21:39:18 +00:00
|
|
|
|
2018-04-09 15:40:12 +00:00
|
|
|
void drawrec(cell *c, const transmatrix& V, gp::loc at, int dir, int maindir) {
|
2018-04-03 21:39:18 +00:00
|
|
|
if(dodrawcell(c)) {
|
2018-05-07 18:11:04 +00:00
|
|
|
/* auto li = get_local_info(c);
|
2018-04-05 22:40:53 +00:00
|
|
|
if(fix6(dir) != fix6(li.total_dir)) printf("totaldir %d/%d\n", dir, li.total_dir);
|
|
|
|
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);
|
|
|
|
transmatrix V1 = V * Tf[draw_li.last_dir][at.first&31][at.second&31][fixg6(dir)];
|
2018-04-11 11:16:40 +00:00
|
|
|
if(in_qrange(V1))
|
|
|
|
drawcell(c, V1, 0, false);
|
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-07-10 02:13:35 +00:00
|
|
|
drawrec(c2, V, at + eudir(dir+i), dir + i + SG3, maindir);
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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-04-03 21:39:18 +00:00
|
|
|
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;
|
2018-05-04 00:46:44 +00:00
|
|
|
draw_li.last_dir = i;
|
2018-07-10 02:13:35 +00:00
|
|
|
drawrec(c2, V, gp::loc(1,0), SG3, i);
|
2018-04-03 23:19:21 +00:00
|
|
|
}
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-11 11:16:40 +00:00
|
|
|
|
2018-11-01 17:59:25 +00:00
|
|
|
void drawrec(const heptspin& hs, hstate s, const transmatrix& V, int reclev) {
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-08-17 22:46:45 +00:00
|
|
|
// calc_relative_matrix(cwt.c, hs.at);
|
2017-07-10 18:47:38 +00:00
|
|
|
|
2018-08-17 22:46:45 +00:00
|
|
|
cell *c = hs.at->c7;
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
transmatrix V10;
|
|
|
|
const transmatrix& V1 = hs.mirrored ? (V10 = V * Mirror) : V;
|
|
|
|
|
2018-07-16 18:05:23 +00:00
|
|
|
bool draw = c->pathdist < PINFD;
|
|
|
|
|
2018-11-09 13:14:36 +00:00
|
|
|
if(cells_drawn > vid.cells_drawn_limit || reclev >= 10000 || std::isinf(V[2][2]) || std::isnan(V[2][2]) || V[2][2] > 1e8)
|
2018-11-01 17:59:25 +00:00
|
|
|
draw = false;
|
|
|
|
else if(vid.use_smart_range) {
|
|
|
|
draw = reclev < 2 ? true : in_smart_range(V);
|
|
|
|
if(draw && vid.use_smart_range == 2)
|
|
|
|
setdist(c, 7, NULL);
|
|
|
|
}
|
|
|
|
|
2018-08-28 15:17:34 +00:00
|
|
|
if(GOLDBERG) {
|
2018-04-09 15:40:12 +00:00
|
|
|
gp::drawrec(c, actualV(hs, V1));
|
2018-04-03 21:39:18 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 15:17:34 +00:00
|
|
|
else if(IRREGULAR) {
|
2018-08-17 22:46:45 +00:00
|
|
|
auto& hi = irr::periodmap[hs.at];
|
2018-07-16 18:05:23 +00:00
|
|
|
transmatrix V0 = actualV(hs, V1);
|
2018-08-17 22:46:45 +00:00
|
|
|
auto& vc = irr::cells_of_heptagon[hi.base.at];
|
2018-07-16 18:05:23 +00:00
|
|
|
for(int i=0; i<isize(vc); i++)
|
|
|
|
if(dodrawcell(hi.subcells[i]) && in_qrange(V0 * irr::cells[vc[i]].pusher))
|
|
|
|
draw = true,
|
|
|
|
drawcell(hi.subcells[i], V0 * irr::cells[vc[i]].pusher, 0, false);
|
|
|
|
}
|
|
|
|
|
2018-04-11 11:16:40 +00:00
|
|
|
else {
|
|
|
|
if(dodrawcell(c)) {
|
|
|
|
transmatrix V2 = actualV(hs, V1);
|
|
|
|
drawcell(c, V2, 0, hs.mirrored);
|
|
|
|
}
|
|
|
|
|
2018-08-28 15:17:34 +00:00
|
|
|
if(BITRUNCATED) for(int d=0; d<S7; d++) {
|
2018-08-17 22:46:45 +00:00
|
|
|
int ds = hs.at->c.fix(hs.spin + d);
|
2018-04-11 11:16:40 +00:00
|
|
|
// createMov(c, ds);
|
2018-08-17 22:46:45 +00:00
|
|
|
if(c->move(ds) && c->c.spin(ds) == 0 && dodrawcell(c->move(ds))) {
|
2018-04-11 11:16:40 +00:00
|
|
|
transmatrix V2 = V1 * hexmove[d];
|
|
|
|
if(in_qrange(V2))
|
2018-08-17 22:46:45 +00:00
|
|
|
drawcell(c->move(ds), V2, 0, hs.mirrored ^ c->c.mirror(ds));
|
2018-04-11 11:16:40 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-16 18:05:23 +00:00
|
|
|
if(draw && in_qrange(V)) for(int d=0; d<S7; d++) {
|
2017-07-10 18:47:38 +00:00
|
|
|
hstate s2 = transition(s, d);
|
|
|
|
if(s2 == hsError) continue;
|
2018-03-24 11:59:01 +00:00
|
|
|
heptspin hs2 = hs + d + wstep;
|
2018-11-09 13:14:36 +00:00
|
|
|
transmatrix Vd = V * heptmove[d];
|
|
|
|
bandfixer bf(Vd);
|
|
|
|
drawrec(hs2, s2, Vd, reclev+1);
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int mindx=-7, mindy=-7, maxdx=7, maxdy=7;
|
|
|
|
|
2017-11-07 13:39:26 +00:00
|
|
|
transmatrix eumove(ld x, ld y) {
|
2017-07-10 18:47:38 +00:00
|
|
|
transmatrix Mat = Id;
|
|
|
|
Mat[2][2] = 1;
|
2017-12-18 12:00:36 +00:00
|
|
|
|
|
|
|
if(a4) {
|
|
|
|
Mat[0][2] += x * eurad;
|
|
|
|
Mat[1][2] += y * eurad;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Mat[0][2] += (x + y * .5) * eurad;
|
|
|
|
// Mat[2][0] += (x + y * .5) * eurad;
|
|
|
|
Mat[1][2] += y * q3 /2 * eurad;
|
|
|
|
// Mat[2][1] += y * q3 /2 * eurad;
|
|
|
|
}
|
|
|
|
|
|
|
|
ld v = a4 ? 1 : q3;
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
while(Mat[0][2] <= -16384 * eurad) Mat[0][2] += 32768 * eurad;
|
|
|
|
while(Mat[0][2] >= 16384 * eurad) Mat[0][2] -= 32768 * eurad;
|
2017-12-18 12:00:36 +00:00
|
|
|
while(Mat[1][2] <= -16384 * v * eurad) Mat[1][2] += 32768 * v * eurad;
|
|
|
|
while(Mat[1][2] >= 16384 * v * eurad) Mat[1][2] -= 32768 * v * eurad;
|
2017-07-10 18:47:38 +00:00
|
|
|
return Mat;
|
|
|
|
}
|
|
|
|
|
2017-12-28 15:46:10 +00:00
|
|
|
transmatrix eumove(int vec) {
|
|
|
|
int x, y;
|
|
|
|
tie(x,y) = vec_to_pair(vec);
|
|
|
|
return eumove(x, y);
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
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 {
|
|
|
|
d = fix6(d);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-11-06 20:18:40 +00:00
|
|
|
ld matrixnorm(const transmatrix& Mat) {
|
|
|
|
return Mat[0][2] * Mat[0][2] + Mat[1][2] * Mat[1][2];
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void drawEuclidean() {
|
|
|
|
DEBB(DF_GRAPH, (debugfile,"drawEuclidean\n"));
|
2017-12-18 12:00:36 +00:00
|
|
|
sphereflip = Id;
|
2018-08-17 22:46:45 +00:00
|
|
|
if(!centerover.at) centerover = cwt;
|
2017-07-10 18:47:38 +00:00
|
|
|
// printf("centerover = %p player = %p [%d,%d]-[%d,%d]\n", lcenterover, cwt.c,
|
|
|
|
// mindx, mindy, maxdx, maxdy);
|
2017-12-28 15:46:10 +00:00
|
|
|
int pvec = cellwalker_to_vec(centerover);
|
2017-11-06 20:18:40 +00:00
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
int minsx = mindx-1, maxsx=maxdx+1, minsy=mindy-1, maxsy=maxdy+1;
|
|
|
|
mindx=maxdx=mindy=maxdy=0;
|
|
|
|
|
2017-11-03 19:55:18 +00:00
|
|
|
transmatrix View0 = View;
|
|
|
|
|
2018-02-20 10:15:08 +00:00
|
|
|
ld cellrad = vid.radius / (1 + vid.alpha);
|
2017-11-03 19:55:18 +00:00
|
|
|
|
2017-11-06 20:18:40 +00:00
|
|
|
ld centerd = matrixnorm(View0);
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
for(int dx=minsx; dx<=maxsx; dx++)
|
|
|
|
for(int dy=minsy; dy<=maxsy; dy++) {
|
2017-11-06 20:18:40 +00:00
|
|
|
torusconfig::torus_cx = dx;
|
|
|
|
torusconfig::torus_cy = dy;
|
2017-12-28 15:46:10 +00:00
|
|
|
cellwalker cw = vec_to_cellwalker(pvec + euclid_getvec(dx, dy));
|
|
|
|
transmatrix Mat = eumove(dx,dy);
|
|
|
|
|
2018-08-17 22:46:45 +00:00
|
|
|
if(!cw.at) continue;
|
2017-12-28 15:46:10 +00:00
|
|
|
|
2017-11-03 19:55:18 +00:00
|
|
|
Mat = View0 * Mat;
|
|
|
|
|
2017-12-28 15:46:10 +00:00
|
|
|
if(true) {
|
2017-11-06 20:18:40 +00:00
|
|
|
ld locald = matrixnorm(Mat);
|
2017-12-28 15:46:10 +00:00
|
|
|
if(locald < centerd) centerd = locald, centerover = cw, View = View0 * eumove(dx, dy);
|
2017-11-03 19:55:18 +00:00
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
|
|
|
|
// Mat[0][0] = -1;
|
|
|
|
// Mat[1][1] = -1;
|
|
|
|
|
|
|
|
// Mat[2][0] = x*x/10;
|
|
|
|
// Mat[2][1] = y*y/10;
|
|
|
|
// Mat = Mat * xpush(x-30) * ypush(y-30);
|
2018-11-01 17:59:25 +00:00
|
|
|
|
|
|
|
if(vid.use_smart_range) {
|
|
|
|
if(in_smart_range(Mat)) {
|
2018-11-06 14:55:07 +00:00
|
|
|
if(vid.use_smart_range == 2) setdist(cw.at, 7, cw.at);
|
2018-11-01 17:59:25 +00:00
|
|
|
if(dx < mindx) mindx = dx;
|
|
|
|
if(dy < mindy) mindy = dy;
|
|
|
|
if(dx > maxdx) maxdx = dx;
|
|
|
|
if(dy > maxdy) maxdy = dy;
|
|
|
|
if(dodrawcell(cw.at))
|
|
|
|
drawcell(cw.at, cw.mirrored ? Mat * Mirror : Mat, cw.spin, cw.mirrored);
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
2018-11-01 17:59:25 +00:00
|
|
|
else {
|
|
|
|
int cx, cy, shift;
|
|
|
|
getcoord0(tC0(Mat), cx, cy, shift);
|
|
|
|
if(cx >= 0 && cy >= 0 && cx < vid.xres && cy < vid.yres) {
|
|
|
|
if(dx < mindx) mindx = dx;
|
|
|
|
if(dy < mindy) mindy = dy;
|
|
|
|
if(dx > maxdx) maxdx = dx;
|
|
|
|
if(dy > maxdy) maxdy = dy;
|
2017-11-03 19:55:18 +00:00
|
|
|
}
|
2018-11-01 17:59:25 +00:00
|
|
|
if(cx >= -cellrad && cy >= -cellrad && cx < vid.xres+cellrad && cy < vid.yres+cellrad)
|
|
|
|
if(dodrawcell(cw.at)) {
|
|
|
|
drawcell(cw.at, cw.mirrored ? Mat * Mirror : Mat, cw.spin, cw.mirrored);
|
|
|
|
}
|
|
|
|
}
|
2017-07-10 18:47:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void spinEdge(ld aspd) {
|
|
|
|
if(downspin > aspd) downspin = aspd;
|
|
|
|
if(downspin < -aspd) downspin = -aspd;
|
|
|
|
View = spin(downspin) * View;
|
|
|
|
}
|
|
|
|
|
|
|
|
void centerpc(ld aspd) {
|
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;
|
|
|
|
DEBB(DF_GRAPH, (debugfile,"center pc\n"));
|
2018-07-23 03:14:19 +00:00
|
|
|
|
|
|
|
ors::unrotate(cwtV); ors::unrotate(View);
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
hyperpoint H = ypush(-vid.yshift) * sphereflip * tC0(cwtV);
|
2018-03-25 13:07:11 +00:00
|
|
|
ld R = H[0] == 0 && H[1] == 0 ? 0 : hdist0(H); // = sqrt(H[0] * H[0] + H[1] * H[1]);
|
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;
|
|
|
|
|
|
|
|
View[0][2] -= cwtV[0][2] * aspd / R;
|
|
|
|
View[1][2] -= cwtV[1][2] * 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));
|
|
|
|
|
|
|
|
if(R < aspd) {
|
|
|
|
View = gpushxto0(H) * View;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
View = rspintox(H) * xpush(-aspd) * spintox(H) * View;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void optimizeview() {
|
|
|
|
|
2018-09-23 21:55:03 +00:00
|
|
|
if(centerover.at && inmirror(centerover.at)) {
|
|
|
|
anims::reflect_view();
|
|
|
|
}
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
DEBB(DF_GRAPH, (debugfile,"optimize view\n"));
|
|
|
|
int turn = 0;
|
|
|
|
ld best = INF;
|
|
|
|
|
|
|
|
transmatrix TB = Id;
|
|
|
|
|
2018-08-19 21:06:32 +00:00
|
|
|
if(binarytiling || archimedean) {
|
2018-08-09 17:28:53 +00:00
|
|
|
turn = -1, best = View[2][2];
|
2018-08-17 22:46:45 +00:00
|
|
|
for(int i=0; i<viewctr.at->c7->type; i++) {
|
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);
|
2018-08-19 21:06:32 +00:00
|
|
|
transmatrix T = (binarytiling) ? binary::relative_matrix(h2, viewctr.at) : arcm::relative_matrix(h2, viewctr.at);
|
2018-08-09 17:28:53 +00:00
|
|
|
hyperpoint H = View * tC0(T);
|
2018-08-18 23:04:15 +00:00
|
|
|
ld quality = euclid ? hdist0(H) : H[2];
|
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
|
|
|
}
|
2018-08-09 17:28:53 +00:00
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
for(int i=-1; i<S7; i++) {
|
|
|
|
|
|
|
|
ld trot = -i * M_PI * 2 / (S7+.0);
|
|
|
|
transmatrix T = i < 0 ? Id : spin(trot) * xpush(tessf) * pispin;
|
|
|
|
hyperpoint H = View * tC0(T);
|
|
|
|
if(H[2] < best) best = H[2], turn = i, TB = T;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
for(int i=0; i<3; i++) h[i] *= vid.radius;
|
|
|
|
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)
|
|
|
|
addball(0, d, geom3::depth);
|
|
|
|
addball(0, 0, -geom3::camera);
|
|
|
|
addball(0, 0, geom3::depth);
|
|
|
|
addball(0, 0, -geom3::camera);
|
|
|
|
addball(0, -10, 0);
|
|
|
|
addball(0, 0, -geom3::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
|
|
|
}
|
|
|
|
|
|
|
|
void resetview() {
|
|
|
|
DEBB(DF_GRAPH, (debugfile,"reset view\n"));
|
|
|
|
View = Id;
|
|
|
|
// 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;
|
2018-01-13 20:58:50 +00:00
|
|
|
cwtV = Id;
|
2017-07-10 18:47:38 +00:00
|
|
|
// SDL_LockSurface(s);
|
|
|
|
// SDL_UnlockSurface(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void panning(hyperpoint hf, hyperpoint ht) {
|
|
|
|
View =
|
|
|
|
rgpushxto0(hf) * rgpushxto0(gpushxto0(hf) * ht) * gpushxto0(hf) * View;
|
|
|
|
playermoved = false;
|
|
|
|
}
|
|
|
|
|
2018-11-01 17:59:25 +00:00
|
|
|
int cells_drawn;
|
|
|
|
|
2017-07-10 18:47:38 +00:00
|
|
|
void fullcenter() {
|
|
|
|
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-02-03 12:41:49 +00:00
|
|
|
V[0][2] += (x - vid.xcenter) / vid.radius * (1+vid.alpha);
|
|
|
|
V[1][2] += (y - vid.ycenter) / vid.radius * (1+vid.alpha);
|
2017-07-10 18:47:38 +00:00
|
|
|
return V;
|
|
|
|
}
|
|
|
|
|
|
|
|
transmatrix atscreenpos(ld x, ld y, ld size) {
|
|
|
|
transmatrix V = Id;
|
|
|
|
|
|
|
|
V[0][2] += (x - vid.xcenter);
|
|
|
|
V[1][2] += (y - vid.ycenter);
|
|
|
|
V[0][0] = size * 2 * hcrossf / crossf;
|
|
|
|
V[1][1] = size * 2 * hcrossf / crossf;
|
2018-02-03 12:41:49 +00:00
|
|
|
V[2][2] = stereo::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) {
|
|
|
|
if(among(pmodel, mdDisk, mdEquiarea, mdEquidistant, mdFisheye) && !(pmodel == mdDisk && hyperbolic && vid.alpha <= -1)) {
|
|
|
|
hyperpoint ret;
|
|
|
|
applymodel(xpush0(radius), ret);
|
|
|
|
ld r = hypot2(ret);
|
|
|
|
queuecircle(vid.xcenter, vid.ycenter, r * vid.radius, linecol, prio, fillcol);
|
|
|
|
return;
|
|
|
|
}
|
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;
|
2018-11-08 16:42:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
color_t periodcolor = 0x00FF0080;
|
|
|
|
color_t ringcolor = darkena(0xFF, 0, 0xFF);
|
|
|
|
color_t modelcolor = 0;
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
void draw_model_elements() {
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
switch(pmodel) {
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
case mdTwoPoint: {
|
|
|
|
ld a = -conformal::model_orientation * degree;
|
|
|
|
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: {
|
|
|
|
queuecircle(vid.xcenter, vid.ycenter, vid.radius, ringcolor, PPR::OUTCIRCLE, modelcolor);
|
|
|
|
ballgeometry();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
case mdHyperboloid: {
|
|
|
|
if(hyperbolic) {
|
2018-11-08 16:42:19 +00:00
|
|
|
#if CAP_QUEUE
|
2018-11-08 18:39:55 +00:00
|
|
|
curvepoint(hpxyz(0,0,1));
|
|
|
|
curvepoint(hpxyz(0,0,-vid.alpha));
|
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
|
|
|
|
ld& tz = conformal::top_z;
|
|
|
|
ld z = acosh(tz);
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
hyperpoint a = xpush0(z);
|
|
|
|
ld cb = conformal::cos_ball;
|
|
|
|
ld sb = conformal::sin_ball;
|
|
|
|
|
|
|
|
a[1] = sb * a[2] / -cb;
|
|
|
|
a[0] = sqrt(-1 + a[2] * a[2] - a[1] * a[1]);
|
|
|
|
|
|
|
|
curvepoint(hpxyz(0,0,-vid.alpha));
|
|
|
|
curvepoint(a);
|
|
|
|
curvepoint(hpxyz(0,0,0));
|
|
|
|
a[0] = -a[0];
|
|
|
|
curvepoint(a);
|
|
|
|
curvepoint(hpxyz(0,0,-vid.alpha));
|
|
|
|
queuecurve(ringcolor, 0, PPR::CIRCLE);
|
|
|
|
|
|
|
|
curvepoint(hpxyz(-1,0,0));
|
|
|
|
curvepoint(hpxyz(1,0,0));
|
|
|
|
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);
|
|
|
|
curvepoint(hpxyz(0,0,-vid.alpha));
|
|
|
|
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) {
|
|
|
|
|
|
|
|
using namespace hyperpoint_vec;
|
|
|
|
hyperpoint H;
|
|
|
|
applymodel(X, H);
|
|
|
|
H *= vid.radius;
|
|
|
|
ld mul = hypot(vid.xres, vid.yres) / hypot2(H);
|
|
|
|
ld m = style == 1 ? -mul : -1;
|
|
|
|
|
|
|
|
queuereset(mdUnchanged, p);
|
|
|
|
curvepoint(H + spin(M_PI/2) * H * mul);
|
|
|
|
curvepoint(H - spin(M_PI/2) * H * mul);
|
|
|
|
curvepoint(m * H - spin(M_PI/2) * H * mul);
|
|
|
|
curvepoint(m * H + spin(M_PI/2) * H * mul);
|
|
|
|
curvepoint(H + spin(M_PI/2) * H * mul);
|
|
|
|
|
|
|
|
queuecurve(lc, fc, p).flags |= POLY_ALWAYS_IN;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void draw_boundary(int w) {
|
|
|
|
|
|
|
|
if(w == 1) return;
|
|
|
|
|
|
|
|
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-11-08 18:39:55 +00:00
|
|
|
|
|
|
|
ld fakeinf = sphere ? M_PI-1e-5 : hyperbolic ? 10 : exp(10);
|
2018-11-08 16:42:19 +00:00
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
if(elliptic && !among(pmodel, mdBand, mdBandEquidistant, mdBandEquiarea, mdSinusoidal))
|
|
|
|
circle_around_center(M_PI/2, periodcolor, 0, PPR::CIRCLE);
|
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
switch(pmodel) {
|
|
|
|
|
|
|
|
case mdTwoPoint: {
|
|
|
|
if(twopoint_do_flips || stereo::active() || !sphere) return;
|
|
|
|
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)) {
|
|
|
|
using namespace hyperpoint_vec;
|
|
|
|
ld x = sin(a * vid.twopoint_param * b / 90);
|
|
|
|
ld y = 0;
|
|
|
|
ld z = -sqrt(1 - x*x);
|
|
|
|
conformal::apply_orientation(y, x);
|
|
|
|
hyperpoint h1;
|
|
|
|
applymodel(hpxyz(x,y,z), h1);
|
|
|
|
|
|
|
|
conformal::apply_orientation(h1[0], h1[1]);
|
|
|
|
h1[1] = abs(h1[1]) * b;
|
|
|
|
conformal::apply_orientation(h1[1], h1[0]);
|
|
|
|
curvepoint(h1);
|
|
|
|
}
|
|
|
|
|
|
|
|
queuecurve(lc, fc, p);
|
|
|
|
queuereset(pmodel, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-08 18:39:55 +00:00
|
|
|
case mdBand: case mdBandEquidistant: case mdBandEquiarea: case mdSinusoidal: {
|
|
|
|
bool bndband = ((pmodel == mdBand) ? hyperbolic : sphere);
|
|
|
|
transmatrix T = spin(-conformal::model_orientation * degree);
|
|
|
|
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));
|
|
|
|
queuecurve(periodcolor, 0, PPR::CIRCLE);
|
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:
|
|
|
|
if(hyperbolic) {
|
|
|
|
queuestraight(xspinpush0(-conformal::model_orientation * degree - M_PI/2, fakeinf), 1, lc, fc, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-11-08 16:42:19 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(!stereo::active() && !euclid && (pmodel == mdDisk || pmodel == mdBall || (sphere && mdAzimuthalEqui()))) {
|
|
|
|
double rad = vid.radius;
|
|
|
|
bool isbnd = true;
|
|
|
|
if(sphere) {
|
|
|
|
if(mdAzimuthalEqui())
|
|
|
|
;
|
|
|
|
else if(!vid.grid && !elliptic && !force_sphere_outline)
|
|
|
|
rad = 0;
|
|
|
|
else if(vid.alpha <= 0)
|
|
|
|
;
|
|
|
|
else if(vid.grid || force_sphere_outline) // mark the edge
|
|
|
|
rad /= sqrt(vid.alpha*vid.alpha - 1);
|
|
|
|
}
|
|
|
|
if(rad)
|
|
|
|
queuecircle(vid.xcenter, vid.ycenter, rad, lc, p, fc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
if(pmodel == mdPolygonal || pmodel == mdPolynomial)
|
|
|
|
polygonal::drawBoundary(darkena(0xFF, 0, 0xFF));
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2018-11-09 13:14:36 +00:00
|
|
|
ld band_shift = 0;
|
|
|
|
void fix_the_band(transmatrix& T) {
|
|
|
|
if((models[pmodel].flags & mf::quasiband) && T[2][2] > 1e6) {
|
|
|
|
hyperpoint H = tC0(T);
|
|
|
|
find_zlev(H);
|
|
|
|
conformal::apply_orientation(H[0], H[1]);
|
|
|
|
|
|
|
|
ld y = asin_auto(H[1]);
|
|
|
|
ld x = asin_auto_clamp(H[0] / cos_auto(y));
|
|
|
|
band_shift += x;
|
|
|
|
// printf("fixing with shift = %lf\n", x);
|
|
|
|
T = xpush(-x) * T;
|
|
|
|
fixmatrix(T);
|
|
|
|
// todo orientation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-10 23:58:31 +00:00
|
|
|
}
|