|
VR-Engage
2.2
|
The DtVirtualDpad converts analog x and y inputs (such as from a joystick or thumbstick) into discrete directional button states (up, down, left, right). It tracks both the current button states and state changes to provide pressed and released events.
#include <virtualDpad.h>
Public Types | |
| enum | Button { Up , Down , Left , Right } |
Public Member Functions | |
| DtVirtualDpad () | |
| virtual | ~DtVirtualDpad () |
| virtual void | update (const float x, const float y) |
| virtual bool | buttonPressed (const Button button) |
| virtual bool | buttonReleased (const Button button) |
| virtual void | clearEvents () |
Public Attributes | |
| const float | AxisThreshold = 0.5f |
Private Member Functions | |
| virtual void | setButtonState (const Button button, bool state) |
Private Attributes | |
| bool | myButtonStates [4] |
| bool | myButtonsChanged [4] |
|
inline |
Default constructor.
Initializes the d-pad with all buttons in the released state and no pending state changes
References myButtonsChanged, and myButtonStates.
|
inlinevirtual |
Virtual destructor.
|
inlinevirtual |
Updates the d-pad state based on x and y input values.
| x | The x-axis input value (positive = right, negative = left) |
| y | The y-axis input value (positive = up, negative = down) |
This method converts the continuous x and y inputs into discrete directional button states based on the axis with the greater magnitude. Only one direction can be active at a time (up, down, left, or right).
References AxisThreshold, clearEvents(), Down, Left, Right, setButtonState(), and Up.
|
inlinevirtual |
Checks if a button was just pressed.
| button | The button to check |
A button is considered "just pressed" if its state changed from released to pressed since the last call to update().
References myButtonsChanged, and myButtonStates.
|
inlinevirtual |
Checks if a button was just released.
| button | The button to check |
A button is considered "just released" if its state changed from pressed to released since the last call to update().
References myButtonsChanged, and myButtonStates.
|
inlinevirtual |
Clears all button events (pressed/released flags)
This method resets the state change tracking for all buttons without modifying their current pressed/released states. It is called automatically at the beginning of each update() call.
References myButtonsChanged.
Referenced by update().
|
inlineprivatevirtual |
Sets the state of a specific button.
| button | The button to set the state for |
| state | True for pressed, false for released |
This method updates the button state and tracks state changes. If the new state is different from the current state, the button is marked as changed.
References myButtonsChanged, and myButtonStates.
Referenced by update().
| const float DtVirtualDpad::AxisThreshold = 0.5f |
Threshold value for axis activation (default 0.5)
Axis values with magnitude greater than this threshold will trigger a button state change in the corresponding direction
Referenced by update().
|
private |
Current state of each button (true = pressed, false = released)
Referenced by buttonPressed(), buttonReleased(), DtVirtualDpad(), and setButtonState().
|
private |
Tracks whether each button state has changed since last update.
Referenced by buttonPressed(), buttonReleased(), clearEvents(), DtVirtualDpad(), and setButtonState().