mirror of
https://github.com/cathery/sys-con.git
synced 2024-10-04 13:29:43 +00:00
Clamp joystick values when dpad and lstick are swapped
They will now fit inside the circle like regular sticks
This commit is contained in:
parent
c7c5c42ae8
commit
bbed9abf55
@ -136,6 +136,15 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)
|
|||||||
daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN
|
daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN
|
||||||
daxis_x += data.buttons[15] ? -1.0f : 0.0f; //DLEFT
|
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);
|
m_controllerHandler.ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user