mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-09-27 13:48:15 +00:00
Rug works better with non-truncated geometries, especially with a4 geometries which previously basically did not work
This commit is contained in:
parent
72c8e0505b
commit
bdb84c5a33
64
rug.cpp
64
rug.cpp
@ -33,6 +33,8 @@ GLAPI void APIENTRY glDeleteFramebuffers (GLsizei n, const GLuint *framebuffers)
|
|||||||
|
|
||||||
namespace rug {
|
namespace rug {
|
||||||
|
|
||||||
|
struct rug_exception { };
|
||||||
|
|
||||||
bool fast_euclidean = true;
|
bool fast_euclidean = true;
|
||||||
bool keep_shape = true;
|
bool keep_shape = true;
|
||||||
bool good_shape;
|
bool good_shape;
|
||||||
@ -554,6 +556,12 @@ void verify() {
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void comp(cell*& minimum, cell *next) {
|
||||||
|
int nc = next->cpdist, mc = minimum->cpdist;
|
||||||
|
if(tie(nc, next) < tie(mc, minimum))
|
||||||
|
minimum = next;
|
||||||
|
}
|
||||||
|
|
||||||
void buildRug() {
|
void buildRug() {
|
||||||
|
|
||||||
if(torus) {
|
if(torus) {
|
||||||
@ -562,27 +570,36 @@ void buildRug() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
celllister cl(centerover.c ? centerover.c : cwt.c, sightrange, vertex_limit, NULL);
|
||||||
|
|
||||||
map<cell*, rugpoint *> vptr;
|
map<cell*, rugpoint *> vptr;
|
||||||
|
|
||||||
for(int i=0; i<size(dcal); i++)
|
for(cell *c: cl.lst)
|
||||||
if(gmatrix.count(dcal[i]))
|
vptr[c] = addRugpoint(shmup::ggmatrix(c)*C0, c->cpdist);
|
||||||
vptr[dcal[i]] = addRugpoint(gmatrix[dcal[i]]*C0, dcal[i]->cpdist);
|
|
||||||
|
|
||||||
for(int i=0; i<size(dcal); i++) {
|
for(auto& p: vptr) {
|
||||||
cell *c = dcal[i];
|
cell *c = p.first;
|
||||||
rugpoint *v = vptr[c];
|
rugpoint *v = p.second;
|
||||||
if(!v) continue;
|
for(int j=0; j<c->type; j++) try {
|
||||||
for(int j=0; j<c->type; j++) {
|
|
||||||
cell *c2 = c->mov[j];
|
cell *c2 = c->mov[j];
|
||||||
rugpoint *w = vptr[c2];
|
rugpoint *w = vptr.at(c2);
|
||||||
if(!w) continue;
|
|
||||||
// if(v<w) addEdge(v, w);
|
// if(v<w) addEdge(v, w);
|
||||||
|
|
||||||
cell *c3 = c->mov[(j+1) % c->type];
|
cell *c3 = c->mov[(j+1) % c->type];
|
||||||
rugpoint *w2 = vptr[c3];
|
rugpoint *w2 = vptr.at(c3);
|
||||||
if(!w2) continue;
|
|
||||||
if(ctof(c)) addTriangle(v, w, w2);
|
if(a4) {
|
||||||
|
cellwalker cw(c, j);
|
||||||
|
cwstep(cw); cwspin(cw, -1); cwstep(cw);
|
||||||
|
cell *c4 = cw.c;
|
||||||
|
cell *cm = c; comp(cm, c); comp(cm, c2); comp(cm, c3); comp(cm, c4);
|
||||||
|
if(cm == c || cm == c4)
|
||||||
|
addTriangle(v, w, w2);
|
||||||
}
|
}
|
||||||
|
else if(v > w && v > w2)
|
||||||
|
addTriangle(v, w, w2);
|
||||||
|
}
|
||||||
|
catch(out_of_range) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("vertices = %d triangles= %d\n", size(points), size(triangles));
|
printf("vertices = %d triangles= %d\n", size(points), size(triangles));
|
||||||
@ -646,7 +663,10 @@ bool force(rugpoint& m1, rugpoint& m2, double rd, double d1=1, double d2=1) {
|
|||||||
|
|
||||||
transmatrix iT1 = inverse(T1);
|
transmatrix iT1 = inverse(T1);
|
||||||
|
|
||||||
for(int i=0; i<3; i++) if(isnan(m1.flat[i])) { printf("NAN!\n"); exit(1); }
|
for(int i=0; i<3; i++) if(isnan(m1.flat[i])) {
|
||||||
|
addMessage("Failed!");
|
||||||
|
throw rug_exception();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
printf("%p %p\n", &m1, &m2);
|
printf("%p %p\n", &m1, &m2);
|
||||||
@ -708,10 +728,10 @@ void preset(rugpoint *m) {
|
|||||||
double c2 = b->edges[k2].len/blen;
|
double c2 = b->edges[k2].len/blen;
|
||||||
|
|
||||||
double cz = (c1*c1-c2*c2+1) / 2;
|
double cz = (c1*c1-c2*c2+1) / 2;
|
||||||
double ch = sqrt(c2*c2 - cz*cz + 1e-10);
|
double ch = sqrt(c1*c1 - cz*cz + 1e-10);
|
||||||
|
|
||||||
double az = (a1*a1-a2*a2+1) / 2;
|
double az = (a1*a1-a2*a2+1) / 2;
|
||||||
double ah = sqrt(a2*a2 - az*az + 1e-10);
|
double ah = sqrt(a1*a1 - az*az + 1e-10);
|
||||||
|
|
||||||
// c->h = a->h + (b->h-a->h) * cz + ch * ort
|
// c->h = a->h + (b->h-a->h) * cz + ch * ort
|
||||||
hyperpoint ort = (c->flat - a->flat - cz * (b->flat-a->flat)) / ch;
|
hyperpoint ort = (c->flat - a->flat - cz * (b->flat-a->flat)) / ch;
|
||||||
@ -730,6 +750,8 @@ void preset(rugpoint *m) {
|
|||||||
|
|
||||||
if(q>0) m->flat = h/q;
|
if(q>0) m->flat = h/q;
|
||||||
printf("preset (%d) -> %s\n", q, display(m->flat));
|
printf("preset (%d) -> %s\n", q, display(m->flat));
|
||||||
|
if(isnan(m->flat[0]) || isnan(m->flat[1]) || isnan(m->flat[2]))
|
||||||
|
throw rug_exception();
|
||||||
}
|
}
|
||||||
|
|
||||||
ld sse(hyperpoint h) {
|
ld sse(hyperpoint h) {
|
||||||
@ -1175,11 +1197,16 @@ void init() {
|
|||||||
qvalid = 0; dt = 0; queueiter = 0;
|
qvalid = 0; dt = 0; queueiter = 0;
|
||||||
err_zero_current = err_zero;
|
err_zero_current = err_zero;
|
||||||
|
|
||||||
|
try {
|
||||||
buildRug();
|
buildRug();
|
||||||
while(good_shape && subdivide_further()) subdivide();
|
while(good_shape && subdivide_further()) subdivide();
|
||||||
|
|
||||||
currentrot = Id;
|
currentrot = Id;
|
||||||
}
|
}
|
||||||
|
catch(rug_exception) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void close() {
|
void close() {
|
||||||
if(!rugged) return;
|
if(!rugged) return;
|
||||||
@ -1196,6 +1223,7 @@ int lastticks;
|
|||||||
ld protractor = 0;
|
ld protractor = 0;
|
||||||
|
|
||||||
void actDraw() {
|
void actDraw() {
|
||||||
|
try {
|
||||||
if(!renderonce) prepareTexture();
|
if(!renderonce) prepareTexture();
|
||||||
physics();
|
physics();
|
||||||
drawRugScene();
|
drawRugScene();
|
||||||
@ -1259,6 +1287,10 @@ void actDraw() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(rug_exception) {
|
||||||
|
rug::close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int besti;
|
int besti;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user