diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2018-05-12 14:30:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-12 14:30:52 +0200 |
commit | d5d248ccbd90701db6ee633ad1057d8dd290b2ba (patch) | |
tree | 59bf13be9e25983c86c549607d29ba44fcf67708 /src | |
parent | 9dd432c29f662fc668cc2473a2e057acd8357a91 (diff) | |
download | minetest-d5d248ccbd90701db6ee633ad1057d8dd290b2ba.tar.gz minetest-d5d248ccbd90701db6ee633ad1057d8dd290b2ba.tar.bz2 minetest-d5d248ccbd90701db6ee633ad1057d8dd290b2ba.zip |
Camera: Improve subpixel movement (#7319)
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/game.cpp b/src/game.cpp index f5a542050..e74d42cd0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2333,13 +2333,15 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime) } #endif - if (m_first_loop_after_window_activation) + if (m_first_loop_after_window_activation) { m_first_loop_after_window_activation = false; - else + + input->setMousePos(driver->getScreenSize().Width / 2, + driver->getScreenSize().Height / 2); + } else { updateCameraOrientation(cam, dtime); + } - input->setMousePos((driver->getScreenSize().Width / 2), - (driver->getScreenSize().Height / 2)); } else { #ifndef ANDROID @@ -2361,17 +2363,18 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) cam->camera_pitch = g_touchscreengui->getPitch(); } else { #endif - - s32 dx = input->getMousePos().X - (driver->getScreenSize().Width / 2); - s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height / 2); + v2s32 center(driver->getScreenSize().Width / 2, driver->getScreenSize().Height / 2); + v2s32 dist = input->getMousePos() - center; if (m_invert_mouse || camera->getCameraMode() == CAMERA_MODE_THIRD_FRONT) { - dy = -dy; + dist.Y = -dist.Y; } - cam->camera_yaw -= dx * m_cache_mouse_sensitivity; - cam->camera_pitch += dy * m_cache_mouse_sensitivity; + cam->camera_yaw -= dist.X * m_cache_mouse_sensitivity; + cam->camera_pitch += dist.Y * m_cache_mouse_sensitivity; + if (dist.X != 0 || dist.Y != 0) + input->setMousePos(center.X, center.Y); #ifdef HAVE_TOUCHSCREENGUI } #endif |