/// <inheritdoc/> public override GamePadJoystickDirection GetJoystickDirection(GamePadJoystick joystick, Single?threshold = null) { Contract.EnsureNotDisposed(this, Disposed); var thresholdValue = Math.Abs(threshold ?? AxisDownThreshold); var hAxis = GamePadAxis.None; var vAxis = GamePadAxis.None; switch (joystick) { case GamePadJoystick.None: return(GamePadJoystickDirection.None); case GamePadJoystick.Left: hAxis = GamePadAxis.LeftJoystickX; vAxis = GamePadAxis.LeftJoystickY; break; case GamePadJoystick.Right: hAxis = GamePadAxis.RightJoystickX; vAxis = GamePadAxis.RightJoystickY; break; default: throw new ArgumentException("joystick"); } var hAxisValue = GetAxisValue(hAxis); var vAxisValue = GetAxisValue(vAxis); var result = GamePadJoystickDirection.None; if (hAxisValue <= -thresholdValue) { result |= GamePadJoystickDirection.Left; } else if (hAxisValue >= thresholdValue) { result |= GamePadJoystickDirection.Right; } if (vAxisValue <= -thresholdValue) { result |= GamePadJoystickDirection.Up; } else if (vAxisValue > thresholdValue) { result |= GamePadJoystickDirection.Down; } return(result); }
/// <summary> /// Gets the direction in which the specified joystick is pointed, using the specified minimum threshold value. /// If no threshold is specified, the value of <see cref="AxisDownThreshold"/> is used instead. /// </summary> /// <param name="joystick">A <see cref="GamePadJoystick"/> value that represents the joystick to evaluate.</param> /// <param name="threshold">The threshold value at which the joystick is considered to be pointed in a particular direction.</param> /// <returns>A set of <see cref="GamePadJoystickDirection"/> values which represent the joystick's direction.</returns> public abstract GamePadJoystickDirection GetJoystickDirection(GamePadJoystick joystick, Single?threshold = null);