intra:: cleaner scale changing

This commit is contained in:
Zeno Rogue 2023-11-30 12:34:41 +01:00
parent c94e927929
commit c69bed4d12
3 changed files with 30 additions and 20 deletions

View File

@ -2262,6 +2262,10 @@ EX void optimizeview() {
View = iview_inverse(iView);
fixmatrix(View);
callhooks(hooks_postoptimize);
#if CAP_PORTALS
intra::apply_scale();
#endif
walking::handle();

View File

@ -527,21 +527,21 @@ EX void analyze_orthonormal(array<hyperpoint, 4> ds, ld sca) {
}
EX void shift_view_portal(hyperpoint H) {
shift_view(H);
shift_view(H * scale);
if(!through_portal()) return;
shift_view(-H);
shift_view(-H * scale);
ld minv = 0, maxv = 1;
for(int i=0; i<30; i++) {
ld t = (minv + maxv) / 2;
shift_view(H * t);
shift_view(H * t * scale);
bool b = through_portal();
if(b) maxv = t; else minv = t;
shift_view(H * -t);
shift_view(H * -t * scale);
}
println(hlog, "maxv = ", maxv);
shift_view(H * maxv);
shift_view(H * maxv * scale);
check_portal_movement();
shift_view_portal(H * (1 - maxv));
shift_view_portal(H * (1 - maxv) * scale);
}
EX const connection_data* through_portal() {
@ -552,6 +552,8 @@ EX const connection_data* through_portal() {
return at_or_null(connections, cw1);
}
EX ld scale = 1;
EX void check_portal_movement() {
auto p = through_portal();
@ -620,20 +622,27 @@ EX void check_portal_movement() {
#endif
}
ld scale = p->id2.scale / p->id1.scale;
camera_speed *= scale;
anims::cycle_length *= scale;
#if CAP_VR
vrhr::absolute_unit_in_meters *= scale;
#endif
if(walking::eye_level != -1) walking::eye_level *= scale;
scale *= p->id2.scale / p->id1.scale;
walking::floor_dir = -1;
walking::on_floor_of = nullptr;
}
}
EX void apply_scale() {
if(scale != 1) {
camera_speed *= scale;
anims::cycle_length *= scale;
vid.ipd *= scale;
#if CAP_VR
vrhr::absolute_unit_in_meters *= scale;
#endif
if(walking::eye_level != -1) walking::eye_level *= scale;
scale = 1;
}
}
vector<cellwalker> unconnected;
void erase_unconnected(cellwalker cw) {

9
vr.cpp
View File

@ -1095,12 +1095,9 @@ EX void render() {
dynamicval<transmatrix> tV(View, View);
dynamicval<transmatrix> tC(current_display->which_copy, current_display->which_copy);
dynamicval<transmatrix> trt(current_display->radar_transform);
/* changed in intra */
dynamicval<ld> tcs(camera_speed);
dynamicval<ld> tcl(anims::cycle_length);
dynamicval<ld> tau(vrhr::absolute_unit_in_meters);
dynamicval<ld> tel(walking::eye_level);
dynamicval<ld> tcs(intra::scale);
// just in case
dynamicval<int> tfd(walking::floor_dir);
dynamicval<cell*> tof(walking::on_floor_of);