1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-06-21 04:39:58 +00:00

moved ray_iadj from hybrid to hrmap method

This commit is contained in:
Zeno Rogue 2021-07-09 19:33:01 +02:00
parent 7da49c9d2f
commit 0aa1d45287
4 changed files with 68 additions and 58 deletions

View File

@ -68,6 +68,13 @@ struct hrmap {
virtual hyperpoint get_corner(cell *c, int cid, ld cf=3) { return C0; }
virtual transmatrix master_relative(cell *c, bool get_inverse = false) { return Id; }
virtual int wall_offset(cell *c);
virtual transmatrix ray_iadj(cell *c, int i) {
if(WDIM == 2) {
return to_other_side(get_corner(c, i), get_corner(c, (i+1)));
}
return currentmap->iadj(c, i);
}
};
/** hrmaps which are based on regular non-Euclidean 2D tilings, possibly quotient

View File

@ -1000,33 +1000,6 @@ EX namespace hybrid {
EX int disc_quotient = 0;
EX transmatrix ray_iadj(cell *c, int i) {
if(prod && i == c->type-2) return (mscale(Id, +cgi.plevel));
if(prod && i == c->type-1) return (mscale(Id, -cgi.plevel));
if(WDIM == 2) {
return to_other_side(get_corner_position(c, i), get_corner_position(c, (i+1)));
}
if(prod) {
transmatrix T;
cell *cw = hybrid::get_where(c).first;
hybrid::in_underlying_geometry([&] {
T = to_other_side(get_corner_position(cw, i), get_corner_position(cw, (i+1)));
});
return T;
}
#if MAXMDIM >= 4
if(rotspace) return rots::ray_iadj(c, i);
#endif
if(is_subcube_based(variation)) {
auto& v = reg3::get_face_vertices(c, i);
hyperpoint h =
project_on_triangle(v[0], v[1], v[2]);
transmatrix T = rspintox(h);
return T * xpush(-2*hdist0(h)) * spintox(h);
}
return currentmap->iadj(c, i);
}
EX void configure(eGeometry g) {
if(WDIM == 3) return;
ray::reset_raycaster();
@ -1528,6 +1501,17 @@ EX namespace product {
});
}
}
virtual transmatrix ray_iadj(cell *c, int i) override {
if(i == c->type-2) return (mscale(Id, +cgi.plevel));
if(i == c->type-1) return (mscale(Id, -cgi.plevel));
transmatrix T;
cell *cw = hybrid::get_where(c).first;
hybrid::in_underlying_geometry([&] {
T = currentmap->ray_iadj(cw, i);
});
return T;
}
};
EX bool current_spin_invalid, cmirror;
@ -2006,34 +1990,6 @@ EX namespace rots {
EX std::map<int, transmatrix> saved_matrices_ray;
EX transmatrix ray_iadj(cell *c1, int i) {
if(i == c1->type-1) return uzpush(-cgi.plevel) * spin(-2*cgi.plevel);
if(i == c1->type-2) return uzpush(+cgi.plevel) * spin(+2*cgi.plevel);
cell *c2 = c1->cmove(i);
#if CAP_ARCM
int id1 = hybrid::underlying == gArchimedean ? arcm::id_of(c1->master) + 20 * arcm::parent_index_of(c1->master) : shvid(c1);
int id2 = hybrid::underlying == gArchimedean ? arcm::id_of(c2->master) + 20 * arcm::parent_index_of(c2->master) : shvid(c2);
#else
int id1 = shvid(c1);
int id2 = shvid(c2);
#endif
int j = c1->c.spin(i);
int id = id1 + (id2 << 10) + (i << 20) + (j << 26);
auto &M = saved_matrices_ray[id];
if(M[3][3]) return M;
cell *cw = hybrid::get_where(c1).first;
transmatrix T;
hybrid::in_underlying_geometry([&] {
hyperpoint h0 = get_corner_position(cw, i);
hyperpoint h1 = get_corner_position(cw, (i+1));
T = to_other_side(h0, h1);
});
return M = lift_matrix(T);
}
struct hrmap_rotation_space : hybrid::hrmap_hybrid {
std::map<int, transmatrix> saved_matrices;
@ -2066,6 +2022,33 @@ EX namespace rots {
return Id; // not implemented yet
}
virtual transmatrix ray_iadj(cell *c1, int i) override {
if(i == c1->type-1) return uzpush(-cgi.plevel) * spin(-2*cgi.plevel);
if(i == c1->type-2) return uzpush(+cgi.plevel) * spin(+2*cgi.plevel);
cell *c2 = c1->cmove(i);
#if CAP_ARCM
int id1 = hybrid::underlying == gArchimedean ? arcm::id_of(c1->master) + 20 * arcm::parent_index_of(c1->master) : shvid(c1);
int id2 = hybrid::underlying == gArchimedean ? arcm::id_of(c2->master) + 20 * arcm::parent_index_of(c2->master) : shvid(c2);
#else
int id1 = shvid(c1);
int id2 = shvid(c2);
#endif
int j = c1->c.spin(i);
int id = id1 + (id2 << 10) + (i << 20) + (j << 26);
auto &M = saved_matrices_ray[id];
if(M[3][3]) return M;
cell *cw = hybrid::get_where(c1).first;
transmatrix T;
hybrid::in_underlying_geometry([&] {
hyperpoint h0 = get_corner_position(cw, i);
hyperpoint h1 = get_corner_position(cw, (i+1));
T = to_other_side(h0, h1);
});
return M = lift_matrix(T);
}
};
/** reinterpret the given point of rotspace as a rotation matrix in the underlying geometry (note: this is the inverse) */

View File

@ -1567,7 +1567,7 @@ struct raycast_map {
cell *c = p.second;
if(!c) continue;
for(int j=0; j<c->type; j++)
ms[id+j] = hybrid::ray_iadj(c, j);
ms[id+j] = currentmap->ray_iadj(c, j);
if(WDIM == 2) for(int a: {0, 1}) {
ms[id+c->type+a] = get_ms(c, a, false);
}
@ -1873,7 +1873,7 @@ EX void cast() {
back:
for(int a=0; a<cs->type; a++)
if(hdist0(hybrid::ray_iadj(cs, a) * tC0(T)) < hdist0(tC0(T))) {
if(hdist0(currentmap->ray_iadj(cs, a) * tC0(T)) < hdist0(tC0(T))) {
T = currentmap->iadj(cs, a) * T;
if(o->uToOrig != -1) {
transmatrix HT = currentmap->adj(cs, a);

View File

@ -671,14 +671,25 @@ EX namespace reg3 {
int wall_offset(cell *c) override;
int shvid(cell *c) { return local_id.at(c).second; }
virtual transmatrix ray_iadj(cell *c, int i) override;
};
struct hrmap_quotient3 : hrmap_closed3 { };
#endif
transmatrix hrmap_closed3::ray_iadj(cell *c, int i) {
if(PURE) return iadj(c, i);
auto& v = get_face_vertices(c, i);
hyperpoint h =
project_on_triangle(v[0], v[1], v[2]);
transmatrix T = rspintox(h);
return T * xpush(-2*hdist0(h)) * spintox(h);
}
int hrmap_closed3::wall_offset(cell *c) {
if(PURE) return 0;
auto& wo = cgi.walloffsets[ local_id[c].second ];
auto& wo = cgi.walloffsets[ local_id.at(c).second ];
if(wo.second == nullptr)
wo.second = c;
return wo.first;
@ -1838,12 +1849,14 @@ EX namespace reg3 {
int wall_offset(cell *c) override {
if(PURE) return 0;
if(!cell_id.count(c)) return quotient_map->wall_offset(c); /* necessary because ray samples are from quotient_map */
int aid = cell_id.at(c);
return quotient_map->wall_offset(quotient_map->acells[aid]);
}
transmatrix adj(cell *c, int d) override {
if(PURE) return adj(c->master, d);
if(!cell_id.count(c)) return quotient_map->adj(c, d); /* necessary because ray samples are from quotient_map */
int aid = cell_id.at(c);
return quotient_map->tmatrices_cell[aid][d];
}
@ -1882,6 +1895,13 @@ EX namespace reg3 {
cell *c1 = get_cell_at(h, quotient_map->local_id[ac->move(d)].first);
c->c.connect(d, c1, ac->c.spin(d), false);
}
virtual transmatrix ray_iadj(cell *c, int i) {
if(PURE) return iadj(c, i);
if(!cell_id.count(c)) return quotient_map->ray_iadj(c, i); /* necessary because ray samples are from quotient_map */
int aid = cell_id.at(c);
return quotient_map->ray_iadj(quotient_map->acells[aid], i);
}
};
struct hrmap_h3_rule_alt : hrmap {