X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Futil%2Fnumeric.cpp;h=cb984d8cb5b60879f7f11bb158c2162afca11848;hb=67a4cb7d8a4461fe7d5206189fd4e9539beb20b7;hp=a48a72a8a8e8c912d8d2062c2423f2123ee9b75a;hpb=88b436e6a9c98af7215bd115e1b7a3f1a1db99d3;p=minetest.git diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index a48a72a8a..cb984d8cb 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -20,10 +20,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "numeric.h" #include "log.h" -#include "../constants.h" // BS, MAP_BLOCKSIZE -#include "../noise.h" // PseudoRandom, PcgRandom -#include "../threading/mutex_auto_lock.h" +#include "constants.h" // BS, MAP_BLOCKSIZE +#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 - std::cos(default_fov / 2.0f)) / + (1.0f - std::cos(zoom_fov / 2.0f)))); +}