|
|
@@ -391,24 +391,29 @@ namespace Ryujinx.Input.HLE
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
private static JoystickPosition ApplyDeadzone(float x, float y, float deadzone)
|
|
|
{
|
|
|
- return new JoystickPosition
|
|
|
+ float magnitudeClamped = Math.Min(MathF.Sqrt(x * x + y * y), 1f);
|
|
|
+
|
|
|
+ if (magnitudeClamped <= deadzone)
|
|
|
+ {
|
|
|
+ return new JoystickPosition() {Dx = 0, Dy = 0};
|
|
|
+ }
|
|
|
+
|
|
|
+ return new JoystickPosition()
|
|
|
{
|
|
|
- Dx = ClampAxis(MathF.Abs(x) > deadzone ? x : 0.0f),
|
|
|
- Dy = ClampAxis(MathF.Abs(y) > deadzone ? y : 0.0f)
|
|
|
+ Dx = ClampAxis((x / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone))),
|
|
|
+ Dy = ClampAxis((y / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone)))
|
|
|
};
|
|
|
}
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
private static short ClampAxis(float value)
|
|
|
{
|
|
|
- if (value <= -short.MaxValue)
|
|
|
+ if (Math.Sign(value) < 0)
|
|
|
{
|
|
|
- return -short.MaxValue;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return (short)(value * short.MaxValue);
|
|
|
+ return (short)Math.Max(value * -short.MinValue, short.MinValue);
|
|
|
}
|
|
|
+
|
|
|
+ return (short)Math.Min(value * short.MaxValue, short.MaxValue);
|
|
|
}
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|