[Input] Fixed GamePadState.SetAxis() implementation

GamePadState.SetAxis() receives a GamePadAxes enumeration, which is a
bitmask of the axes we wish to set. SetAxis now correctly decodes the
bitmask to apply the values we are interested in.
This commit is contained in:
thefiddler 2013-12-30 13:39:43 +01:00
parent f7fbf38c43
commit e997ddf9c6

View file

@ -111,26 +111,36 @@ namespace OpenTK.Input
internal void SetAxis(GamePadAxes axis, short value) internal void SetAxis(GamePadAxes axis, short value)
{ {
switch (axis) if ((axis & GamePadAxes.LeftX) != 0)
{ {
case GamePadAxes.LeftX: left_stick_x = value;
left_stick_x = value; }
break;
case GamePadAxes.LeftY: if ((axis & GamePadAxes.LeftY) != 0)
left_stick_y = value; {
break; left_stick_y = value;
}
case GamePadAxes.RightX: if ((axis & GamePadAxes.RightX) != 0)
right_stick_x = value; {
break; right_stick_x = value;
}
case GamePadAxes.RightY: if ((axis & GamePadAxes.RightY) != 0)
right_stick_y = value; {
break; right_stick_y = value;
}
default: if ((axis & GamePadAxes.LeftTrigger) != 0)
throw new ArgumentOutOfRangeException("axis"); {
// Adjust from [-32768, 32767] to [0, 255]
left_trigger = (byte)((ev.Value - short.MinValue) >> 8);
}
if ((axis & GamePadAxes.RightTrigger) != 0)
{
// Adjust from [-32768, 32767] to [0, 255]
right_trigger = (byte)((ev.Value - short.MinValue) >> 8);
} }
} }