Scale mouse/joystick sensitivity depending on FOV (#11007)

This commit is contained in:
Elias Åström 2021-03-19 21:43:01 +01:00 committed by GitHub
parent 96d4df995c
commit 59a1b53d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -829,6 +829,8 @@ private:
const NodeMetadata *meta); const NodeMetadata *meta);
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX]; static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
f32 getSensitivityScaleFactor() const;
InputHandler *input = nullptr; InputHandler *input = nullptr;
Client *client = nullptr; Client *client = nullptr;
@ -2341,7 +2343,6 @@ void Game::checkZoomEnabled()
m_game_ui->showTranslatedStatusText("Zoom currently disabled by game or mod"); m_game_ui->showTranslatedStatusText("Zoom currently disabled by game or mod");
} }
void Game::updateCameraDirection(CameraOrientation *cam, float dtime) void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
{ {
if ((device->isWindowActive() && device->isWindowFocused() if ((device->isWindowActive() && device->isWindowFocused()
@ -2377,6 +2378,18 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
} }
} }
// Get the factor to multiply with sensitivity to get the same mouse/joystick
// responsiveness independently of FOV.
f32 Game::getSensitivityScaleFactor() const
{
f32 fov_y = client->getCamera()->getFovY();
// Multiply by a constant such that it becomes 1.0 at 72 degree FOV and
// 16:9 aspect ratio to minimize disruption of existing sensitivity
// settings.
return tan(fov_y / 2.0f) * 1.3763818698f;
}
void Game::updateCameraOrientation(CameraOrientation *cam, float dtime) void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
{ {
#ifdef HAVE_TOUCHSCREENGUI #ifdef HAVE_TOUCHSCREENGUI
@ -2392,8 +2405,9 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
dist.Y = -dist.Y; dist.Y = -dist.Y;
} }
cam->camera_yaw -= dist.X * m_cache_mouse_sensitivity; f32 sens_scale = getSensitivityScaleFactor();
cam->camera_pitch += dist.Y * m_cache_mouse_sensitivity; cam->camera_yaw -= dist.X * m_cache_mouse_sensitivity * sens_scale;
cam->camera_pitch += dist.Y * m_cache_mouse_sensitivity * sens_scale;
if (dist.X != 0 || dist.Y != 0) if (dist.X != 0 || dist.Y != 0)
input->setMousePos(center.X, center.Y); input->setMousePos(center.X, center.Y);
@ -2402,7 +2416,8 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
#endif #endif
if (m_cache_enable_joysticks) { if (m_cache_enable_joysticks) {
f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime; f32 sens_scale = getSensitivityScaleFactor();
f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime * sens_scale;
cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c; cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c;
cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c; cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c;
} }