1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-19 11:44:48 +00:00

2D-as-3D works in all geometries

This commit is contained in:
Zeno Rogue 2019-05-08 20:15:50 +02:00
parent 1c4d86e0e9
commit f8247073e7
2 changed files with 91 additions and 62 deletions

View File

@ -206,7 +206,9 @@ void horopoint(ld y, ld x, cell &fc, int c) {
}
void horoline(ld y, ld x1, ld x2) {
for(int a=0; a<=16; a++)
if(DIM == 3)
horopoint(y, x1), horopoint(y, x2);
else for(int a=0; a<=16; a++)
horopoint(y, x1 + (x2-x1) * a / 16.);
}
@ -271,43 +273,6 @@ void bshape_regular(floorshape &fsh, int id, int sides, int shift, ld size) {
hpcpush(xspinpush0(-M_PI/sides, size));
chasmifyPoly(dlow_table[k], dhi_table[k], k);
}
for(int k=0; k<SIDEPARS; k++) {
fsh.levels[k].resize(2);
bshape(fsh.levels[k][id], fsh.prio);
/*
for(int i=fsh.b[id].s; i< fsh.b[id].e; i++)
hpcpush(zshift(hpc[i], dfloor_table[k]));
*/
fsh.levels[k][id].tinf = &fsh.tinf3;
fsh.levels[k][id].texture_offset = 0;
auto at = [&] (hyperpoint h, int a) {
hpcpush(normalize(h));
};
const int STEP = TEXTURE_STEP_3D;
for(int t=0; t<sides; t++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
using namespace hyperpoint_vec;
hyperpoint center = zpush(dfloor_table[k]) * C0;
hyperpoint v1 = (xspinpush(t*2 * M_PI / sides + shift * M_PI / S42, size) * center - center) / STEP;
hyperpoint v2 = (xspinpush((t+1)*2 * M_PI / sides + shift * M_PI / S42, size) * center - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
last->flags |= POLY_TRIANGLES;
}
}
#if CAP_IRR
@ -443,35 +408,12 @@ void generate_floorshapes_for(int id, cell *c, int siid, int sidir) {
hpcpush(iddspin(c, cid) * cornerlist[(cid+1)%cor]);
chasmifyPoly(dlow_table[k], dhi_table[k], k);
}
for(int k=0; k<SIDEPARS; k++) {
sizeto(fsh.levels[k], id);
bshape(fsh.levels[k][id], fsh.prio);
for(int i=fsh.b[id].s; i< fsh.b[id].e; i++)
hpcpush(zshift(hpc[i], dfloor_table[k]));
}
}
for(auto pfsh: all_escher_floorshapes) {
auto& fsh = *pfsh;
if(WDIM == 2 && GDIM == 3) {
ld hexside = shFullFloor.rad0, heptside = shFullFloor.rad1;
int td = ((PURE || euclid) && !(S7&1)) ? S42+S6 : 0;
if(id == 1)
bshape_regular(fsh, 1, S7, td, heptside);
else if(PURE)
bshape_regular(fsh, 0, S7, td, heptside);
else
bshape_regular(fsh, 0, S6, S7, hexside);
continue;
}
sizeto(fsh.b, id);
sizeto(fsh.shadow, id);
@ -534,6 +476,90 @@ void generate_floorshapes_for(int id, cell *c, int siid, int sidir) {
}
}
}
if(WDIM == 2 && GDIM == 3) {
finishshape();
for(auto pfsh: all_plain_floorshapes) {
auto& fsh = *pfsh;
for(int k=0; k<SIDEPARS; k++) {
sizeto(fsh.levels[k], id);
bshape(fsh.levels[k][id], fsh.prio);
fsh.levels[k][id].tinf = &fsh.tinf3;
fsh.levels[k][id].texture_offset = 0;
auto at = [&] (hyperpoint h, int a) {
hpcpush(normalize(h));
};
const int STEP = TEXTURE_STEP_3D;
int s = fsh.b[id].s;
int e = fsh.b[id].e-1;
if(binarytiling) {
vector<hyperpoint> cors;
for(int i=0; i<c->type; i++) cors.push_back(get_corner_position(c, i, 3));
cors.push_back(cors[0]);
for(int t=0; t<c->type; t++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
using namespace hyperpoint_vec;
hyperpoint center = zpush(dfloor_table[k]) * C0;
hyperpoint v1 = (rgpushxto0(cors[t]) * center - center) / STEP;
hyperpoint v2 = (rgpushxto0(cors[t+1]) * center - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
}
else {
for(int t=0; t<e-s; t++)
for(int y=0; y<STEP; y++)
for(int x=0; x<STEP; x++) {
using namespace hyperpoint_vec;
hyperpoint center = zpush(dfloor_table[k]) * C0;
hyperpoint v1 = (rgpushxto0(hpc[s+t]) * center - center) / STEP;
hyperpoint v2 = (rgpushxto0(hpc[s+t+1]) * center - center) / STEP;
if(x+y < STEP) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x+1) + v2 * y, 1);
at(center + v1 * x + v2 * (y+1), 2);
}
if(x+y <= STEP && x && y) {
at(center + v1 * x + v2 * y, 0);
at(center + v1 * (x-1) + v2 * y, 1);
at(center + v1 * x + v2 * (y-1), 2);
}
}
}
last->flags |= POLY_TRIANGLES;
}
}
for(auto pfsh: all_escher_floorshapes) {
auto& fsh = *pfsh;
for(int l=0; l<SIDEPARS; l++) {
fsh.levels[l] = shFullFloor.levels[l];
fsh.side[l] = shFullFloor.side[l];
for(int e=0; e<MAX_EDGE; e++)
fsh.gpside[l][e] = shFullFloor.gpside[l][e];
}
for(auto& l: fsh.levels)
for(auto& li: l)
li.tinf = &fsh.tinf3;
}
finishshape();
}
}
void generate_floorshapes() {

View File

@ -339,7 +339,10 @@ transmatrix matrix3(ld a, ld b, ld c, ld d, ld e, ld f, ld g, ld h, ld i) {
#if MAXMDIM==3
return transmatrix {{{a,b,c},{d,e,f},{g,h,i}}};
#else
return transmatrix {{{a,b,c,0},{d,e,f,0},{g,h,i,0},{0,0,0,1}}};
if(DIM == 2)
return transmatrix {{{a,b,c,0},{d,e,f,0},{g,h,i,0},{0,0,0,1}}};
else
return transmatrix {{{a,b,0,c},{d,e,0,f},{0,0,1,0},{g,h,0,i}}};
#endif
}