summaryrefslogtreecommitdiff
path: root/src/camera.cpp
diff options
context:
space:
mode:
authorNovatux <nathanael.courant@laposte.net>2014-01-26 11:40:21 +0100
committerNovatux <nathanael.courant@laposte.net>2014-03-04 20:12:10 +0100
commit062de11b4cff30861dd4e9eb56f131d821f34b51 (patch)
tree37bdcbacb355abfe1f8091307222e430e58b78d8 /src/camera.cpp
parent8e15179e7d896851c6f5814fc6524c86b26ce2e3 (diff)
downloadminetest-062de11b4cff30861dd4e9eb56f131d821f34b51.tar.gz
minetest-062de11b4cff30861dd4e9eb56f131d821f34b51.tar.bz2
minetest-062de11b4cff30861dd4e9eb56f131d821f34b51.zip
Fix rendering glitches when far from the center of the map
Diffstat (limited to 'src/camera.cpp')
-rw-r--r--src/camera.cpp16
1 files changed, 14 insertions, 2 deletions
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");