From 062de11b4cff30861dd4e9eb56f131d821f34b51 Mon Sep 17 00:00:00 2001 From: Novatux Date: Sun, 26 Jan 2014 11:40:21 +0100 Subject: Fix rendering glitches when far from the center of the map --- src/game.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 196d1e316..18e69c132 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -228,6 +228,7 @@ PointedThing getPointedThing(Client *client, v3f player_position, core::line3d shootline, f32 d, bool liquids_pointable, bool look_for_object, + v3s16 camera_offset, std::vector &hilightboxes, ClientActiveObject *&selected_object) { @@ -258,8 +259,8 @@ PointedThing getPointedThing(Client *client, v3f player_position, v3f pos = selected_object->getPosition(); hilightboxes.push_back(aabb3f( - selection_box->MinEdge + pos, - selection_box->MaxEdge + pos)); + selection_box->MinEdge + pos - intToFloat(camera_offset, BS), + selection_box->MaxEdge + pos - intToFloat(camera_offset, BS))); } mindistance = (selected_object->getPosition() - camera_position).getLength(); @@ -361,8 +362,8 @@ PointedThing getPointedThing(Client *client, v3f player_position, i2 != boxes.end(); i2++) { aabb3f box = *i2; - box.MinEdge += npf + v3f(-d,-d,-d); - box.MaxEdge += npf + v3f(d,d,d); + box.MinEdge += npf + v3f(-d,-d,-d) - intToFloat(camera_offset, BS); + box.MaxEdge += npf + v3f(d,d,d) - intToFloat(camera_offset, BS); hilightboxes.push_back(box); } } @@ -2541,6 +2542,8 @@ void the_game( Update camera */ + v3s16 old_camera_offset = camera.getOffset(); + LocalPlayer* player = client.getEnv().getLocalPlayer(); float full_punch_interval = playeritem_toolcap.full_punch_interval; float tool_reload_ratio = time_from_last_punch / full_punch_interval; @@ -2554,10 +2557,19 @@ void the_game( v3f camera_position = camera.getPosition(); v3f camera_direction = camera.getDirection(); f32 camera_fov = camera.getFovMax(); + v3s16 camera_offset = camera.getOffset(); + + bool camera_offset_changed = (camera_offset != old_camera_offset); if(!disable_camera_update){ client.getEnv().getClientMap().updateCamera(camera_position, - camera_direction, camera_fov); + camera_direction, camera_fov, camera_offset); + if (camera_offset_changed){ + client.updateCameraOffset(camera_offset); + client.getEnv().updateCameraOffset(camera_offset); + if (clouds) + clouds->updateCameraOffset(camera_offset); + } } // Update sound listener @@ -2600,6 +2612,7 @@ void the_game( &client, player_position, camera_direction, camera_position, shootline, d, playeritem_def.liquids_pointable, !ldown_for_dig, + camera_offset, // output hilightboxes, selected_object); @@ -3030,7 +3043,7 @@ void the_game( Update particles */ - allparticles_step(dtime, client.getEnv()); + allparticles_step(dtime); allparticlespawners_step(dtime, client.getEnv()); /* @@ -3249,7 +3262,8 @@ void the_game( */ update_draw_list_timer += dtime; if(update_draw_list_timer >= 0.2 || - update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2){ + update_draw_list_last_cam_dir.getDistanceFrom(camera_direction) > 0.2 || + camera_offset_changed){ update_draw_list_timer = 0; client.getEnv().getClientMap().updateDrawList(driver); update_draw_list_last_cam_dir = camera_direction; -- cgit v1.2.3