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/camera.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/camera.cpp') diff --git a/src/camera.cpp b/src/camera.cpp index 937ba38af..783ae84c4 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -36,6 +36,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "profiler.h" #include "util/numeric.h" #include "util/mathconstants.h" +#include "constants.h" + +#define CAMERA_OFFSET_STEP 200 Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, IGameDef *gamedef): @@ -53,6 +56,7 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, m_camera_position(0,0,0), m_camera_direction(0,0,0), + m_camera_offset(0,0,0), m_aspect(1.0), m_fov_x(1.0), @@ -348,11 +352,19 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, v3f abs_cam_up; m_headnode->getAbsoluteTransformation().rotateVect(abs_cam_up, rel_cam_up); + // Update offset if too far away from the center of the map + m_camera_offset.X += CAMERA_OFFSET_STEP* + (((s16)(m_camera_position.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP); + m_camera_offset.Y += CAMERA_OFFSET_STEP* + (((s16)(m_camera_position.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP); + m_camera_offset.Z += CAMERA_OFFSET_STEP* + (((s16)(m_camera_position.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP); + // Set camera node transformation - m_cameranode->setPosition(m_camera_position); + m_cameranode->setPosition(m_camera_position-intToFloat(m_camera_offset, BS)); m_cameranode->setUpVector(abs_cam_up); // *100.0 helps in large map coordinates - m_cameranode->setTarget(m_camera_position + 100 * m_camera_direction); + m_cameranode->setTarget(m_camera_position-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction); // Get FOV setting f32 fov_degrees = g_settings->getFloat("fov"); -- cgit v1.2.3