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 | isButtonDown (const GamepadInput input) const |
|
Checks if a button is currently held down. More... | |
| bool | isButtonHeld (const GamepadInput input) const |
|
Checks if a button has been held for at least 2 frames. More... | |
| bool | isButtonUp (const GamepadInput input) const |
|
Checks if a button was released this frame. More... | |
| bool | isButtonPressed (const GamepadInput input) const |
|
Checks if a button was pressed this frame. More... | |
| bool | buttonStart () const noexcept |
|
Returns true when the Start button is pressed. More... | |
| bool | buttonPressedStart () const noexcept |
|
Returns true if Start was pressed this frame. 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
| uint32_t | currInput_ = 0 |
| uint32_t | prevInput_ = 0 |
| bool | buttonA_ = false |
|
State of the A button (true if pressed). More... | |
| bool | prevButtonA_ = false |
| bool | buttonB_ = false |
|
State of the B button (true if pressed). More... | |
| bool | prevButtonB_ = false |
| 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 | prevButtonStart_ = false |
| 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 | prevButtonDpadUp_ = false |
| 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 | prevButtonDpadDown_ = false |
| 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 60 of file GamepadState.ixx.
Public Constructors
GamepadState()
| default |
Default constructor.
Initializes all the values with 0.0f.
Definition at line 224 of file GamepadState.ixx.
GamepadState()
| inline explicit noexcept |
Creates a new GamepadState object.
Delegates to `updateAxes` for value initialization.
- See Also
Definition at line 233 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 217 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 470 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 479 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 631 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 703 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 712 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 694 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 685 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 640 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 649 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 667 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
buttonPressedStart()
| inline nodiscard noexcept |
Returns true if Start was pressed this frame.
- Returns
True if Start was just pressed.
Definition at line 622 of file GamepadState.ixx.
buttonRightBumper()
| inline nodiscard noexcept |
Returns true when the right bumper is pressed.
- Returns
true if pressed, false otherwise.
Definition at line 658 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 676 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 613 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 488 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 497 of file GamepadState.ixx.
Referenced by GamepadState and updateAxes.
isButtonDown()
| inline nodiscard |
Checks if a button is currently held down.
- Parameters
-
input The button to check.
- Returns
True if the button is currently pressed.
Definition at line 509 of file GamepadState.ixx.
References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.
isButtonHeld()
| inline nodiscard |
Checks if a button has been held for at least 2 frames.
- Parameters
-
input The button to check.
- Returns
True if the button was pressed last frame and is still pressed.
Definition at line 535 of file GamepadState.ixx.
References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.
isButtonPressed()
| inline nodiscard |
Checks if a button was pressed this frame.
- Parameters
-
input The button to check.
- Returns
True if the button was not pressed last frame but is pressed now.
Definition at line 588 of file GamepadState.ixx.
References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.
isButtonUp()
| inline nodiscard |
Checks if a button was released this frame.
- Parameters
-
input The button to check.
- Returns
True if the button was pressed last frame but is now released.
Definition at line 561 of file GamepadState.ixx.
References helios::input::types::A, helios::input::types::B, helios::input::types::Down, helios::input::types::Start and helios::input::types::Up.
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 431 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 371 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 381 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 444 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 391 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 401 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 458 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 411 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 421 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 288 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 208 of file GamepadState.ixx.
Private Member Attributes
axisLeftX_
|
Raw float value of the left stick's x-axis.
Definition at line 161 of file GamepadState.ixx.
axisLeftY_
|
Raw float value of the left stick's y-axis.
Definition at line 166 of file GamepadState.ixx.
axisRightX_
|
Raw float value of the right stick's x-axis.
Definition at line 171 of file GamepadState.ixx.
axisRightY_
|
Raw float value of the right stick's y-axis.
Definition at line 176 of file GamepadState.ixx.
buttonA_
|
State of the A button (true if pressed).
Definition at line 75 of file GamepadState.ixx.
buttonB_
|
State of the B button (true if pressed).
Definition at line 81 of file GamepadState.ixx.
buttonBack_
|
State of the Back button (true if pressed).
Definition at line 104 of file GamepadState.ixx.
buttonDpadDown_
|
State of the D-pad down button (true if pressed).
Definition at line 145 of file GamepadState.ixx.
buttonDpadLeft_
|
State of the D-pad left button (true if pressed).
Definition at line 151 of file GamepadState.ixx.
buttonDpadRight_
|
State of the D-pad right button (true if pressed).
Definition at line 140 of file GamepadState.ixx.
buttonDpadUp_
|
State of the D-pad up button (true if pressed).
Definition at line 134 of file GamepadState.ixx.
buttonGuide_
|
State of the Guide button (true if pressed).
Definition at line 109 of file GamepadState.ixx.
buttonLeftBumper_
|
State of the left bumper button (true if pressed).
Definition at line 114 of file GamepadState.ixx.
buttonLeftThumb_
|
State of the left thumbstick button (true if pressed).
Definition at line 124 of file GamepadState.ixx.
buttonRightBumper_
|
State of the right bumper button (true if pressed).
Definition at line 119 of file GamepadState.ixx.
buttonRightThumb_
|
State of the right thumbstick button (true if pressed).
Definition at line 129 of file GamepadState.ixx.
buttonStart_
|
State of the Start button (true if pressed).
Definition at line 97 of file GamepadState.ixx.
buttonX_
|
State of the X button (true if pressed).
Definition at line 87 of file GamepadState.ixx.
buttonY_
|
State of the Y button (true if pressed).
Definition at line 92 of file GamepadState.ixx.
currInput_
|
Definition at line 63 of file GamepadState.ixx.
left_
| mutable |
Cached vec2f representation of the left stick (x, y).
Definition at line 191 of file GamepadState.ixx.
needsUpdate_
| mutable |
Flag to indicate if the cached vec2f members need to be recalculated.
Definition at line 156 of file GamepadState.ixx.
prevButtonA_
|
Definition at line 76 of file GamepadState.ixx.
prevButtonB_
|
Definition at line 82 of file GamepadState.ixx.
prevButtonDpadDown_
|
Definition at line 146 of file GamepadState.ixx.
prevButtonDpadUp_
|
Definition at line 135 of file GamepadState.ixx.
prevButtonStart_
|
Definition at line 99 of file GamepadState.ixx.
prevInput_
|
Definition at line 64 of file GamepadState.ixx.
right_
| mutable |
Cached vec2f representation of the right stick (x, y).
Definition at line 196 of file GamepadState.ixx.
trigger_
| mutable |
Cached vec2f representation of the triggers (left, right).
Definition at line 201 of file GamepadState.ixx.
triggerLeft_
|
Raw float value of the left trigger.
Definition at line 181 of file GamepadState.ixx.
triggerRight_
|
Raw float value of the right trigger.
Definition at line 186 of file GamepadState.ixx.
Private Static Attributes
logger_
| static |
Shared logger instance for all GamepadState objects.
Definition at line 69 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.