GamepadState Class
A lightweight class for transferring the state of a Gamepad. More...
Declaration
Public Constructors Index
| GamepadState ()=default | |
|
Default constructor. More... | |
| GamepadState (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft) noexcept | |
|
Creates a new GamepadState object. More... | |
Public Destructor Index
| ~GamepadState ()=default | |
Public Member Functions Index
| void | updateAxes (float axisLeftX, float axisLeftY, float axisRightX, float axisRightY, float triggerLeft, float triggerRight, bool buttonA, bool buttonB, bool buttonX, bool buttonY, bool buttonStart, bool buttonBack, bool buttonGuide, bool buttonLeftBumper, bool buttonRightBumper, bool buttonLeftThumb, bool buttonRightThumb, bool buttonDpadUp, bool buttonDpadRight, bool buttonDpadDown, bool buttonDpadLeft) noexcept |
|
Updates the axes and button states of this GamepadState object. More... | |
| float | leftX () const noexcept |
|
Returns the current value of the left stick's x-axis. More... | |
| float | leftY () const noexcept |
|
Returns the current value of the left stick's y-axis. More... | |
| float | rightX () const noexcept |
|
Returns the current value of the right stick's x-axis. More... | |
| float | rightY () const noexcept |
|
Returns the current value of the right stick's y-axis. More... | |
| float | triggerLeft () const noexcept |
|
Returns the current value of the left trigger. More... | |
| float | triggerRight () const noexcept |
|
Returns the current value of the right trigger. More... | |
| helios::math::vec2f | left () const noexcept |
|
Returns the state of the left stick as a helios::math::vec2f. More... | |
| helios::math::vec2f | right () const noexcept |
|
Returns the state of the right stick as a helios::math::vec2f. More... | |
| helios::math::vec2f | trigger () const noexcept |
|
Returns the state of the triggers as a helios::math::vec2f. More... | |
| bool | buttonA () const noexcept |
|
Returns true when the A button is pressed. More... | |
| bool | buttonB () const noexcept |
|
Returns true when the B button is pressed. More... | |
| bool | buttonX () const noexcept |
|
Returns true when the X button is pressed. More... | |
| bool | buttonY () const noexcept |
|
Returns true when the Y button is pressed. More... | |
| bool | buttonStart () const noexcept |
|
Returns true when the Start button is pressed. More... | |
| bool | buttonBack () const noexcept |
|
Returns true when the Back button is pressed. More... | |
| bool | buttonGuide () const noexcept |
|
Returns true when the Guide button is pressed. More... | |
| bool | buttonLeftBumper () const noexcept |
|
Returns true when the left bumper is pressed. More... | |
| bool | buttonRightBumper () const noexcept |
|
Returns true when the right bumper is pressed. More... | |
| bool | buttonLeftThumb () const noexcept |
|
Returns true when the left thumbstick button is pressed. More... | |
| bool | buttonRightThumb () const noexcept |
|
Returns true when the right thumbstick button is pressed. More... | |
| bool | buttonDpadUp () const noexcept |
|
Returns true when the D-pad Up button is pressed. More... | |
| bool | buttonDpadRight () const noexcept |
|
Returns true when the D-pad Right button is pressed. More... | |
| bool | buttonDpadDown () const noexcept |
|
Returns true when the D-pad Down button is pressed. More... | |
| bool | buttonDpadLeft () const noexcept |
|
Returns true when the D-pad Left button is pressed. More... | |
Private Member Functions Index
| void | update () const noexcept |
|
Internal method to update the cached vec2f representations. This method should be called when the current values of the axes are queried in vec2f form and `needsUpdate_` evaluates to `true`. More... | |
Private Member Attributes Index
| bool | buttonA_ = false |
|
State of the A button (true if pressed). More... | |
| bool | buttonB_ = false |
|
State of the B button (true if pressed). More... | |
| bool | buttonX_ = false |
|
State of the X button (true if pressed). More... | |
| bool | buttonY_ = false |
|
State of the Y button (true if pressed). More... | |
| bool | buttonStart_ = false |
|
State of the Start button (true if pressed). More... | |
| bool | buttonBack_ = false |
|
State of the Back button (true if pressed). More... | |
| bool | buttonGuide_ = false |
|
State of the Guide button (true if pressed). More... | |
| bool | buttonLeftBumper_ = false |
|
State of the left bumper button (true if pressed). More... | |
| bool | buttonRightBumper_ = false |
|
State of the right bumper button (true if pressed). More... | |
| bool | buttonLeftThumb_ = false |
|
State of the left thumbstick button (true if pressed). More... | |
| bool | buttonRightThumb_ = false |
|
State of the right thumbstick button (true if pressed). More... | |
| bool | buttonDpadUp_ = false |
|
State of the D-pad up button (true if pressed). More... | |
| bool | buttonDpadRight_ = false |
|
State of the D-pad right button (true if pressed). More... | |
| bool | buttonDpadDown_ = false |
|
State of the D-pad down button (true if pressed). More... | |
| bool | buttonDpadLeft_ = false |
|
State of the D-pad left button (true if pressed). More... | |
| bool | needsUpdate_ = true |
|
Flag to indicate if the cached vec2f members need to be recalculated. More... | |
| float | axisLeftX_ {} |
|
Raw float value of the left stick's x-axis. More... | |
| float | axisLeftY_ {} |
|
Raw float value of the left stick's y-axis. More... | |
| float | axisRightX_ {} |
|
Raw float value of the right stick's x-axis. More... | |
| float | axisRightY_ {} |
|
Raw float value of the right stick's y-axis. More... | |
| float | triggerLeft_ {} |
|
Raw float value of the left trigger. More... | |
| float | triggerRight_ {} |
|
Raw float value of the right trigger. More... | |
| helios::math::vec2f | left_ |
|
Cached vec2f representation of the left stick (x, y). More... | |
| helios::math::vec2f | right_ |
|
Cached vec2f representation of the right stick (x, y). More... | |
| helios::math::vec2f | trigger_ |
|
Cached vec2f representation of the triggers (left, right). More... | |
Private Static Attributes Index
| static const helios::util::log::Logger & | logger_ = helios::util::log::LogManager::loggerForScope(HELIOS_LOG_SCOPE) |
|
Shared logger instance for all GamepadState objects. More... | |
Description
A lightweight class for transferring the state of a Gamepad.
This class models a reusable object representing the input state of a gamepad. The input state of a gamepad consists of the state of the left and right trigger, ranging from [0, 1], where 1 means fully pressed and 0 means not pressed at all.
Similarly, a GamepadState provides information about the left and the right gamepad axes. Both the x- and the y-axis range from [-1, 1]. For the x-axis, the following holds:
- 0.00 => not moved at all
- -1.00 => moved all the way to the left
- 1.00 => moved all the way to the right
For the y-axis the positive direction corresponds to "up" and the negative direction corresponds to "down".
Updating the values is done by calling `updateAxes` on this object.
For convenient access of the axes in 2D coordinates, the class provides accessors to the sticks' axes in `vec2f` form.
Button states are generally represented with boolean values, i.e. true for pressed, otherwise false.
Implementations must account for joystick drift: achieving exactly 0.0 for x/y when no human input occurred is rare. Consider applying a dead zone when processing the GamepadState. Axis values are individually clipped to [-1.0, 1.0], but the magnitude of the resulting (x, y) vector may exceed 1.0. Applications should normalize input vectors where appropriate and possibly offer calibration.
This implementation is inspired by the GLFW gamepad input model.
Definition at line 54 of file GamepadState.ixx.
Public Constructors
GamepadState()
| default |
Default constructor.
Initializes all the values with 0.0f.
Definition at line 209 of file GamepadState.ixx.
GamepadState()
| inline explicit noexcept |
Creates a new GamepadState object.
Delegates to `updateAxes` for value initialization.
- See Also
Definition at line 218 of file GamepadState.ixx.
References buttonA, buttonB, buttonBack, buttonDpadDown, buttonDpadLeft, buttonDpadRight, buttonDpadUp, buttonGuide, buttonLeftBumper, buttonLeftThumb, buttonRightBumper, buttonRightThumb, buttonStart, buttonX, buttonY, triggerLeft, triggerRight and updateAxes.
Public Destructor
~GamepadState()
| default |
Definition at line 202 of file GamepadState.ixx.
Public Member Functions
buttonA()
| inline nodiscard noexcept |
Returns true when the A button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 435 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonB()
| inline nodiscard noexcept |
Returns true when the B button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 444 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonBack()
| inline nodiscard noexcept |
Returns true when the Back button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 480 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonDpadDown()
| inline nodiscard noexcept |
Returns true when the D-pad Down button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 552 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonDpadLeft()
| inline nodiscard noexcept |
Returns true when the D-pad Left button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 561 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonDpadRight()
| inline nodiscard noexcept |
Returns true when the D-pad Right button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 543 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonDpadUp()
| inline nodiscard noexcept |
Returns true when the D-pad Up button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 534 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonGuide()
| inline nodiscard noexcept |
Returns true when the Guide button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 489 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonLeftBumper()
| inline nodiscard noexcept |
Returns true when the left bumper is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 498 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonLeftThumb()
| inline nodiscard noexcept |
Returns true when the left thumbstick button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 516 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonRightBumper()
| inline nodiscard noexcept |
Returns true when the right bumper is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 507 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonRightThumb()
| inline nodiscard noexcept |
Returns true when the right thumbstick button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 525 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonStart()
| inline nodiscard noexcept |
Returns true when the Start button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 471 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonX()
| inline nodiscard noexcept |
Returns true when the X button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 453 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonY()
| inline nodiscard noexcept |
Returns true when the Y button is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 462 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
left()
| inline nodiscard noexcept |
Returns the state of the left stick as a helios::math::vec2f.
- Returns
A helios::math::vec2f, with the first component being the x-axis, the second component the y-axis.
Definition at line 396 of file GamepadState.ixx.
leftX()
| inline nodiscard noexcept |
Returns the current value of the left stick's x-axis.
- Returns
float value in the range [-1, 1]
Definition at line 336 of file GamepadState.ixx.
leftY()
| inline nodiscard noexcept |
Returns the current value of the left stick's y-axis.
- Returns
float value in the range [-1, 1]
Definition at line 346 of file GamepadState.ixx.
right()
| inline nodiscard noexcept |
Returns the state of the right stick as a helios::math::vec2f.
- Returns
A helios::math::vec2f, with the first component being the x-axis, the second component the y-axis.
Definition at line 409 of file GamepadState.ixx.
rightX()
| inline nodiscard noexcept |
Returns the current value of the right stick's x-axis.
- Returns
float value in the range [-1, 1]
Definition at line 356 of file GamepadState.ixx.
rightY()
| inline nodiscard noexcept |
Returns the current value of the right stick's y-axis.
- Returns
float value in the range [-1, 1]
Definition at line 366 of file GamepadState.ixx.
trigger()
| inline nodiscard noexcept |
Returns the state of the triggers as a helios::math::vec2f.
- Returns
A helios::math::vec2f, with the first component being the left trigger-axis, the second component the right trigger-axis.
Definition at line 423 of file GamepadState.ixx.
triggerLeft()
| inline nodiscard noexcept |
Returns the current value of the left trigger.
- Returns
float value in the range [0, 1]
Definition at line 376 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
triggerRight()
| inline nodiscard noexcept |
Returns the current value of the right trigger.
- Returns
float value in the range [0, 1]
Definition at line 386 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
updateAxes()
| inline noexcept |
Updates the axes and button states of this GamepadState object.
This method updates raw axis and trigger values and stores the boolean state of all standard gamepad buttons. Float parameters are asserted to be in their expected ranges and then clamped.
For the sticks' range [-1, 1] the following holds: -1 means moved all the way left/down, 0 means not moved at all, 1 means moved all the way right/up.
For the triggers' range of [0, 1] the following holds: 0 means not pressed, 1 means fully pressed.
- Parameters
-
axisLeftX The x-axis of the left stick, expected in [-1, 1].
axisLeftY The y-axis of the left stick, expected in [-1, 1].
axisRightX The x-axis of the right stick, expected in [-1, 1].
axisRightY The y-axis of the right stick, expected in [-1, 1].
triggerLeft The left trigger value, expected in [0, 1].
triggerRight The right trigger value, expected in [0, 1].
buttonA True if the A button is pressed.
buttonB True if the B button is pressed.
buttonX True if the X button is pressed.
buttonY True if the Y button is pressed.
buttonStart True if the Start button is pressed.
buttonBack True if the Back button is pressed.
buttonGuide True if the Guide (platform) button is pressed.
buttonLeftBumper True if the left bumper is pressed.
buttonRightBumper True if the right bumper is pressed.
buttonLeftThumb True if the left thumbstick button is pressed.
buttonRightThumb True if the right thumbstick button is pressed.
buttonDpadUp True if the D-pad Up button is pressed.
buttonDpadRight True if the D-pad Right button is pressed.
buttonDpadDown True if the D-pad Down button is pressed.
buttonDpadLeft True if the D-pad Left button is pressed.
Definition at line 273 of file GamepadState.ixx.
References buttonA, buttonB, buttonBack, buttonDpadDown, buttonDpadLeft, buttonDpadRight, buttonDpadUp, buttonGuide, buttonLeftBumper, buttonLeftThumb, buttonRightBumper, buttonRightThumb, buttonStart, buttonX, buttonY, triggerLeft and triggerRight.
Referenced by GamepadState.
Private Member Functions
update()
| inline noexcept |
Internal method to update the cached vec2f representations. This method should be called when the current values of the axes are queried in vec2f form and `needsUpdate_` evaluates to `true`.
Definition at line 193 of file GamepadState.ixx.
Private Member Attributes
axisLeftX_
|
Raw float value of the left stick's x-axis.
Definition at line 146 of file GamepadState.ixx.
axisLeftY_
|
Raw float value of the left stick's y-axis.
Definition at line 151 of file GamepadState.ixx.
axisRightX_
|
Raw float value of the right stick's x-axis.
Definition at line 156 of file GamepadState.ixx.
axisRightY_
|
Raw float value of the right stick's y-axis.
Definition at line 161 of file GamepadState.ixx.
buttonA_
|
State of the A button (true if pressed).
Definition at line 66 of file GamepadState.ixx.
buttonB_
|
State of the B button (true if pressed).
Definition at line 71 of file GamepadState.ixx.
buttonBack_
|
State of the Back button (true if pressed).
Definition at line 91 of file GamepadState.ixx.
buttonDpadDown_
|
State of the D-pad down button (true if pressed).
Definition at line 131 of file GamepadState.ixx.
buttonDpadLeft_
|
State of the D-pad left button (true if pressed).
Definition at line 136 of file GamepadState.ixx.
buttonDpadRight_
|
State of the D-pad right button (true if pressed).
Definition at line 126 of file GamepadState.ixx.
buttonDpadUp_
|
State of the D-pad up button (true if pressed).
Definition at line 121 of file GamepadState.ixx.
buttonGuide_
|
State of the Guide button (true if pressed).
Definition at line 96 of file GamepadState.ixx.
buttonLeftBumper_
|
State of the left bumper button (true if pressed).
Definition at line 101 of file GamepadState.ixx.
buttonLeftThumb_
|
State of the left thumbstick button (true if pressed).
Definition at line 111 of file GamepadState.ixx.
buttonRightBumper_
|
State of the right bumper button (true if pressed).
Definition at line 106 of file GamepadState.ixx.
buttonRightThumb_
|
State of the right thumbstick button (true if pressed).
Definition at line 116 of file GamepadState.ixx.
buttonStart_
|
State of the Start button (true if pressed).
Definition at line 86 of file GamepadState.ixx.
buttonX_
|
State of the X button (true if pressed).
Definition at line 76 of file GamepadState.ixx.
buttonY_
|
State of the Y button (true if pressed).
Definition at line 81 of file GamepadState.ixx.
left_
| mutable |
Cached vec2f representation of the left stick (x, y).
Definition at line 176 of file GamepadState.ixx.
needsUpdate_
| mutable |
Flag to indicate if the cached vec2f members need to be recalculated.
Definition at line 141 of file GamepadState.ixx.
right_
| mutable |
Cached vec2f representation of the right stick (x, y).
Definition at line 181 of file GamepadState.ixx.
trigger_
| mutable |
Cached vec2f representation of the triggers (left, right).
Definition at line 186 of file GamepadState.ixx.
triggerLeft_
|
Raw float value of the left trigger.
Definition at line 166 of file GamepadState.ixx.
triggerRight_
|
Raw float value of the right trigger.
Definition at line 171 of file GamepadState.ixx.
Private Static Attributes
logger_
| static |
Shared logger instance for all GamepadState objects.
Definition at line 60 of file GamepadState.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.