0
0
Fork 0

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:
emmauss 2021-08-04 21:08:33 +00:00 committed by GitHub
parent ff5df5d8a1
commit 5ceaf344ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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() public GamepadInput GetHLEInputState()
{ {
GamepadInput state = new GamepadInput(); GamepadInput state = new GamepadInput();
@ -400,13 +378,53 @@ namespace Ryujinx.Input.HLE
(float leftAxisX, float leftAxisY) = State.GetStick(StickInputId.Left); (float leftAxisX, float leftAxisY) = State.GetStick(StickInputId.Left);
(float rightAxisX, float rightAxisY) = State.GetStick(StickInputId.Right); (float rightAxisX, float rightAxisY) = State.GetStick(StickInputId.Right);
state.LStick = ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft); state.LStick = ClampToCircle(ApplyDeadzone(leftAxisX, leftAxisY, controllerConfig.DeadzoneLeft));
state.RStick = ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight); state.RStick = ClampToCircle(ApplyDeadzone(rightAxisX, rightAxisY, controllerConfig.DeadzoneRight));
} }
return state; 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) public SixAxisInput GetHLEMotionState(bool isJoyconRightPair = false)
{ {
float[] orientationForHLE = new float[9]; float[] orientationForHLE = new float[9];