Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOV mouse sensitivity setting #12483

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -112,6 +112,10 @@ invert_mouse (Invert mouse) bool false
# Mouse sensitivity multiplier.
mouse_sensitivity (Mouse sensitivity) float 0.2 0.001 10.0

# ADS mouse sensitivity multiplier.
ads_sensitivity (ADS sensitivity) float 1.0 0.0 100.0


[*Touchscreen]

# The length in pixels it takes for touch screen interaction to start.
Expand Down
4 changes: 4 additions & 0 deletions minetest.conf.example
Expand Up @@ -61,6 +61,10 @@
# type: float
# mouse_sensitivity = 0.2

# ADS mouse sensitivity multiplier.
# type: float
# ADS_sensitivity = 1.0

# If enabled, "Aux1" key instead of "Sneak" key is used for climbing down and
# descending.
# type: bool
Expand Down
26 changes: 17 additions & 9 deletions src/client/game.cpp
Expand Up @@ -895,6 +895,7 @@ class Game {
bool m_cache_enable_noclip;
bool m_cache_enable_free_move;
f32 m_cache_mouse_sensitivity;
f32 m_cache_ads_sensitivity;
f32 m_cache_joystick_frustum_sensitivity;
f32 m_repeat_place_time;
f32 m_cache_cam_smoothing;
Expand Down Expand Up @@ -934,6 +935,8 @@ Game::Game() :
&settingChangedCallback, this);
g_settings->registerChangedCallback("mouse_sensitivity",
&settingChangedCallback, this);
g_settings->registerChangedCallback("ads_sensitivity",
&settingChangedCallback, this);
g_settings->registerChangedCallback("joystick_frustum_sensitivity",
&settingChangedCallback, this);
g_settings->registerChangedCallback("repeat_place_time",
Expand Down Expand Up @@ -994,6 +997,8 @@ Game::~Game()
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("mouse_sensitivity",
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("ads_sensitivity",
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("repeat_place_time",
&settingChangedCallback, this);
g_settings->deregisterChangedCallback("noclip",
Expand Down Expand Up @@ -2438,12 +2443,14 @@ void Game::updateCameraDirection(CameraOrientation *cam, float dtime)
// 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;
if (m_cache_ads_sensitivity == 0) {
return 1.0f;
} else {
// Multiply by a constant such that it becomes 1.0 at 72 degree FOV
// to minimize disruption of existing sensitivity settings.
f32 fov_y = client->getCamera()->getFovY();
return pow(tan(fov_y / 2.0f) * 1.3763818698f, m_cache_ads_sensitivity);
}
}

void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
Expand All @@ -2461,7 +2468,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
dist.Y = -dist.Y;
}

f32 sens_scale = getSensitivityScaleFactor();
const 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;

Expand Down Expand Up @@ -4135,8 +4142,9 @@ void Game::readSettings()
m_cache_enable_particles = g_settings->getBool("enable_particles");
m_cache_enable_fog = g_settings->getBool("enable_fog");
m_cache_mouse_sensitivity = g_settings->getFloat("mouse_sensitivity", 0.001f, 10.0f);
m_cache_ads_sensitivity = g_settings->getFloat("ads_sensitivity");
m_cache_joystick_frustum_sensitivity = std::max(g_settings->getFloat("joystick_frustum_sensitivity"), 0.001f);
m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.25f, 2.0);
m_repeat_place_time = g_settings->getFloat("repeat_place_time", 0.25f, 2.0f);

m_cache_enable_noclip = g_settings->getBool("noclip");
m_cache_enable_free_move = g_settings->getBool("free_move");
Expand All @@ -4151,7 +4159,7 @@ void Game::readSettings()

m_cache_fog_start = rangelim(m_cache_fog_start, 0.0f, 0.99f);
m_cache_cam_smoothing = rangelim(m_cache_cam_smoothing, 0.01f, 1.0f);
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001, 100.0);
m_cache_mouse_sensitivity = rangelim(m_cache_mouse_sensitivity, 0.001f, 100.0f);

m_does_lost_focus_pause_game = g_settings->getBool("pause_on_lost_focus");
}
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -280,6 +280,7 @@ void set_default_settings()
// Input
settings->setDefault("invert_mouse", "false");
settings->setDefault("mouse_sensitivity", "0.2");
settings->setDefault("ads_sensitivity", "1.0");
settings->setDefault("repeat_place_time", "0.25");
settings->setDefault("safe_dig_and_place", "false");
settings->setDefault("random_input", "false");
Expand Down