mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 22:52:25 +01:00
Scale mouse/joystick sensitivity depending on FOV (#11007)
This commit is contained in:
parent
96d4df995c
commit
59a1b53d67
@ -829,6 +829,8 @@ private:
|
||||
const NodeMetadata *meta);
|
||||
static const ClientEventHandler clientEventHandler[CLIENTEVENT_MAX];
|
||||
|
||||
f32 getSensitivityScaleFactor() const;
|
||||
|
||||
InputHandler *input = nullptr;
|
||||
|
||||
Client *client = nullptr;
|
||||
@ -2341,7 +2343,6 @@ void Game::checkZoomEnabled()
|
||||
m_game_ui->showTranslatedStatusText("Zoom currently disabled by game or mod");
|
||||
}
|
||||
|
||||
|
||||
void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
|
||||
{
|
||||
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)
|
||||
{
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
@ -2392,8 +2405,9 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
|
||||
dist.Y = -dist.Y;
|
||||
}
|
||||
|
||||
cam->camera_yaw -= dist.X * m_cache_mouse_sensitivity;
|
||||
cam->camera_pitch += dist.Y * m_cache_mouse_sensitivity;
|
||||
f32 sens_scale = getSensitivityScaleFactor();
|
||||
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)
|
||||
input->setMousePos(center.X, center.Y);
|
||||
@ -2402,7 +2416,8 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
|
||||
#endif
|
||||
|
||||
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_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user