VR-Engage  2.2
Loading...
Searching...
No Matches
DtVirtualDpad Class Reference

Detailed Description

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]
 

Member Enumeration Documentation

◆ Button

Enumeration of d-pad button directions.

Enumerator
Up 

Up direction button.

Down 

Down direction button.

Left 

Left direction button.

Right 

Right direction button.

Constructor & Destructor Documentation

◆ DtVirtualDpad()

DtVirtualDpad::DtVirtualDpad ( )
inline

Default constructor.

Initializes the d-pad with all buttons in the released state and no pending state changes

References myButtonsChanged, and myButtonStates.

◆ ~DtVirtualDpad()

virtual DtVirtualDpad::~DtVirtualDpad ( )
inlinevirtual

Virtual destructor.

Member Function Documentation

◆ update()

virtual void DtVirtualDpad::update ( const float x,
const float y )
inlinevirtual

Updates the d-pad state based on x and y input values.

Parameters
xThe x-axis input value (positive = right, negative = left)
yThe 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.

◆ buttonPressed()

virtual bool DtVirtualDpad::buttonPressed ( const Button button)
inlinevirtual

Checks if a button was just pressed.

Parameters
buttonThe button to check
Returns
True if the button was just pressed, false otherwise

A button is considered "just pressed" if its state changed from released to pressed since the last call to update().

References myButtonsChanged, and myButtonStates.

◆ buttonReleased()

virtual bool DtVirtualDpad::buttonReleased ( const Button button)
inlinevirtual

Checks if a button was just released.

Parameters
buttonThe button to check
Returns
True if the button was just released, false otherwise

A button is considered "just released" if its state changed from pressed to released since the last call to update().

References myButtonsChanged, and myButtonStates.

◆ clearEvents()

virtual void DtVirtualDpad::clearEvents ( )
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().

◆ setButtonState()

virtual void DtVirtualDpad::setButtonState ( const Button button,
bool state )
inlineprivatevirtual

Sets the state of a specific button.

Parameters
buttonThe button to set the state for
stateTrue 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().

Member Data Documentation

◆ AxisThreshold

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().

◆ myButtonStates

bool DtVirtualDpad::myButtonStates[4]
private

Current state of each button (true = pressed, false = released)

Referenced by buttonPressed(), buttonReleased(), DtVirtualDpad(), and setButtonState().

◆ myButtonsChanged

bool DtVirtualDpad::myButtonsChanged[4]
private

Tracks whether each button state has changed since last update.

Referenced by buttonPressed(), buttonReleased(), clearEvents(), DtVirtualDpad(), and setButtonState().


The documentation for this class was generated from the following file: