summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2019-04-13 12:13:13 -0400
committerGitHub <noreply@github.com>2019-04-13 12:13:13 -0400
commita891115ea350528f1735dab54d05edc8b8fe77c6 (patch)
tree08257dd14877d4693d502dcf50e81a734e0cb043 /Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp
parent241166a1a5becb0a6a2af209e7f5ea2962d6a2dd (diff)
parentc89ddf8cba9c6b19d59e2db1896292797163c54c (diff)
Merge pull request #7952 from jordan-woyak/emu-shake-params
WiimoteEmu: Allow shake frequency and intensity to be configured.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp')
-rw-r--r--Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp68
1 files changed, 66 insertions, 2 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp
index 715ae89b5a..93a9d06cb3 100644
--- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp
+++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/Force.cpp
@@ -71,8 +71,7 @@ Force::StateData Force::GetState(bool adjusted)
if (adjusted)
{
// Apply deadzone to z.
- const ControlState deadzone = GetDeadzonePercentage();
- z = std::copysign(std::max(0.0, std::abs(z) - deadzone) / (1.0 - deadzone), z);
+ z = ApplyDeadzone(z, GetDeadzonePercentage());
}
return {float(state.x), float(state.y), float(z)};
@@ -105,4 +104,69 @@ ControlState Force::GetDefaultInputRadiusAtAngle(double) const
return 1.0;
}
+Shake::Shake(const std::string& name_, ControlState default_intensity_scale)
+ : ControlGroup(name_, name_, GroupType::Shake)
+{
+ // i18n: Refers to a 3D axis (used when mapping motion controls)
+ controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("X")));
+ // i18n: Refers to a 3D axis (used when mapping motion controls)
+ controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("Y")));
+ // i18n: Refers to a 3D axis (used when mapping motion controls)
+ controls.emplace_back(new ControllerEmu::Input(ControllerEmu::Translate, _trans("Z")));
+
+ AddDeadzoneSetting(&m_deadzone_setting, 50);
+
+ // Total travel distance in centimeters.
+ // Negative values can be used to reverse the initial direction of movement.
+ AddSetting(&m_intensity_setting,
+ // i18n: Refers to the intensity of shaking an emulated wiimote.
+ {_trans("Intensity"),
+ // i18n: The symbol/abbreviation for centimeters.
+ _trans("cm"),
+ // i18n: Refering to emulated wii remote movement.
+ _trans("Total travel distance.")},
+ 10 * default_intensity_scale, -50, 50);
+
+ // Approximate number of up/down movements in one second.
+ AddSetting(&m_frequency_setting,
+ // i18n: Refers to a number of actions per second in Hz.
+ {_trans("Frequency"),
+ // i18n: The symbol/abbreviation for hertz (cycles per second).
+ _trans("Hz"),
+ // i18n: Refering to emulated wii remote movement.
+ _trans("Number of shakes per second.")},
+ 6, 1, 20);
+}
+
+Shake::StateData Shake::GetState(bool adjusted) const
+{
+ const float x = controls[0]->control_ref->State();
+ const float y = controls[1]->control_ref->State();
+ const float z = controls[2]->control_ref->State();
+
+ StateData result = {x, y, z};
+
+ // FYI: Unadjusted values are used in UI.
+ if (adjusted)
+ for (auto& c : result.data)
+ c = ApplyDeadzone(c, GetDeadzone());
+
+ return result;
+}
+
+ControlState Shake::GetDeadzone() const
+{
+ return m_deadzone_setting.GetValue() / 100;
+}
+
+ControlState Shake::GetIntensity() const
+{
+ return m_intensity_setting.GetValue() / 100;
+}
+
+ControlState Shake::GetFrequency() const
+{
+ return m_frequency_setting.GetValue();
+}
+
} // namespace ControllerEmu