Skip to content

Commit ae9b1aa

Browse files
committedNov 16, 2017
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.
1 parent ee6bb5a commit ae9b1aa

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed
 

Diff for: ‎src/camera.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
458458
} else {
459459
fov_degrees = m_cache_fov;
460460
}
461-
fov_degrees = rangelim(fov_degrees, 7.0, 160.0);
461+
fov_degrees = rangelim(fov_degrees, 1.0, 160.0);
462462

463463
// FOV and aspect ratio
464464
const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
@@ -550,7 +550,8 @@ void Camera::updateViewingRange()
550550
{
551551
f32 viewing_range = g_settings->getFloat("viewing_range");
552552
f32 near_plane = g_settings->getFloat("near_plane");
553-
m_draw_control.wanted_range = viewing_range;
553+
554+
m_draw_control.wanted_range = std::fmin(adjustDist(viewing_range, getFovMax()), 4000);
554555
m_cameranode->setNearValue(rangelim(near_plane, 0.0f, 0.5f) * BS);
555556
if (m_draw_control.range_all) {
556557
m_cameranode->setFarValue(100000.0);

Diff for: ‎src/clientiface.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,20 @@ void RemoteClient::GetNextBlocks (
196196
s16 wanted_range = sao->getWantedRange() + 1;
197197
float camera_fov = sao->getFov();
198198

199+
const s16 full_d_max = std::min(adjustDist(m_max_send_distance, camera_fov), wanted_range);
200+
const s16 d_opt = std::min(adjustDist(m_block_optimize_distance, camera_fov), wanted_range);
201+
const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
202+
infostream << "Fov from client " << camera_fov << " full_d_max " << full_d_max << std::endl;
203+
204+
s16 d_max = full_d_max;
205+
s16 d_max_gen = std::min(adjustDist(m_max_gen_distance, camera_fov), wanted_range);
206+
207+
// Don't loop very much at a time, adjust with distance,
208+
// do more work per RTT with greater distances.
209+
s16 max_d_increment_at_time = full_d_max / 9 + 1;
210+
if (d_max > d_start + max_d_increment_at_time)
211+
d_max = d_start + max_d_increment_at_time;
212+
199213
// cos(angle between velocity and camera) * |velocity|
200214
// Limit to 0.0f in case player moves backwards.
201215
f32 dot = rangelim(camera_dir.dotProduct(playerspeed), 0.0f, 300.0f);
@@ -204,19 +218,6 @@ void RemoteClient::GetNextBlocks (
204218
// limit max fov effect to 50%, 60% at 20n/s fly speed
205219
camera_fov = camera_fov / (1 + dot / 300.0f);
206220

207-
const s16 full_d_max = std::min(m_max_send_distance, wanted_range);
208-
const s16 d_opt = std::min(m_block_optimize_distance, wanted_range);
209-
const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
210-
//infostream << "Fov from client " << camera_fov << " full_d_max " << full_d_max << std::endl;
211-
212-
s16 d_max = full_d_max;
213-
s16 d_max_gen = std::min(m_max_gen_distance, wanted_range);
214-
215-
// Don't loop very much at a time
216-
s16 max_d_increment_at_time = 2;
217-
if (d_max > d_start + max_d_increment_at_time)
218-
d_max = d_start + max_d_increment_at_time;
219-
220221
s32 nearest_emerged_d = -1;
221222
s32 nearest_emergefull_d = -1;
222223
s32 nearest_sent_d = -1;

Diff for: ‎src/util/numeric.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include "noise.h" // PseudoRandom, PcgRandom
2525
#include "threading/mutex_auto_lock.h"
2626
#include <cstring>
27+
#include <cmath>
2728

2829

2930
// myrand
@@ -161,3 +162,16 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
161162

162163
return true;
163164
}
165+
166+
s16 adjustDist(s16 dist, float zoom_fov)
167+
{
168+
// 1.775 ~= 72 * PI / 180 * 1.4, the default on the client
169+
const float default_fov = 1.775f;
170+
// heuristic cut-off for zooming
171+
if (zoom_fov > default_fov / 2.0f)
172+
return dist;
173+
174+
// new_dist = dist * ((1 - cos(FOV / 2)) / (1-cos(zoomFOV /2))) ^ (1/3)
175+
return round(dist * cbrt((1.0f - cos(default_fov / 2.0f)) /
176+
(1.0f - cos(zoom_fov / 2.0f))));
177+
}

Diff for: ‎src/util/numeric.h

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed);
232232
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
233233
f32 camera_fov, f32 range, f32 *distance_ptr=NULL);
234234

235+
s16 adjustDist(s16 dist, float zoom_fov);
236+
235237
/*
236238
Returns nearest 32-bit integer for given floating point number.
237239
<cmath> and <math.h> in VC++ don't provide round().

0 commit comments

Comments
 (0)
Please sign in to comment.