| 1 | // Copyright 2017 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "InputCommon/ControllerEmu/ControlGroup/Tilt.h" |
| 5 | |
| 6 | #include <string> |
| 7 | |
| 8 | #include "Common/Common.h" |
| 9 | #include "Common/MathUtil.h" |
| 10 | |
| 11 | #include "InputCommon/ControllerEmu/Control/Control.h" |
| 12 | #include "InputCommon/ControllerEmu/Setting/NumericSetting.h" |
| 13 | |
| 14 | namespace ControllerEmu |
| 15 | { |
| 16 | Tilt::Tilt(const std::string& name_) : ReshapableInput(name_, name_, GroupType::Tilt) |
| 17 | { |
| 18 | AddInput(Translatability::Translate, _trans("Forward")); |
| 19 | AddInput(Translatability::Translate, _trans("Backward")); |
| 20 | AddInput(Translatability::Translate, _trans("Left")); |
| 21 | AddInput(Translatability::Translate, _trans("Right")); |
| 22 | |
| 23 | AddInput(Translatability::Translate, _trans("Modifier")); |
| 24 | |
| 25 | AddSetting(&m_max_angle_setting, |
| 26 | {_trans("Angle"), |
| 27 | // i18n: The symbol/abbreviation for degrees (unit of angular measure). |
| 28 | _trans("°"), |
| 29 | // i18n: Refers to tilting an emulated Wii Remote. |
| 30 | _trans("Maximum tilt angle.")}, |
| 31 | 85, 0, 180); |
| 32 | |
| 33 | AddSetting(&m_max_rotational_velocity, |
| 34 | {_trans("Velocity"), |
| 35 | // i18n: The symbol/abbreviation for hertz (cycles per second). |
| 36 | _trans("Hz"), |
| 37 | // i18n: Refers to tilting an emulated Wii Remote. |
| 38 | _trans("Peak angular velocity (measured in turns per second).")}, |
| 39 | 7, 1, 50); |
| 40 | } |
| 41 | |
| 42 | Tilt::ReshapeData Tilt::GetReshapableState(bool adjusted) const |
| 43 | { |
| 44 | const ControlState y = controls[0]->GetState() - controls[1]->GetState(); |
| 45 | const ControlState x = controls[3]->GetState() - controls[2]->GetState(); |
| 46 | |
| 47 | // Return raw values. (used in UI) |
| 48 | if (!adjusted) |
| 49 | return {x, y}; |
| 50 | |
| 51 | return Reshape(x, y, GetModifierInput()->GetState()); |
| 52 | } |
| 53 | |
| 54 | Tilt::StateData Tilt::GetState() const |
| 55 | { |
| 56 | return GetReshapableState(true); |
| 57 | } |
| 58 | |
| 59 | ControlState Tilt::GetGateRadiusAtAngle(double ang) const |
| 60 | { |
| 61 | const ControlState max_tilt_angle = m_max_angle_setting.GetValue() / 180; |
| 62 | return SquareStickGate(max_tilt_angle).GetRadiusAtAngle(ang); |
| 63 | } |
| 64 | |
| 65 | ControlState Tilt::GetDefaultInputRadiusAtAngle(double ang) const |
| 66 | { |
| 67 | return SquareStickGate(1.0).GetRadiusAtAngle(ang); |
| 68 | } |
| 69 | |
| 70 | ControlState Tilt::GetMaxRotationalVelocity() const |
| 71 | { |
| 72 | return m_max_rotational_velocity.GetValue() * MathUtil::TAU; |
| 73 | } |
| 74 | |
| 75 | Control* Tilt::GetModifierInput() const |
| 76 | { |
| 77 | return controls[4].get(); |
| 78 | } |
| 79 | |
| 80 | } // namespace ControllerEmu |