From c3dc3c106ccb32911a4a6448f7b21c8beaae0c35 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 29 Dec 2018 16:06:03 -0600 Subject: ControllerEmu: Reorganize stick reshaping code and use it for emu wiimote tilt as well. Also make the tilt mapping indicator pretty. --- .../ControllerEmu/ControlGroup/AnalogStick.cpp | 81 ++-------------------- 1 file changed, 7 insertions(+), 74 deletions(-) (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp') diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index 9db29909fd..e072f6b7bd 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -24,22 +24,17 @@ AnalogStick::AnalogStick(const char* const name_, std::unique_ptr&& s AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, std::unique_ptr&& stick_gate) - : ControlGroup(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate)) + : ReshapableInput(name_, ui_name_, GroupType::Stick), m_stick_gate(std::move(stick_gate)) { for (auto& named_direction : named_directions) controls.emplace_back(std::make_unique(Translate, named_direction)); controls.emplace_back(std::make_unique(Translate, _trans("Modifier"))); - // Set default input radius to that of the gate radius (no resizing) - // Allow radius greater than 1.0 for definitions of rounded squares - // This is ideal for Xbox controllers (and probably others) - numeric_settings.emplace_back( - std::make_unique(_trans("Input Radius"), GetGateRadiusAtAngle(0.0), 0, 140)); - // Set default input shape to an octagon (no reshaping) - numeric_settings.emplace_back( - std::make_unique(_trans("Input Shape"), 0.0, 0, 50)); - numeric_settings.emplace_back(std::make_unique(_trans("Dead Zone"), 0, 0, 50)); + // Default input radius to that of the gate radius (no resizing) + // Default input shape to an octagon (no reshaping) + // Max deadzone to 50% + AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50); } AnalogStick::StateData AnalogStick::GetState(bool adjusted) @@ -51,40 +46,9 @@ AnalogStick::StateData AnalogStick::GetState(bool adjusted) if (!adjusted) return {x, y}; - // TODO: make the AtAngle functions work with negative angles: - const ControlState ang = std::atan2(y, x) + MathUtil::TAU; - - const ControlState gate_max_dist = GetGateRadiusAtAngle(ang); - const ControlState input_max_dist = GetInputRadiusAtAngle(ang); - - // If input radius is zero we apply no scaling. - // This is useful when mapping native controllers without knowing intimate radius details. - const ControlState max_dist = input_max_dist ? input_max_dist : gate_max_dist; - - ControlState dist = std::sqrt(x * x + y * y) / max_dist; - - // If the modifier is pressed, scale the distance by the modifier's value. - // This is affected by the modifier's "range" setting which defaults to 50%. const ControlState modifier = controls[4]->control_ref->State(); - if (modifier) - { - // TODO: Modifier's range setting gets reset to 100% when the clear button is clicked. - // This causes the modifier to not behave how a user might suspect. - // Retaining the old scale-by-50% behavior until range is fixed to clear to 50%. - dist *= 0.5; - // dist *= modifier; - } - - // Apply deadzone as a percentage of the user-defined radius/shape: - const ControlState deadzone = GetDeadzoneRadiusAtAngle(ang); - dist = std::max(0.0, dist - deadzone) / (1.0 - deadzone); - - // Scale to the gate shape/radius: - dist = dist *= gate_max_dist; - - x = MathUtil::Clamp(std::cos(ang) * dist, -1.0, 1.0); - y = MathUtil::Clamp(std::sin(ang) * dist, -1.0, 1.0); - return {x, y}; + + return Reshape(x, y, modifier); } ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const @@ -92,37 +56,6 @@ ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const return m_stick_gate->GetRadiusAtAngle(ang); } -ControlState AnalogStick::GetDeadzoneRadiusAtAngle(double ang) const -{ - return CalculateInputShapeRadiusAtAngle(ang) * numeric_settings[SETTING_DEADZONE]->GetValue(); -} - -ControlState AnalogStick::GetInputRadiusAtAngle(double ang) const -{ - const ControlState radius = - CalculateInputShapeRadiusAtAngle(ang) * numeric_settings[SETTING_INPUT_RADIUS]->GetValue(); - // Clamp within the -1 to +1 square as input radius may be greater than 1.0: - return std::min(radius, SquareStickGate(1).GetRadiusAtAngle(ang)); -} - -ControlState AnalogStick::CalculateInputShapeRadiusAtAngle(double ang) const -{ - const auto shape = numeric_settings[SETTING_INPUT_SHAPE]->GetValue() * 4.0; - - if (shape < 1.0) - { - // Between 0 and 25 return a shape between octagon and circle - const auto amt = shape; - return OctagonStickGate(1).GetRadiusAtAngle(ang) * (1 - amt) + amt; - } - else - { - // Between 25 and 50 return a shape between circle and square - const auto amt = shape - 1.0; - return (1 - amt) + SquareStickGate(1).GetRadiusAtAngle(ang) * amt; - } -} - OctagonAnalogStick::OctagonAnalogStick(const char* name, ControlState gate_radius) : OctagonAnalogStick(name, name, gate_radius) { -- cgit v1.2.3 From 7a00f55cfa6e65e58ebf9f279bfff61f8b0f8c13 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 30 Dec 2018 09:10:32 -0600 Subject: ControllerEmu::Cursor: Add input radius/shape settings to IR Cursor mappings to allow use of round inputs in absolute mode. Make relative input option obey the center/width/height settings. Make the mapping indicator pretty and actually show what the relative/center/w/h settings are doing. --- .../InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp') diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index e072f6b7bd..de9a75dd23 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -37,10 +37,10 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50); } -AnalogStick::StateData AnalogStick::GetState(bool adjusted) +AnalogStick::StateData AnalogStick::GetReshapableState(bool adjusted) { - ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); - ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); + const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); + const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); // Return raw values. (used in UI) if (!adjusted) @@ -51,6 +51,11 @@ AnalogStick::StateData AnalogStick::GetState(bool adjusted) return Reshape(x, y, modifier); } +AnalogStick::StateData AnalogStick::GetState() +{ + return GetReshapableState(true); +} + ControlState AnalogStick::GetGateRadiusAtAngle(double ang) const { return m_stick_gate->GetRadiusAtAngle(ang); -- cgit v1.2.3 From 7efa96eda979f5e717813e7c76cefb0720bc239a Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sun, 30 Dec 2018 10:52:45 -0600 Subject: ControllerEmu: code cleanup. --- Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp') diff --git a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp index de9a75dd23..0cd5da6ba0 100644 --- a/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp +++ b/Source/Core/InputCommon/ControllerEmu/ControlGroup/AnalogStick.cpp @@ -37,7 +37,7 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_, AddReshapingSettings(GetGateRadiusAtAngle(0.0), 0.0, 50); } -AnalogStick::StateData AnalogStick::GetReshapableState(bool adjusted) +AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted) { const ControlState y = controls[0]->control_ref->State() - controls[1]->control_ref->State(); const ControlState x = controls[3]->control_ref->State() - controls[2]->control_ref->State(); -- cgit v1.2.3