mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-02-02 12:19:18 +00:00
reg3:: subcubes:: neater again
This commit is contained in:
parent
670f315df5
commit
2a7d932703
68
reg3.cpp
68
reg3.cpp
@ -320,45 +320,47 @@ EX namespace reg3 {
|
||||
for(co[1]=-sub; co[1]<=sub; co[1]+=s)
|
||||
for(co[2]=-sub; co[2]<=sub; co[2]+=s)
|
||||
if(((co[0]^co[1]^1)&1) && ((co[0]^co[2]^1)&1)) {
|
||||
vector<hyperpoint> dirs;
|
||||
vector<int> dirlimits;
|
||||
vector<transmatrix> mirrors;
|
||||
hyperpoint ctr = Hypc;
|
||||
ctr[3] = vz * sub;
|
||||
|
||||
struct direction {
|
||||
hyperpoint dir;
|
||||
int limit;
|
||||
transmatrix mirror;
|
||||
void flip() { dir = -dir; limit = 200 - limit; }
|
||||
};
|
||||
|
||||
array<direction, 3> di;
|
||||
|
||||
int mi = 0;
|
||||
|
||||
for(int i=0; i<3; i++)
|
||||
if(co[i] != -sub && co[i] != +sub) {
|
||||
dirs.push_back(ctangent(i, vx));
|
||||
dirlimits.push_back(999);
|
||||
mirrors.push_back(cpush(i, -step/2) * cmirror(i) * cpush(i, step/2));
|
||||
}
|
||||
for(int i=0; i<3; i++) {
|
||||
ctr[i] += co[i] * vx;
|
||||
if(co[i] == sub) {
|
||||
mi++;
|
||||
dirs.push_back(ctangent(i, vx));
|
||||
dirlimits.push_back(0);
|
||||
mirrors.push_back(cpush(i, +step/2) * cmirror(i) * cpush(i, -step/2));
|
||||
auto& dii = di[i];
|
||||
if(co[i] >= 0) {
|
||||
dii.dir = ctangent(i, vx);
|
||||
dii.limit = sub - co[i];
|
||||
dii.mirror = cpush(i, +step/2) * cmirror(i) * cpush(i, -step/2);
|
||||
}
|
||||
else if(co[i] == -sub) {
|
||||
mi++;
|
||||
dirs.push_back(ctangent(i, -vx));
|
||||
dirlimits.push_back(0);
|
||||
mirrors.push_back(cpush(i, -step/2) * cmirror(i) * cpush(i, +step/2));
|
||||
else {
|
||||
dii.dir = ctangent(i, -vx);
|
||||
dii.limit = co[i] + sub;
|
||||
dii.mirror = cpush(i, -step/2) * cmirror(i) * cpush(i, +step/2);
|
||||
}
|
||||
if(dii.limit == 0) mi++;
|
||||
}
|
||||
|
||||
sort(di.begin(), di.end(), [] (direction& d1, direction& d2) { return d1.limit > d2.limit; });
|
||||
|
||||
cgi.subshapes.emplace_back();
|
||||
auto &ss = cgi.subshapes.back();
|
||||
|
||||
auto pt = [&] (ld x, ld y, ld z) {
|
||||
transmatrix M = Id;
|
||||
if(x > dirlimits[0]) x = -x, M = mirrors[0] * M;
|
||||
if(y > dirlimits[1]) y = -y, M = mirrors[1] * M;
|
||||
if(z > dirlimits[2]) z = -z, M = mirrors[2] * M;
|
||||
return normalize(M * (ctr + dirs[0] * x + dirs[1] * y + dirs[2] * z));
|
||||
if(x > di[0].limit) x = -x, M = di[0].mirror * M;
|
||||
if(y > di[1].limit) y = -y, M = di[1].mirror * M;
|
||||
if(z > di[2].limit) z = -z, M = di[2].mirror * M;
|
||||
return normalize(M * (ctr + di[0].dir * x + di[1].dir * y + di[2].dir * z));
|
||||
};
|
||||
|
||||
auto add_face = [&] (std::initializer_list<hyperpoint> vh) {
|
||||
@ -374,17 +376,17 @@ EX namespace reg3 {
|
||||
add_face({pt(0,.5,s), pt(.5,0,s), pt(0,-.5,s), pt(-.5,0,s)});
|
||||
else
|
||||
add_face({pt(-1,-1,s), pt(-1,+1,s), pt(+1,+1,s), pt(+1,-1,s)});
|
||||
tie(dirs[0], dirs[1], dirs[2]) = make_tuple(dirs[1], dirs[2], dirs[0]);
|
||||
tie(di[0], di[1], di[2]) = make_tuple(di[1], di[2], di[0]);
|
||||
}
|
||||
}
|
||||
if(bch) for(int u=0; u<8; u++) {
|
||||
for(int j=0; j<3; j++) if((u>>j)&1) dirs[j] = -dirs[j];
|
||||
for(int j=0; j<3; j++) if((u>>j)&1) di[j].flip();
|
||||
add_face({pt(0,.5,1), pt(0,1,.5), pt(.5,1,0), pt(1,.5,0), pt(1,0,.5), pt(.5,0,1)});
|
||||
for(int j=0; j<3; j++) if((u>>j)&1) dirs[j] = -dirs[j];
|
||||
for(int j=0; j<3; j++) if((u>>j)&1) di[j].flip();
|
||||
}
|
||||
}
|
||||
else if(mi == 1) {
|
||||
auto& M = mirrors[2];
|
||||
auto& M = di[2].mirror;
|
||||
for(int s: {-1, 1}) {
|
||||
if(bch)
|
||||
add_face({pt(0,h,s), pt(h,0,s), pt(0,-h,s), pt(-h,0,s)});
|
||||
@ -395,23 +397,23 @@ EX namespace reg3 {
|
||||
add_face({pt(1,0,-.5), pt(1,-.5,0), M*pt(1,0,-.5), pt(1,.5,0)});
|
||||
else
|
||||
add_face({pt(-1,-1,-1), pt(-1,+1,-1), pt(-1,+1,+1), pt(-1,-1,+1)});
|
||||
tie(dirs[0], dirs[1]) = make_tuple(dirs[1], -dirs[0]);
|
||||
tie(di[0], di[1]) = make_tuple(di[1], di[0]); di[0].flip();
|
||||
}
|
||||
}
|
||||
if(bch) for(ld s: {-1, 1}) for(int i=0; i<4; i++) {
|
||||
add_face({pt(0,.5,s), pt(0,1,s/2), pt(.5,1,0), pt(1,.5,0), pt(1,0,s/2), pt(.5,0,s)});
|
||||
tie(dirs[0], dirs[1]) = make_tuple(dirs[1], -dirs[0]);
|
||||
tie(di[0], di[1]) = make_tuple(di[1], di[0]); di[0].flip();
|
||||
}
|
||||
}
|
||||
else {
|
||||
transmatrix spi = mi == 2 ? mirrors[1] * mirrors[2] : mirrors[0] * mirrors[1];
|
||||
transmatrix spi = mi == 2 ? di[1].mirror * di[2].mirror : di[0].mirror * di[1].mirror;
|
||||
if(cgi.loop == 5) spi = spi * spi;
|
||||
vector<transmatrix> spi_power = {Id};
|
||||
for(int i=1; i<cgi.loop; i++) spi_power.push_back(spi_power.back() * spi);
|
||||
if(mi == 2) {
|
||||
for(auto P: spi_power) {
|
||||
if(bch)
|
||||
add_face({P*pt(.5,0,-1), P*pt(0,-.5,-1), P*pt(-.5,0,-1), P*mirrors[1]*pt(0,-.5,-1)});
|
||||
add_face({P*pt(.5,0,-1), P*pt(0,-.5,-1), P*pt(-.5,0,-1), P*pt(0,.5,-1)});
|
||||
else
|
||||
add_face({P*pt(-1,-1,-1), P*pt(1,-1,-1), P*spi*pt(1,-1,-1), P*spi*pt(-1,-1,-1)});
|
||||
}
|
||||
@ -430,8 +432,8 @@ EX namespace reg3 {
|
||||
for(int j=0; j<2; j++)
|
||||
for(auto P1: spi_power) {
|
||||
auto T = face_dirs[i];
|
||||
if(j == 0) T = T * P1 * mirrors[1] * mirrors[2];
|
||||
if(j == 1) T = T * P1 * mirrors[2] * mirrors[0];
|
||||
if(j == 0) T = T * P1 * di[1].mirror * di[2].mirror;
|
||||
if(j == 1) T = T * P1 * di[2].mirror * di[0].mirror;
|
||||
bool fnd = false;
|
||||
for(auto& F: face_dirs)
|
||||
for(auto P: spi_power)
|
||||
|
Loading…
Reference in New Issue
Block a user