From eeaa3276f17cfaba696487eab88cb3087a5e45ed Mon Sep 17 00:00:00 2001 From: thefiddler Date: Wed, 29 Jan 2014 10:39:18 +0100 Subject: [PATCH] [Input] Implemented axis-button mappings --- Source/OpenTK/Platform/MappedGamePadDriver.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Source/OpenTK/Platform/MappedGamePadDriver.cs b/Source/OpenTK/Platform/MappedGamePadDriver.cs index 12f918c9..79245405 100644 --- a/Source/OpenTK/Platform/MappedGamePadDriver.cs +++ b/Source/OpenTK/Platform/MappedGamePadDriver.cs @@ -77,17 +77,20 @@ namespace OpenTK.Platform { // JoystickAxis -> Buttons/GamePadAxes mapping JoystickAxis source_axis = map.Source.Axis; - GamePadAxes target_axis = map.Target.Axis; short value = joy.GetAxisRaw(source_axis); switch (map.Target.Type) { case ConfigurationType.Axis: - pad.SetAxis(target_axis, value); + pad.SetAxis(map.Target.Axis, value); break; case ConfigurationType.Button: - throw new NotImplementedException(); + // Todo: if SDL2 GameController config is ever updated to + // distinguish between negative/positive axes, then remove + // Math.Abs below. + // Button is considered press when the axis is >= 0.5 from center + pad.SetButton(map.Target.Button, Math.Abs(value) >= short.MaxValue >> 1); break; } } @@ -97,17 +100,19 @@ namespace OpenTK.Platform { // JoystickButton -> Buttons/GamePadAxes mapping JoystickButton source_button = map.Source.Button; - Buttons target_button = map.Target.Button; bool pressed = joy.GetButton(source_button) == ButtonState.Pressed; switch (map.Target.Type) { case ConfigurationType.Axis: - throw new NotImplementedException(); + // Todo: if SDL2 GameController config is ever updated to + // distinguish between negative/positive axes, then update + // the following line to support both. + pad.SetAxis(map.Target.Axis, pressed ? short.MaxValue : (short)0); break; case ConfigurationType.Button: - pad.SetButton(target_button, pressed); + pad.SetButton(map.Target.Button, pressed); break; } }