VR-Engage  2.2
Loading...
Searching...
No Matches
makVrv::DtVirtualRealityControllerState Class Reference

Detailed Description

This class represents the state of a VR controller at a specific point in time, including its position, orientation, button states, touch states, and analog input values. It also tracks which aspects of the controller state have changed since the last update cycle, making it easier for event handlers to respond to specific types of input events (e.g., button presses, controller movements).

#include <DtVirtualRealityControllerState.h>

Public Types

enum  DeviceType {
  Type_Undefined = 0 , Type_Left = 1 << 1 , Type_Right = 1 << 2 , Type_Tracked = 1 << 3 ,
  Type_Input = 1 << 4 , Type_HMD = 1 | Type_Tracked , Type_LeftHand = Type_Left | Type_Input | Type_Tracked , Type_RightHand = Type_Right | Type_Input | Type_Tracked
}
 
enum  ButtonId {
  Button_System = 1 << 0 , Button_Menu = 1 << 1 , Button_Trigger = 1 << 2 , Button_Grip = 1 << 3 ,
  Button_A = 1 << 4 , Button_B = 1 << 5 , Button_Thumb = 1 << 6 , Button_Left = 1 << 7 ,
  Button_Up = 1 << 8 , Button_Right = 1 << 9 , Button_Down = 1 << 10
}
 
enum  TouchId {
  Touch_Trigger = 1 << 0 , Touch_Grip = 1 << 1 , Touch_A = 1 << 2 , Touch_B = 1 << 3 ,
  Touch_Thumb = 1 << 4
}
 
enum  AxisId {
  Axis_Thumb = 0 , Axis_Trigger = 1 , Axis_Grip = 2 , Axis_3 = 3 ,
  Axis_4 = 4
}
 
enum  ControllerEventType { NoEvent = 0 , ControllerDiscovered , ControllerLost , StateChanged }
 
using Bitfield = unsigned long long
 
using ControllerId = unsigned int
 
using DtVector2f = DtVector2<float32>
 

Public Member Functions

 DtVirtualRealityControllerState ()
 
 DtVirtualRealityControllerState (const DtVirtualRealityControllerState &orig)
 
virtual ~DtVirtualRealityControllerState ()
 
DtVirtualRealityControllerStateoperator= (const DtVirtualRealityControllerState &rhs)
 
virtual ControllerId controllerId () const
 
virtual void setControllerId (ControllerId)
 
virtual Bitfield controllerType () const
 
virtual void setControllerType (Bitfield)
 
virtual DtVector position () const
 
virtual void setPosition (const DtVector &pos)
 
virtual DtQuat orientation () const
 
virtual void setOrientation (const DtQuat &ori)
 
virtual Bitfield buttonStates () const
 
virtual void setButtonStates (Bitfield buttonStates)
 
virtual bool buttonState (ButtonId buttonId) const
 
virtual void setButtonState (ButtonId buttonId, bool down)
 
virtual Bitfield touchStates () const
 
virtual void setTouchStates (Bitfield touchStates)
 
virtual bool touchState (TouchId touchId) const
 
virtual void setTouchState (TouchId touchId, bool touched)
 
virtual DtVector2f axisPosition (AxisId axisId) const
 
virtual void setAxisPosition (AxisId axisId, const DtVector2f &value)
 
virtual DtVector2f axisDeadZone (AxisId axisId) const
 
virtual void setAxisDeadZone (AxisId axisId, const DtVector2f &value)
 
virtual void setControllerAsLost ()
 
virtual bool controllerWasLost () const
 
virtual Bitfield buttonsChanged () const
 
virtual bool buttonChanged (ButtonId buttonId) const
 
virtual bool buttonPressed (ButtonId buttonId) const
 
virtual bool buttonReleased (ButtonId buttonId) const
 
virtual Bitfield touchChanged () const
 
virtual bool touchChanged (TouchId touchid) const
 
virtual bool touchStarted (TouchId touchId) const
 
virtual bool touchEnded (TouchId touchId) const
 
virtual Bitfield axesChanged () const
 
virtual bool axisChanged (AxisId axisId) const
 
virtual bool controllerMoved () const
 
virtual ControllerEventType controllerEvent () const
 
virtual void clearEvent ()
 

Static Public Member Functions

static unsigned int MaxAxes ()
 
static Bitfield bit (unsigned int n)
 

Static Public Attributes

static const ControllerId NoId = ControllerId(-1)
 

Protected Member Functions

virtual void markStateChanged ()
 

Protected Attributes

ControllerId myControllerId
 
Bitfield myControllerType
 
DtVector myPosition
 
DtQuat myOrientation
 
Bitfield myButtonStates
 
Bitfield myTouchStates
 
std::vector< DtVector2fmyAxisStates
 
std::vector< DtVector2fmyAxisDeadZones
 
ControllerEventType myEventType
 
Bitfield myButtonsChanged
 
Bitfield myTouchChanged
 
Bitfield myAxesChanged
 
bool myControllerMoved
 

Member Typedef Documentation

◆ Bitfield

Type used for bit flags throughout the class.

This type is used for representing sets of buttons, touch surfaces, or axes as bit flags, where each bit corresponds to a specific item.

◆ ControllerId

Type used for controller identification.

This type is used to uniquely identify controllers in the VR system.

◆ DtVector2f

Type used for 2D vector values.

This type is used for representing 2D analog input values, such as thumbstick or touchpad positions.

Member Enumeration Documentation

◆ DeviceType

Non-exclusive controller device properties.

Enumerator
Type_Undefined 
Type_Left 
Type_Right 
Type_Tracked 
Type_Input 
Type_HMD 
Type_LeftHand 
Type_RightHand 

◆ ButtonId

Unique known button IDs; controller may have additional buttons.

Enumerator
Button_System 
Button_Menu 
Button_Trigger 
Button_Grip 
Button_A 
Button_B 
Button_Thumb 
Button_Left 
Button_Up 
Button_Right 
Button_Down 

◆ TouchId

Unique known touch surface IDs; controller may have additional surfaces.

Enumerator
Touch_Trigger 
Touch_Grip 
Touch_A 
Touch_B 
Touch_Thumb 

◆ AxisId

Unique known axis IDs; controller may have additional axes.

Enumerator
Axis_Thumb 
Axis_Trigger 
Axis_Grip 
Axis_3 
Axis_4 

◆ ControllerEventType

Overall status of this controller.

The first time a controller is added to the map, the event type will be ControllerDiscovered, and all change flags will be true. When a controller is lost, it will appear for one more event with type ControllerLost, with the last known state. All change flags will be false, and the controller will be removed from the map after the event is processed.

During normal operation, the event type for a controller will be either NoEvent or StateChanged, indicating whether there has been any change in the state of this controller. If event type is StateChanged, individual change flags can be used to determine what component or components have changed since the last event cycle.

Enumerator
NoEvent 
ControllerDiscovered 
ControllerLost 
StateChanged 

Constructor & Destructor Documentation

◆ DtVirtualRealityControllerState() [1/2]

makVrv::DtVirtualRealityControllerState::DtVirtualRealityControllerState ( )

Default constructor.

Initializes a new controller state with default values. The controller ID is set to NoId, event type is set to NoEvent, and all state values and change flags are initialized to zero/false.

Referenced by DtVirtualRealityControllerState(), and operator=().

◆ DtVirtualRealityControllerState() [2/2]

makVrv::DtVirtualRealityControllerState::DtVirtualRealityControllerState ( const DtVirtualRealityControllerState & orig)

Copy constructor.

Parameters
origThe controller state to copy

Creates a new controller state that is a copy of the original.

References DtVirtualRealityControllerState().

◆ ~DtVirtualRealityControllerState()

virtual makVrv::DtVirtualRealityControllerState::~DtVirtualRealityControllerState ( )
virtual

Virtual destructor.

Cleans up any resources associated with the controller state.

Member Function Documentation

◆ MaxAxes()

static unsigned int makVrv::DtVirtualRealityControllerState::MaxAxes ( )
static

Gets the maximum number of analog axes supported by the system.

Returns
Maximum number of supported axes

Returns the maximum number of analog axes that can be tracked for a controller. Not all controllers will have this many axes, but the system allocates space for this many to accommodate all supported controller types.

◆ bit()

static Bitfield makVrv::DtVirtualRealityControllerState::bit ( unsigned int n)
static

Converts an integer to the corresponding bit in a bitfield.

Parameters
nThe bit position (0-63)
Returns
A bitfield with only the nth bit set

This convenience function converts an integer n to a bitfield with only the nth bit set (equivalent to 1 << n). This is useful for working with the various bitfields used throughout this class.

◆ operator=()

DtVirtualRealityControllerState & makVrv::DtVirtualRealityControllerState::operator= ( const DtVirtualRealityControllerState & rhs)

Assignment operator.

Parameters
rhsThe controller state to copy
Returns
Reference to this object after assignment

Assigns the contents of another controller state to this one.

References DtVirtualRealityControllerState().

◆ controllerId()

virtual ControllerId makVrv::DtVirtualRealityControllerState::controllerId ( ) const
virtual

Unique integer identifier for this VR Controller device.

◆ setControllerId()

virtual void makVrv::DtVirtualRealityControllerState::setControllerId ( ControllerId )
virtual

◆ controllerType()

virtual Bitfield makVrv::DtVirtualRealityControllerState::controllerType ( ) const
virtual

Bitfield of controller DeviceType properties.

◆ setControllerType()

virtual void makVrv::DtVirtualRealityControllerState::setControllerType ( Bitfield )
virtual

◆ position()

virtual DtVector makVrv::DtVirtualRealityControllerState::position ( ) const
virtual

Current position of this controller. This is an East-North-Up coordinate system with respect to the observer.

◆ setPosition()

virtual void makVrv::DtVirtualRealityControllerState::setPosition ( const DtVector & pos)
virtual

◆ orientation()

virtual DtQuat makVrv::DtVirtualRealityControllerState::orientation ( ) const
virtual

Current orientation of this controller. This is an East-North-Up coordinate system with respect to the observer.

◆ setOrientation()

virtual void makVrv::DtVirtualRealityControllerState::setOrientation ( const DtQuat & ori)
virtual

◆ buttonStates()

virtual Bitfield makVrv::DtVirtualRealityControllerState::buttonStates ( ) const
virtual

Bitfield of all the button states of the controller. Each bit represents a button state, as 1 << buttonId. See ButtonId enum for known button IDs.

Referenced by setButtonStates().

◆ setButtonStates()

virtual void makVrv::DtVirtualRealityControllerState::setButtonStates ( Bitfield buttonStates)
virtual

References buttonStates().

◆ buttonState()

virtual bool makVrv::DtVirtualRealityControllerState::buttonState ( ButtonId buttonId) const
virtual

Get an individual button state by unique buttonId. true == button down, buttonId must be < number of bits in long long.

◆ setButtonState()

virtual void makVrv::DtVirtualRealityControllerState::setButtonState ( ButtonId buttonId,
bool down )
virtual

◆ touchStates()

virtual Bitfield makVrv::DtVirtualRealityControllerState::touchStates ( ) const
virtual

Bitfield of all the touch surface states of the controller. Each bit represents a surface state, as 1 << touchId. See TouchId enum for known touch surface IDs.

Referenced by setTouchStates().

◆ setTouchStates()

virtual void makVrv::DtVirtualRealityControllerState::setTouchStates ( Bitfield touchStates)
virtual

References touchStates().

◆ touchState()

virtual bool makVrv::DtVirtualRealityControllerState::touchState ( TouchId touchId) const
virtual

Get an individual surface state by unique touchId. true == touched, touchId must be < number of bits in long long.

◆ setTouchState()

virtual void makVrv::DtVirtualRealityControllerState::setTouchState ( TouchId touchId,
bool touched )
virtual

◆ axisPosition()

virtual DtVector2f makVrv::DtVirtualRealityControllerState::axisPosition ( AxisId axisId) const
virtual

Returns the current values of a given axis. All axes are 2-dimensional, though some only use one, usually x. Values will be 0,0 if this controller does not have the given axis. See AxisId enum for known axes; axisId must be < MaxAxes().

◆ setAxisPosition()

virtual void makVrv::DtVirtualRealityControllerState::setAxisPosition ( AxisId axisId,
const DtVector2f & value )
virtual

◆ axisDeadZone()

virtual DtVector2f makVrv::DtVirtualRealityControllerState::axisDeadZone ( AxisId axisId) const
virtual

Returns the dead-zone values of a given axis. Dead-zones are defined independently for x and y axis components. Default dead-zone values are 0.01 for both dimensions. See AxisId enum for known axes; axisId must be < MaxAxes().

◆ setAxisDeadZone()

virtual void makVrv::DtVirtualRealityControllerState::setAxisDeadZone ( AxisId axisId,
const DtVector2f & value )
virtual

◆ setControllerAsLost()

virtual void makVrv::DtVirtualRealityControllerState::setControllerAsLost ( )
virtual

Marks this controller as lost; event type is set to ControllerLost. Is is expected that this controller state will be deleted after the event processor has processed this final state.

◆ controllerWasLost()

virtual bool makVrv::DtVirtualRealityControllerState::controllerWasLost ( ) const
virtual

◆ buttonsChanged()

virtual Bitfield makVrv::DtVirtualRealityControllerState::buttonsChanged ( ) const
virtual

Returns a bitfield identifying all the buttons which have changed since the last event cycle. Each bit represents a button that changed, as 1 << buttonId. See enum ButtonId for known button IDs.

◆ buttonChanged()

virtual bool makVrv::DtVirtualRealityControllerState::buttonChanged ( ButtonId buttonId) const
virtual

Returns whether a particular button with specified ID has changed state since the last event cycle.

◆ buttonPressed()

virtual bool makVrv::DtVirtualRealityControllerState::buttonPressed ( ButtonId buttonId) const
virtual

Returns whether the button with specified ID was pressed/released since the last event cycle.

◆ buttonReleased()

virtual bool makVrv::DtVirtualRealityControllerState::buttonReleased ( ButtonId buttonId) const
virtual

◆ touchChanged() [1/2]

virtual Bitfield makVrv::DtVirtualRealityControllerState::touchChanged ( ) const
virtual

Returns a bitfield identifying all the surfaces which have changed touch state since the last event cycle. Each bit represents a touch surface that changed, as 1 << touchId. See enum TouchId for known button IDs.

◆ touchChanged() [2/2]

virtual bool makVrv::DtVirtualRealityControllerState::touchChanged ( TouchId touchid) const
virtual

Returns whether a particular surface with specified ID has changed touch state since the last event cycle.

◆ touchStarted()

virtual bool makVrv::DtVirtualRealityControllerState::touchStarted ( TouchId touchId) const
virtual

Returns whether the specified touch surface was touched or un-touched since the last event cycle.

◆ touchEnded()

virtual bool makVrv::DtVirtualRealityControllerState::touchEnded ( TouchId touchId) const
virtual

◆ axesChanged()

virtual Bitfield makVrv::DtVirtualRealityControllerState::axesChanged ( ) const
virtual

Returns bitfield identifying all axes which have changed since the last event cycle. Each bit represents an axis, as 1 << axisId. See enum AxisId for known axes.

◆ axisChanged()

virtual bool makVrv::DtVirtualRealityControllerState::axisChanged ( AxisId axisId) const
virtual

Returns whether a particular axis with specified ID has had a value changed since the last event cycle.

◆ controllerMoved()

virtual bool makVrv::DtVirtualRealityControllerState::controllerMoved ( ) const
virtual

Returns whether there has been any change to the tracked position or orientation of this controller since the last event cycle.

◆ controllerEvent()

virtual ControllerEventType makVrv::DtVirtualRealityControllerState::controllerEvent ( ) const
virtual

Returns ControllerEventType describing the state of this controller after the most recent update.

◆ clearEvent()

virtual void makVrv::DtVirtualRealityControllerState::clearEvent ( )
virtual

Resets all change flags to 0/false and event type to NoEvent. This should be called after the event processor has processed the current state of events, before this controller state is updated.

◆ markStateChanged()

virtual void makVrv::DtVirtualRealityControllerState::markStateChanged ( )
inlineprotectedvirtual

Member Data Documentation

◆ NoId

const ControllerId makVrv::DtVirtualRealityControllerState::NoId = ControllerId(-1)
static

Special value indicating no controller ID.

This constant is used to indicate that a controller ID is not set or not applicable in the current context.

◆ myControllerId

ControllerId makVrv::DtVirtualRealityControllerState::myControllerId
protected

◆ myControllerType

Bitfield makVrv::DtVirtualRealityControllerState::myControllerType
protected

◆ myPosition

DtVector makVrv::DtVirtualRealityControllerState::myPosition
protected

◆ myOrientation

DtQuat makVrv::DtVirtualRealityControllerState::myOrientation
protected

◆ myButtonStates

Bitfield makVrv::DtVirtualRealityControllerState::myButtonStates
protected

◆ myTouchStates

Bitfield makVrv::DtVirtualRealityControllerState::myTouchStates
protected

◆ myAxisStates

std::vector<DtVector2f> makVrv::DtVirtualRealityControllerState::myAxisStates
protected

◆ myAxisDeadZones

std::vector<DtVector2f> makVrv::DtVirtualRealityControllerState::myAxisDeadZones
protected

◆ myEventType

ControllerEventType makVrv::DtVirtualRealityControllerState::myEventType
protected

◆ myButtonsChanged

Bitfield makVrv::DtVirtualRealityControllerState::myButtonsChanged
protected

◆ myTouchChanged

Bitfield makVrv::DtVirtualRealityControllerState::myTouchChanged
protected

◆ myAxesChanged

Bitfield makVrv::DtVirtualRealityControllerState::myAxesChanged
protected

◆ myControllerMoved

bool makVrv::DtVirtualRealityControllerState::myControllerMoved
protected

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