aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Input/HLE/NpadController.cs
diff options
context:
space:
mode:
authorskrek <liam@tannock.net>2022-02-16 02:06:52 -0800
committerGitHub <noreply@github.com>2022-02-16 11:06:52 +0100
commit8cc2479825a818f126c53939dacba8007a36125b (patch)
tree4209c8576ad2db27546acbfbb19361c4f4c52f7d /Ryujinx.Input/HLE/NpadController.cs
parent8f353457295767edaaf9dfccb4d938bc1befeb40 (diff)
Adjusting how deadzones are calculated (#3079)1.1.28
* Making deadzones feel nice and smooth + adding rider files to .gitignore * removing unnecessary parentheses and fixing possibility of divide by 0 * formatting :) * fixing up ClampAxis * fixing up ClampAxis
Diffstat (limited to 'Ryujinx.Input/HLE/NpadController.cs')
-rw-r--r--Ryujinx.Input/HLE/NpadController.cs23
1 files changed, 14 insertions, 9 deletions
diff --git a/Ryujinx.Input/HLE/NpadController.cs b/Ryujinx.Input/HLE/NpadController.cs
index 2af114d2..eb9989b0 100644
--- a/Ryujinx.Input/HLE/NpadController.cs
+++ b/Ryujinx.Input/HLE/NpadController.cs
@@ -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)]