Browse files

[Input] Implemented axis-button mappings

  • Loading branch information...
1 parent ef429af commit eeaa3276f17cfaba696487eab88cb3087a5e45ed @thefiddler thefiddler committed Jan 29, 2014
Showing with 11 additions and 6 deletions.
  1. +11 −6 Source/OpenTK/Platform/MappedGamePadDriver.cs
View
17 Source/OpenTK/Platform/MappedGamePadDriver.cs
@@ -77,17 +77,20 @@ public GamePadState GetState(int index)
{
// 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 @@ public GamePadState GetState(int index)
{
// 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;
}
}

0 comments on commit eeaa327

Please sign in to comment.