diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2020-02-03 19:45:36 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-02-17 15:57:43 -0600 |
| commit | 82a3aa5ff67b0239b85d18a6da77d3fd2900640c (patch) | |
| tree | 9d808c8590dad2fd32854c798482c9d9cc0ae16b /Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp | |
| parent | 2d6a72e941da4b24d1795760e7f5a4394cc69263 (diff) | |
InputCommon: Add "Dead Zone" setting to raw gyro inputs.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp index 84f9f20821..6109f20b8c 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/IMUGyroscope.cpp @@ -7,6 +7,7 @@ #include <memory> #include "Common/Common.h" +#include "Common/MathUtil.h" #include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControllerEmu/Control/Control.h" @@ -23,6 +24,21 @@ IMUGyroscope::IMUGyroscope(std::string name, std::string ui_name) AddInput(Translate, _trans("Roll Right")); AddInput(Translate, _trans("Yaw Left")); AddInput(Translate, _trans("Yaw Right")); + + AddSetting(&m_deadzone_setting, + {_trans("Dead Zone"), + // i18n: "°/s" is the symbol for degrees (angular measurement) divided by seconds. + _trans("°/s"), + // i18n: Refers to the dead-zone setting of gyroscope input. + _trans("Angular velocity to ignore.")}, + 1, 0, 180); +} + +auto IMUGyroscope::GetRawState() const -> StateData +{ + return StateData(controls[1]->GetState() - controls[0]->GetState(), + controls[2]->GetState() - controls[3]->GetState(), + controls[4]->GetState() - controls[5]->GetState()); } std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState() const @@ -30,11 +46,18 @@ std::optional<IMUGyroscope::StateData> IMUGyroscope::GetState() const if (controls[0]->control_ref->BoundCount() == 0) return std::nullopt; - StateData state; - state.x = (controls[1]->GetState() - controls[0]->GetState()); - state.y = (controls[2]->GetState() - controls[3]->GetState()); - state.z = (controls[4]->GetState() - controls[5]->GetState()); + auto state = GetRawState(); + + // Apply "deadzone". + for (auto& c : state.data) + c *= std::abs(c) > GetDeadzone(); + return state; } +ControlState IMUGyroscope::GetDeadzone() const +{ + return m_deadzone_setting.GetValue() / 360 * MathUtil::TAU; +} + } // namespace ControllerEmu |
