Skip to content

Commit b98f98b

Browse files
Rogier-5Zeno-
authored andcommittedNov 11, 2016
Fix incorrect distance computation for visible blocks (#4765)
The client would not compute the distance from the camera to to a mapblock correctly. The result was that blocks that were in view (i.e. not beyond the fog limit) would not be rendered. With the improved distance computation, a range adjustment that existed in clientiface.cpp is no longer required.
1 parent 7e17eae commit b98f98b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

‎src/clientiface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void RemoteClient::GetNextBlocks (
175175

176176
const s16 full_d_max = g_settings->getS16("max_block_send_distance");
177177
const s16 d_opt = g_settings->getS16("block_send_optimize_distance");
178-
const s16 d_blocks_in_sight = (full_d_max + 1) * BS * MAP_BLOCKSIZE;
178+
const s16 d_blocks_in_sight = full_d_max * BS * MAP_BLOCKSIZE;
179179

180180
s16 d_max = full_d_max;
181181
s16 d_max_gen = g_settings->getS16("max_block_generate_distance");

‎src/util/numeric.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,19 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
188188
}
189189

190190
/*
191-
blockpos: position of block in block coordinates
191+
blockpos_b: position of block in block coordinates
192192
camera_pos: position of camera in nodes
193193
camera_dir: an unit vector pointing to camera direction
194194
range: viewing range
195+
distance_ptr: return location for distance from the camera
195196
*/
196197
bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
197198
f32 camera_fov, f32 range, f32 *distance_ptr)
198199
{
200+
// Maximum radius of a block. The magic number is
201+
// sqrt(3.0) / 2.0 in literal form.
202+
const f32 block_max_radius = 0.866025403784 * MAP_BLOCKSIZE * BS;
203+
199204
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
200205

201206
// Block center position
@@ -209,7 +214,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
209214
v3f blockpos_relative = blockpos - camera_pos;
210215

211216
// Total distance
212-
f32 d = blockpos_relative.getLength();
217+
f32 d = MYMAX(0, blockpos_relative.getLength() - block_max_radius);
213218

214219
if(distance_ptr)
215220
*distance_ptr = d;
@@ -218,13 +223,9 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
218223
if(d > range)
219224
return false;
220225

221-
// Maximum radius of a block. The magic number is
222-
// sqrt(3.0) / 2.0 in literal form.
223-
f32 block_max_radius = 0.866025403784 * MAP_BLOCKSIZE * BS;
224-
225226
// If block is (nearly) touching the camera, don't
226227
// bother validating further (that is, render it anyway)
227-
if(d < block_max_radius)
228+
if(d == 0)
228229
return true;
229230

230231
// Adjust camera position, for purposes of computing the angle,

0 commit comments

Comments
 (0)
Please sign in to comment.