From 80b9d9533c4f9ccf430f2223c81b834eb78ca548 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 26 Feb 2022 09:49:46 +0100 Subject: [PATCH] intra:: fixed portals to/from S3 and H3 --- intra.cpp | 8 ++++++++ raycaster.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/intra.cpp b/intra.cpp index 52a5ef35..ec417d61 100644 --- a/intra.cpp +++ b/intra.cpp @@ -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); } } diff --git a/raycaster.cpp b/raycaster.cpp index a0c5583d..0d304f7e 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -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");