Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Camera: Improve subpixel movement (#7319)
  • Loading branch information
SmallJoker committed May 12, 2018
1 parent 9dd432c commit d5d248c
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/game.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit d5d248c

Please sign in to comment.