internal void SetAxis(GamePadAxes axis, short value) { if ((axis & GamePadAxes.LeftX) != 0) { left_stick_x = value; } if ((axis & GamePadAxes.LeftY) != 0) { left_stick_y = (short)~value; } if ((axis & GamePadAxes.RightX) != 0) { right_stick_x = value; } if ((axis & GamePadAxes.RightY) != 0) { right_stick_y = (short)~value; } if ((axis & GamePadAxes.LeftTrigger) != 0) { // Adjust from [-32768, 32767] to [0, 255] left_trigger = (byte)((value - short.MinValue) >> 8); } if ((axis & GamePadAxes.RightTrigger) != 0) { // Adjust from [-32768, 32767] to [0, 255] right_trigger = (byte)((value - short.MinValue) >> 8); } }
internal void SetAxis(GamePadAxes axis, short value) { if ((byte)(axis & GamePadAxes.LeftX) != 0) { this.left_stick_x = value; } if ((byte)(axis & GamePadAxes.LeftY) != 0) { this.left_stick_y = value; } if ((byte)(axis & GamePadAxes.RightX) != 0) { this.right_stick_x = value; } if ((byte)(axis & GamePadAxes.RightY) != 0) { this.right_stick_y = value; } if ((byte)(axis & GamePadAxes.LeftTrigger) != 0) { this.left_trigger = (byte)(value - -32768 >> 8); } if ((byte)(axis & GamePadAxes.RightTrigger) != 0) { this.right_trigger = (byte)(value - -32768 >> 8); } }
internal Axis(string name, int playerIndex, GamePadAxes gamePadAxes) { Name = name; _type = InputTypes.GamePad; _playerIndex = playerIndex; _gamePadAxis = gamePadAxes; }
internal GamePadCapabilities(GamePadType type, GamePadAxes axes, Buttons buttons, bool is_connected) : this() { gamepad_type = (byte)type; this.axes = axes; this.buttons = buttons; this.is_connected = is_connected; }
GamePadAxes GetBoundAxes(IntPtr gamecontroller) { GamePadAxes axes = 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.LeftX) ? GamePadAxes.LeftX : 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.LeftY) ? GamePadAxes.LeftY : 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.RightX) ? GamePadAxes.RightX : 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.RightY) ? GamePadAxes.RightY : 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.TriggerLeft) ? GamePadAxes.LeftTrigger : 0; axes |= IsAxisBind(gamecontroller, GameControllerAxis.TriggerRight) ? GamePadAxes.RightTrigger : 0; return axes; }
GamePadAxes TranslateAxes(ref XInputGamePad pad) { GamePadAxes axes = 0; axes |= pad.ThumbLX != 0 ? GamePadAxes.LeftX : 0; axes |= pad.ThumbLY != 0 ? GamePadAxes.LeftY : 0; axes |= pad.LeftTrigger != 0 ? GamePadAxes.LeftTrigger : 0; axes |= pad.ThumbRX != 0 ? GamePadAxes.RightX : 0; axes |= pad.ThumbRY != 0 ? GamePadAxes.RightY : 0; axes |= pad.RightTrigger != 0 ? GamePadAxes.RightTrigger : 0; return(axes); }
public GamePadCapabilities GetCapabilities(int index) { XInputDeviceCapabilities xcaps; XInputErrorCode error = xinput.GetCapabilities( (XInputUserIndex)index, XInputCapabilitiesFlags.Default, out xcaps); if (error == XInputErrorCode.Success) { GamePadType type = TranslateSubType(xcaps.SubType); Buttons buttons = TranslateButtons(xcaps.GamePad.Buttons); GamePadAxes axes = TranslateAxes(ref xcaps.GamePad); return(new GamePadCapabilities(type, axes, buttons, true)); } return(new GamePadCapabilities()); }
public GamePadCapabilities GetCapabilities(int index) { var joy = Joystick.GetCapabilities(index); GamePadCapabilities pad; if (joy.IsConnected) { var configuration = GetConfiguration(Joystick.GetGuid(index)); GamePadAxes mapped_axes = 0; Buttons mapped_buttons = 0; foreach (var map in configuration) { switch (map.Target.Type) { case ConfigurationType.Axis: mapped_axes |= map.Target.Axis; break; case ConfigurationType.Button: mapped_buttons |= map.Target.Button; break; } } pad = new GamePadCapabilities( GamePadType.GamePad, // Todo: detect different types mapped_axes, mapped_buttons, joy.IsConnected, configuration.Name != GamePadConfigurationDatabase.UnmappedName); } else { pad = new GamePadCapabilities(); } return(pad); }
public GamePadConfigurationTarget(GamePadAxes axis) : this() { Type = ConfigurationType.Axis; map_axis = axis; }
private bool IsAxisValid(GamePadAxes axis) { int index = (int)axis; return(index >= 0 && index < GamePad.MaxAxisCount); }
internal Axis(string name, PlayerIndex playerIndex, GamePadAxes gamePadAxes) : this(name, (int)playerIndex, gamePadAxes) { }
private bool IsAxisValid(GamePadAxes axis) { return(axis >= (GamePadAxes)0 && axis < (GamePadAxes.LeftY | GamePadAxes.RightX)); }
public void GamePadAxesTheory(float leftThumbSticksX, float leftThumbSticksY, float rightThumbSticksX, float rightThumbSticksY, float leftTrigger, float rightTrigger, GamePadAxes gamePadAxes, float expected) { GamePadState state = new GamePadState( new Vector2(leftThumbSticksX, leftThumbSticksY), new Vector2(rightThumbSticksX, rightThumbSticksY), leftTrigger, rightTrigger, new Buttons[0]); string actionName = "Action" + _counter++; InputManager.CreateAction(actionName, PlayerIndex.One, gamePadAxes); InputManager.GamePadStates = new GamePadState[] { state }; InputManager.ActionUpdate(); Assert.Equal(expected, InputManager.GetAxis(actionName)); }