mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-24 19:15:12 +00:00
Adjusting how deadzones are calculated (#3079)
* 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
This commit is contained in:
parent
8f35345729
commit
8cc2479825
2 changed files with 17 additions and 9 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -74,6 +74,9 @@ _TeamCity*
|
||||||
# DotCover is a Code Coverage Tool
|
# DotCover is a Code Coverage Tool
|
||||||
*.dotCover
|
*.dotCover
|
||||||
|
|
||||||
|
# Rider is a Visual Studio alternative
|
||||||
|
.idea/*
|
||||||
|
|
||||||
# NCrunch
|
# NCrunch
|
||||||
*.ncrunch*
|
*.ncrunch*
|
||||||
.*crunch*.local.xml
|
.*crunch*.local.xml
|
||||||
|
|
|
@ -391,24 +391,29 @@ namespace Ryujinx.Input.HLE
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static JoystickPosition ApplyDeadzone(float x, float y, float deadzone)
|
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)
|
||||||
{
|
{
|
||||||
Dx = ClampAxis(MathF.Abs(x) > deadzone ? x : 0.0f),
|
return new JoystickPosition() {Dx = 0, Dy = 0};
|
||||||
Dy = ClampAxis(MathF.Abs(y) > deadzone ? y : 0.0f)
|
}
|
||||||
|
|
||||||
|
return new JoystickPosition()
|
||||||
|
{
|
||||||
|
Dx = ClampAxis((x / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone))),
|
||||||
|
Dy = ClampAxis((y / magnitudeClamped) * ((magnitudeClamped - deadzone) / (1 - deadzone)))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static short ClampAxis(float value)
|
private static short ClampAxis(float value)
|
||||||
{
|
{
|
||||||
if (value <= -short.MaxValue)
|
if (Math.Sign(value) < 0)
|
||||||
{
|
{
|
||||||
return -short.MaxValue;
|
return (short)Math.Max(value * -short.MinValue, short.MinValue);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (short)(value * short.MaxValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (short)Math.Min(value * short.MaxValue, short.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
|
Loading…
Reference in a new issue