intra:: H3-bt portals (preliminary)

This commit is contained in:
Zeno Rogue 2021-10-03 10:19:45 +02:00
parent 1458929a5d
commit 6fea0c31e4
2 changed files with 80 additions and 8 deletions

View File

@ -63,6 +63,8 @@ hyperpoint portal_data::to_poco(hyperpoint h) const {
h[3] = 1;
return h;
}
else if(hyperbolic && bt::in())
return T * bt::minkowski_to_bt(h);
else {
h = T * h;
h /= h[3];
@ -86,6 +88,8 @@ hyperpoint portal_data::from_poco(hyperpoint h) const {
h[3] = 1;
return iT * h * exp(h0[1]);
}
else if(hyperbolic && bt::in())
return bt::bt_to_minkowski(iT * h);
else {
h[3] = 1;
return normalize(iT * h);
@ -94,7 +98,7 @@ hyperpoint portal_data::from_poco(hyperpoint h) const {
EX portal_data make_portal(cellwalker cw, int spin) {
auto& ss = currentmap->get_cellshape(cw.at);
auto& fac = ss.faces[cw.spin];
auto fac = ss.faces[cw.spin];
portal_data id;
id.scale = 1;
if(prod && cw.spin == cw.at->type - 1) {
@ -121,6 +125,24 @@ EX portal_data make_portal(cellwalker cw, int spin) {
println(hlog, kz(h), " -> ", kz(spintox(id.v0)*h), " -> ", kz(cpush(0, -hdist0(id.v0))) * kz(spintox(id.v0) * h), " -> ", kz(id.to_poco(h)));
}
}
else if(hyperbolic && bt::in()) {
if(isize(fac) == 5) fac.erase(fac.begin() + 1);
id.kind = 0;
id.v0 = Hypc;
id.T = Id;
for(auto& h: fac) h[3] = 1;
for(auto p: fac) id.v0 += p;
id.v0 /= isize(fac);
dynamicval<eGeometry> g(geometry, gCubeTiling);
id.T = gpushxto0(id.v0);
for(auto p: fac) {
if(abs((id.T * p)[2]) > 1e-3 && abs((id.T * p)[0]) < 1e-3)
id.T = cspin(2, 0, 90*degree) * id.T;
if(abs((id.T * p)[2]) > 1e-3 && abs((id.T * p)[1]) < 1e-3)
id.T = cspin(2, 1, 90*degree) * id.T;
}
if((id.T * C03)[2] > 0) id.T = cspin(2, 0, 180*degree) * id.T;
}
else {
id.kind = 0;
id.v0 = Hypc;
@ -134,8 +156,9 @@ EX portal_data make_portal(cellwalker cw, int spin) {
int second = spin + 1;
first = gmod(first, isize(fac));
second = gmod(second, isize(fac));
id.co0 = id.to_poco(fac[first]);
id.co1 = id.to_poco(fac[second]);
id.co0 = id.to_poco(final_coords(fac[first]));
id.co1 = id.to_poco(final_coords(fac[second]));
return id;
}

View File

@ -999,6 +999,13 @@ void raygen::emit_intra_portal(int gid1, int gid2) {
}
fmain += " }\n";
}
else if(hyperbolic && bt::in()) {
fmain +=
" mediump vec4 nposition = position + tangent * 1e-3;\n"
" mediump mat4 tkt = " + getM("mid+1") + ";\n"
" position = tkt * minkowski_to_bt(position);\n"
" nposition = tkt * minkowski_to_bt(nposition);\n";
}
else {
fmain +=
" mediump vec4 nposition = position + tangent * 1e-3;\n"
@ -1062,14 +1069,23 @@ void raygen::emit_intra_portal(int gid1, int gid2) {
fmain += "}\n";
}
else {
string sgn = hyperbolic ? "-" : "+";
string he = hyperbolic ? "from_poco_h3" : "from_poco_s3";
fmain +=
" mediump mat4 itkt = " + getM("mid+2") + ";\n";
if(hyperbolic || sphere) fmain +=
if(hyperbolic || sphere) {
string sgn = hyperbolic ? "-" : "+";
if(hyperbolic && bt::in()) {
fmain +=
" position = bt_to_minkowski(itkt * position);\n"
" nposition = bt_to_minkowski(itkt * nposition);\n";
}
else {
string he = hyperbolic ? "from_poco_h3" : "from_poco_s3";
fmain +=
" position = itkt * "+he+"(position);\n"
" nposition = itkt * "+he+"(nposition);\n"
" nposition = itkt * "+he+"(nposition);\n";
}
fmain +=
" tangent = (nposition - position) * 1e3;\n"
" mediump float pnorm = position.w * position.w "+sgn+" dot(position.xyz, position.xyz);\n"
" position /= sqrt(pnorm);\n"
@ -1077,6 +1093,7 @@ void raygen::emit_intra_portal(int gid1, int gid2) {
" tangent -= position * pnorm;\n"
" mediump float xspeed = sqrt(dot(tangent.xyz, tangent.xyz) "+sgn+" tangent.w * tangent.w);\n"
" tangent /= xspeed;\n";
}
else fmain +=
" position = itkt * position;\n"
@ -1316,7 +1333,39 @@ void raygen::emit_iterate(int gid1) {
if(!intra::in) fmain += no_intra_portal;
else {
if(hyperbolic) {
if(hyperbolic && bt::in()) {
fsh +=
"mediump vec4 minkowski_to_bt(mediump vec4 h) {\n"
" h /= (1. + h[3]);\n"
" h[0] -= 1.;\n"
" h /= h.x*h.x + h.y*h.y + h.z * h.z;\n"
" h[0] += .5;\n"
" float co = " + to_glsl(vid.binary_width / log(2) / 8) + ";\n"
" mediump vec4 res;\n"
" res.x = h.y / co;\n"
" res.y = h.z / co;\n"
" res.z = (log(2.) + log(-h.x)) / (log(2.)/2.);\n"
" res.w = 1.;\n"
" return res;\n"
" }\n\n"
"mediump vec4 bt_to_minkowski(mediump vec4 h) {\n"
" h.z = h.z * " + to_glsl(log(2)/2) + ";\n"
" mediump vec4 res;\n"
" float co = " + to_glsl(vid.binary_width / log(2) / 4) + ";\n"
" h.x *= co; h.y *= co;\n"
" float diag = (h.x*h.x + h.y*h.y)/2.;\n"
" float px = sinh(h.z);\n"
" float pw = cosh(h.z);\n"
" res.x = (1.-diag) * px + diag * pw;\n"
" res.y = (-h.x) * px + h.x * pw;\n"
" res.z = (-h.y) * px + h.y * pw;\n"
" res.w = (-diag) * px + (1.+diag) * pw;\n"
" return res;\n"
" }\n\n";
}
else if(hyperbolic) {
fsh +=
"mediump vec4 to_poco_h3(mediump vec4 pos) {\n"
" return pos / pos[3];\n"