intra:: fixed portals to/from S3 and H3

This commit is contained in:
Zeno Rogue 2022-02-26 09:49:46 +01:00
parent 6b17cd6412
commit 80b9d9533c
2 changed files with 16 additions and 2 deletions

View File

@ -91,6 +91,10 @@ hyperpoint portal_data::to_poco(hyperpoint h) const {
else {
h = T * h;
h /= h[3];
if(sphere)
h[2] /= sqrt(1+h[0]*h[0]+h[1]*h[1]);
if(hyperbolic)
h[2] /= sqrt(1-h[0]*h[0]-h[1]*h[1]);
return h;
}
}
@ -126,6 +130,10 @@ hyperpoint portal_data::from_poco(hyperpoint h) const {
}
else {
h[3] = 1;
if(sphere)
h[2] *= sqrt(1+h[0]*h[0]+h[1]*h[1]);
if(hyperbolic)
h[2] *= sqrt(1-h[0]*h[0]-h[1]*h[1]);
return normalize(iT * h);
}
}

View File

@ -1575,22 +1575,28 @@ void raygen::add_functions() {
add_if("to_poco_h3",
"mediump vec4 to_poco_h3(mediump vec4 pos) {\n"
" return pos / pos[3];\n"
" pos = pos / pos[3];\n"
" pos[2] /= sqrt(1.-pos.x*pos.x-pos.y*pos.y);\n"
" return pos;\n"
" }\n\n");
add_if("from_poco_h3",
"mediump vec4 from_poco_h3(mediump vec4 pos) {\n"
" pos[2] *= sqrt(1.-pos.x*pos.x-pos.y*pos.y);\n"
" float s = 1. - dot(pos.xyz, pos.xyz);\n"
" return pos / sqrt(s);\n"
" }\n\n");
add_if("to_poco_s3",
"mediump vec4 to_poco_s3(mediump vec4 pos) {\n"
" return pos / pos[3];\n"
" pos = pos / pos[3];\n"
" pos[2] /= sqrt(1.+pos.x*pos.x+pos.y*pos.y);\n"
" return pos;\n"
" }\n\n");
add_if("from_poco_s3",
"mediump vec4 from_poco_s3(mediump vec4 pos) {\n"
" pos[2] *= sqrt(1.+pos.x*pos.x+pos.y*pos.y);\n"
" float s = 1. + dot(pos.xyz, pos.xyz);\n"
" return pos / sqrt(s);\n"
" }\n\n");