1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-20 23:50:27 +00:00

rug:: nonisotropic native geometry

This commit is contained in:
Zeno Rogue 2020-04-17 17:17:22 +02:00
parent 0a6c80e909
commit 44cfe1af59
2 changed files with 30 additions and 15 deletions

View File

@ -940,7 +940,7 @@ EX void runGeometryExperiments() {
#if CAP_COMMANDLINE #if CAP_COMMANDLINE
eGeometry readGeo(const string& ss) { EX eGeometry readGeo(const string& ss) {
for(int i=0; i<isize(ginf); i++) if(ginf[i].shortname == ss) return eGeometry(i); for(int i=0; i<isize(ginf); i++) if(ginf[i].shortname == ss) return eGeometry(i);
bool numeric = true; bool numeric = true;
for(char c: ss) if(c < '0' || c > '9') numeric = false; for(char c: ss) if(c < '0' || c > '9') numeric = false;

35
rug.cpp
View File

@ -253,14 +253,12 @@ EX rugpoint *addRugpoint(hyperpoint h, double dist) {
else { else {
m->native = h; m->native = h;
ld hd = h[LDIM]; ld hd = h[LDIM];
for(int d=GDIM; d<MAXMDIM; d++) { for(int d=GDIM; d<MAXMDIM-1; d++) {
m->native[d] = (hd - .99) * (rand() % 1000 - rand() % 1000) / 1000; m->native[d] = (hd - .99) * (rand() % 1000 - rand() % 1000) / 1000;
} }
USING_NATIVE_GEOMETRY; USING_NATIVE_GEOMETRY;
#if MAXMDIM >= 4 #if MAXMDIM >= 4
if(euclid)
m->native[3] = 1; m->native[3] = 1;
else
m->native = normalize(m->native); m->native = normalize(m->native);
#endif #endif
} }
@ -701,7 +699,6 @@ EX void preset(rugpoint *m) {
if(q>0) m->native = h / q; if(q>0) m->native = h / q;
#endif #endif
// printf("preset (%d) -> %s\n", q, display(m->native));
if(std::isnan(m->native[0]) || std::isnan(m->native[1]) || std::isnan(m->native[2])) if(std::isnan(m->native[0]) || std::isnan(m->native[1]) || std::isnan(m->native[2]))
throw rug_exception(); throw rug_exception();
} }
@ -1006,6 +1003,7 @@ void drawTriangle(triangle& t) {
hyperpoint hc = (t.m[1]->native - t.m[0]->native) ^ (t.m[2]->native - t.m[0]->native); hyperpoint hc = (t.m[1]->native - t.m[0]->native) ^ (t.m[2]->native - t.m[0]->native);
double hch = hypot_d(3, hc); double hch = hypot_d(3, hc);
col = (2 + hc[0]/hch) / 3; col = (2 + hc[0]/hch) / 3;
if(nonisotropic) col = (9+col) / 10;
} }
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
@ -1092,7 +1090,15 @@ EX void drawRugScene() {
auto& rug = queuecurve(0, 0xFFFFFFFF, PPR::LINE); auto& rug = queuecurve(0, 0xFFFFFFFF, PPR::LINE);
if(nonisotropic) {
transmatrix T2 = eupush( tC0(inverse(rugView)) );
NLP = rugView * T2;
rug.V = inverse(NLP) * rugView;
}
else {
rug.V = rugView; rug.V = rugView;
}
rug.offset_texture = 0; rug.offset_texture = 0;
rug.tinf = &tinf; rug.tinf = &tinf;
rug.flags = POLY_TRIANGLES | POLY_FAT | POLY_PRINTABLE | POLY_ALWAYS_IN | POLY_ISSIDE | POLY_SHADE_TEXTURE; rug.flags = POLY_TRIANGLES | POLY_FAT | POLY_PRINTABLE | POLY_ALWAYS_IN | POLY_ISSIDE | POLY_SHADE_TEXTURE;
@ -1435,18 +1441,26 @@ EX void rug_geometry_choice() {
gamescreen(0); gamescreen(0);
dialog::init(XLAT("hypersian rug mode"), iinf[itPalace].color, 150, 100); dialog::init(XLAT("hypersian rug mode"), iinf[itPalace].color, 150, 100);
dialog::addBoolItem("Euclidean", rug_euclid(), 'a'); USING_NATIVE_GEOMETRY;
dialog::addBoolItem("Euclidean", euclid, 'a');
dialog::add_action([] { gwhere = rgEuclid; popScreen(); }); dialog::add_action([] { gwhere = rgEuclid; popScreen(); });
dialog::addBoolItem("hyperbolic", rug_hyperbolic(), 'b'); dialog::addBoolItem("hyperbolic", hyperbolic, 'b');
dialog::add_action([] { gwhere = rgHyperbolic; popScreen(); }); dialog::add_action([] { gwhere = rgHyperbolic; popScreen(); });
dialog::addBoolItem("spherical", rug_sphere() && !rug_elliptic(), 'c'); dialog::addBoolItem("spherical", sphere && !elliptic, 'c');
dialog::add_action([] { gwhere = rgSphere; popScreen(); }); dialog::add_action([] { gwhere = rgSphere; popScreen(); });
dialog::addBoolItem("elliptic", rug_elliptic(), 'd'); dialog::addBoolItem("elliptic", elliptic, 'd');
dialog::add_action([] { gwhere = rgElliptic; popScreen(); }); dialog::add_action([] { gwhere = rgElliptic; popScreen(); });
dialog::addBoolItem("Nil", nil, 'e');
dialog::add_action([] { gwhere = gNil; popScreen(); });
dialog::addBoolItem("Solv", sol, 'e');
dialog::add_action([] { gwhere = gSol; popScreen(); });
dialog::addBack(); dialog::addBack();
dialog::display(); dialog::display();
} }
@ -1732,7 +1746,7 @@ int rugArgs() {
} }
else if(argis("-ruggeo")) { else if(argis("-ruggeo")) {
shift(); gwhere = (eGeometry) argi(); shift(); gwhere = readGeo(args());
if(gwhere == gEuclid) gwhere = rgEuclid; if(gwhere == gEuclid) gwhere = rgEuclid;
if(gwhere == gSphere) gwhere = rgSphere; if(gwhere == gSphere) gwhere = rgSphere;
if(gwhere == gNormal) gwhere = rgHyperbolic; if(gwhere == gNormal) gwhere = rgHyperbolic;
@ -1740,7 +1754,8 @@ int rugArgs() {
} }
else if(argis("-rugpers")) { else if(argis("-rugpers")) {
rconf.model = mdPerspective; USING_NATIVE_GEOMETRY;
rconf.model = nonisotropic ? mdGeodesic : mdPerspective;
} }
else if(argis("-rugonce")) { else if(argis("-rugonce")) {