From bbed9abf55846fc079b164b409d8a3444947e4ab Mon Sep 17 00:00:00 2001 From: cathery Date: Fri, 24 Jan 2020 01:39:36 +0300 Subject: [PATCH] Clamp joystick values when dpad and lstick are swapped They will now fit inside the circle like regular sticks --- source/ControllerSwitch/SwitchHDLHandler.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/ControllerSwitch/SwitchHDLHandler.cpp b/source/ControllerSwitch/SwitchHDLHandler.cpp index 7e97c39..8a8351b 100644 --- a/source/ControllerSwitch/SwitchHDLHandler.cpp +++ b/source/ControllerSwitch/SwitchHDLHandler.cpp @@ -136,6 +136,15 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data) daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN daxis_x += data.buttons[15] ? -1.0f : 0.0f; //DLEFT + float real_magnitude = std::sqrt(daxis_x * daxis_x + daxis_y * daxis_y); + + float clipped_magnitude = std::min(1.0f, real_magnitude); + + float ratio = clipped_magnitude / real_magnitude; + + daxis_x *= ratio; + daxis_y *= ratio; + m_controllerHandler.ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy); } else