hyperrogue/rogueviz/hypcity.cpp

95 lines
2.1 KiB
C++

#include "rogueviz.h"
// 'hyperbolic city' demo
// download the model from https://sketchfab.com/3d-models/night-city-p2-82637933a7cb4fafadb0e2a79415c438 as rogueviz/models/emilejohansson_p2.obj
// see the results posted here:
// https://twitter.com/ZenoRogue/status/1375750351391981570
// -noplayer -geo 4x5 -gp 1 1 -unrectified -switch-fpp -canvas 303030 camera=0 depth=0 -sr 3 -PM 0 -alpha 1 -zoom .95
// https://twitter.com/ZenoRogue/status/1375748835046215682
// -noplayer -geo nil -canvas 303030 -back 44e4 -sight3 3
// https://twitter.com/ZenoRogue/status/1375754422752575488
// add -PM 0 -alpha 1
namespace hr {
using namespace rogueviz::objmodels;
model city("rogueviz/models/", "emilejohansson_p2.obj");
hyperpoint low, high;
void prepare_tf() {
if(!city.models.empty()) return;
prec = 40;
for(int i=0; i<4; i++) low[i] = 100, high[i] = -100;
cgi.require_basics();
hyperpoint corner = get_corner_position(cwt.at, 0);
ld t = abs(corner[0] / corner[3]);
city.tf = [=] (hyperpoint h) -> pair<int, hyperpoint> {
swap(h[1], h[2]);
h[2] = -h[2];
h[2] += 0.063;
h[0] -= 0.063;
h[1] += 0.063;
h *= 6;
// h[0] -= .5;
// h[1] += .5;
for(int i=0; i<4; i++)
low[i] = min(low[i], h[i]),
high[i] = max(high[i], h[i]);
if(hyperbolic) {
hyperpoint hx;
hx[0] = h[0] * t * 2;
hx[1] = h[1] * t * 2;
hx[2] = 0;
hx[3] = 1;
hx = spin(45 * degree) * hx;
normalize(hx);
hx = zshift(hx, h[2]*(t*7));
return {0, hx};
}
if(nil) {
swap(h[1], h[2]);
h *= 0.5 / 0.378;
h[3] = 1;
return {0, h};
}
return {0, h};
};
println(hlog, "low = ", low);
println(hlog, "high = ", high);
}
bool draw_city_at(cell *c, const shiftmatrix& V) {
prepare_tf();
if(nil) {
auto co = nilv::get_coord(c->master);
if(co[1]) return false;
}
if(c == cwt.at || true)
city.render(V);
return false;
}
auto hypcity_ah = addHook(hooks_drawcell, 100, draw_city_at);
}