From ae9b1aa1774aedca8f452514d9462c281e36773a Mon Sep 17 00:00:00 2001 From: Lars Hofhansl Date: Wed, 15 Nov 2017 21:58:23 -0800 Subject: Allow zoom to actually show more data. This allows the client to retrieve blocks at a greater distance from the server, thus allowing for a real zoom. --- src/util/numeric.cpp | 14 ++++++++++++++ src/util/numeric.h | 2 ++ 2 files changed, 16 insertions(+) (limited to 'src/util') diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index ebc81185f..12c91be91 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "noise.h" // PseudoRandom, PcgRandom #include "threading/mutex_auto_lock.h" #include +#include // myrand @@ -161,3 +162,16 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, return true; } + +s16 adjustDist(s16 dist, float zoom_fov) +{ + // 1.775 ~= 72 * PI / 180 * 1.4, the default on the client + const float default_fov = 1.775f; + // heuristic cut-off for zooming + if (zoom_fov > default_fov / 2.0f) + return dist; + + // new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3) + return round(dist * cbrt((1.0f - cos(default_fov / 2.0f)) / + (1.0f - cos(zoom_fov / 2.0f)))); +} diff --git a/src/util/numeric.h b/src/util/numeric.h index 347e7a49e..8ee2d585c 100644 --- a/src/util/numeric.h +++ b/src/util/numeric.h @@ -232,6 +232,8 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed); bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov, f32 range, f32 *distance_ptr=NULL); +s16 adjustDist(s16 dist, float zoom_fov); + /* Returns nearest 32-bit integer for given floating point number. and in VC++ don't provide round(). -- cgit v1.2.3