From 2de9c0b907c92fd309d72f9770fe75aa5872c24a Mon Sep 17 00:00:00 2001 From: Fraser Waters Date: Fri, 9 Jan 2015 12:50:50 +0000 Subject: [PATCH] Fix wrap around bug in XInput. Fixes #209. Negating short.MinValue would cause a wrap around back to short.MinValue. This resulted in joystick inputs like 0.8, 0.9, -1.00031. --- Source/OpenTK/Platform/Windows/XInputJoystick.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/XInputJoystick.cs b/Source/OpenTK/Platform/Windows/XInputJoystick.cs index 2e21adfe..0ffed2a7 100644 --- a/Source/OpenTK/Platform/Windows/XInputJoystick.cs +++ b/Source/OpenTK/Platform/Windows/XInputJoystick.cs @@ -59,10 +59,10 @@ namespace OpenTK.Platform.Windows state.SetIsConnected(true); state.SetAxis(JoystickAxis.Axis0, (short)xstate.GamePad.ThumbLX); - state.SetAxis(JoystickAxis.Axis1, (short)(-xstate.GamePad.ThumbLY)); + state.SetAxis(JoystickAxis.Axis1, (short)Math.Min(short.MaxValue, -xstate.GamePad.ThumbLY)); state.SetAxis(JoystickAxis.Axis2, (short)Common.HidHelper.ScaleValue(xstate.GamePad.LeftTrigger, 0, byte.MaxValue, short.MinValue, short.MaxValue)); state.SetAxis(JoystickAxis.Axis3, (short)xstate.GamePad.ThumbRX); - state.SetAxis(JoystickAxis.Axis4, (short)(-xstate.GamePad.ThumbRY)); + state.SetAxis(JoystickAxis.Axis4, (short)Math.Min(short.MaxValue, -xstate.GamePad.ThumbRY)); state.SetAxis(JoystickAxis.Axis5, (short)Common.HidHelper.ScaleValue(xstate.GamePad.RightTrigger, 0, byte.MaxValue, short.MinValue, short.MaxValue)); state.SetButton(JoystickButton.Button0, (xstate.GamePad.Buttons & XInputButtons.A) != 0);