mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-10-01 12:30:00 +02:00
Clamp controller sticks to circle, instead of square (#2493)
* clamp controller sticks to circle, instead of square * fix deadzone * addressed comments
This commit is contained in:
parent
ff5df5d8a1
commit
5ceaf344ce
1 changed files with 42 additions and 24 deletions
|
@ -343,28 +343,6 @@ namespace Ryujinx.Input.HLE
|
|||
}
|
||||
}
|
||||
|
||||
private static short ClampAxis(float value)
|
||||
{
|
||||
if (value <= -short.MaxValue)
|
||||
{
|
||||
return -short.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (short)(value * short.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static JoystickPosition ApplyDeadzone(float x, float y, float deadzone)
|
||||
{
|
||||
return new JoystickPosition
|
||||
{
|
||||
Dx = ClampAxis(MathF.Abs(x) > deadzone ? x : 0.0f),
|
||||
Dy = ClampAxis(MathF.Abs(y) > deadzone ? y : 0.0f)
|
||||
};
|
||||
}
|
||||
|
||||
public GamepadInput GetHLEInputState()
|
||||
{
|
||||
GamepadInput state = new GamepadInput();
|
||||
|
@ -400,13 +378,53 @@ namespace Ryujinx.Input.HLE
|
|||
(float leftAxisX, float leftAxisY) = State.GetStick(StickInputId.Left);
|
||||
(float rightAxisX, float rightAxisY) = State.GetStick(StickInputId.Right);
|
||||
|
||||
state.LStick = ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft);
|
||||
state.RStick = ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight);
|
||||
state.LStick = ClampToCircle(ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft));
|
||||
state.RStick = ClampToCircle(ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight));
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static JoystickPosition ApplyDeadzone(float x, float y, float deadzone)
|
||||
{
|
||||
return new JoystickPosition
|
||||
{
|
||||
Dx = ClampAxis(MathF.Abs(x) > deadzone ? x : 0.0f),
|
||||
Dy = ClampAxis(MathF.Abs(y) > deadzone ? y : 0.0f)
|
||||
};
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static short ClampAxis(float value)
|
||||
{
|
||||
if (value <= -short.MaxValue)
|
||||
{
|
||||
return -short.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (short)(value * short.MaxValue);
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static JoystickPosition ClampToCircle(JoystickPosition position)
|
||||
{
|
||||
Vector2 point = new Vector2(position.Dx, position.Dy);
|
||||
|
||||
if (point.Length() > short.MaxValue)
|
||||
{
|
||||
point = point / point.Length() * short.MaxValue;
|
||||
}
|
||||
|
||||
return new JoystickPosition
|
||||
{
|
||||
Dx = (int)point.X,
|
||||
Dy = (int)point.Y
|
||||
};
|
||||
}
|
||||
|
||||
public SixAxisInput GetHLEMotionState(bool isJoyconRightPair = false)
|
||||
{
|
||||
float[] orientationForHLE = new float[9];
|
||||
|
|
Loading…
Reference in a new issue