From c3b289ee9ba0cffb28288b7eb7a4dd4746c57ddb Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Thu, 16 Jan 2014 01:20:32 +0100 Subject: [PATCH] [Win] Implemented XInput vibration support --- Source/OpenTK/Platform/Windows/XInputJoystick.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Source/OpenTK/Platform/Windows/XInputJoystick.cs b/Source/OpenTK/Platform/Windows/XInputJoystick.cs index 3155964..b3518ef 100644 --- a/Source/OpenTK/Platform/Windows/XInputJoystick.cs +++ b/Source/OpenTK/Platform/Windows/XInputJoystick.cs @@ -116,7 +116,14 @@ namespace OpenTK.Platform.Windows public bool SetVibration(int index, float left, float right) { - return false; + left = MathHelper.Clamp(left, 0.0f, 1.0f); + right = MathHelper.Clamp(right, 0.0f, 1.0f); + + XInputVibration vibration = new XInputVibration( + (ushort)(left * UInt16.MaxValue), + (ushort)(right * UInt16.MaxValue)); + + return xinput.SetState((XInputUserIndex)index, ref vibration) == XInputErrorCode.Success; } #endregion @@ -285,8 +292,14 @@ namespace OpenTK.Platform.Windows struct XInputVibration { - public short LeftMotorSpeed; - public short RightMotorSpeed; + public ushort LeftMotorSpeed; + public ushort RightMotorSpeed; + + public XInputVibration(ushort left, ushort right) + { + LeftMotorSpeed = left; + RightMotorSpeed = right; + } } struct XInputDeviceCapabilities -- 2.7.4