Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
Input::XrInputHandler Class Reference

Creates OpenXR controller actions from the profile registry and samples the input state. More...

#include <XrInputHandler.h>

Collaboration diagram for Input::XrInputHandler:

Classes

struct  XrActionCache
 Cached sampled state for one subaction path of an action. More...
struct  XrActionInfo
 Runtime state for one created OpenXR action. More...

Public Member Functions

 XrInputHandler ()
 ~XrInputHandler ()
 Destroys the OpenXR action set.
void bindForSession ()
 Creates actions, suggests profile bindings, attaches the action set, and detects the active profile.
void rebind ()
 Re-detects the active interaction profile after the runtime reports a profile change.
void syncInputs ()
 Samples all created OpenXR actions and updates cached poses, axes, analog values, and button states.
XrSpace getLeftHandSpace ()
 Returns the left hand aim-pose action space.
XrSpace getRightHandSpace ()
 Returns the right hand aim-pose action space.
HandPoseInfo getHandPoseInfo (Hand hand) const
 Returns the latest raw pose snapshot for the specified hand.
glm::vec2 getRightThumbstick () const
 Returns the latest right thumbstick axis value.
glm::vec2 getLeftThumbstick () const
 Returns the latest left thumbstick axis value.
float getTriggerValue (Hand hand) const
 Returns the latest trigger analog value for a hand.
float getGripValue (Hand hand) const
 Returns the latest grip or squeeze analog value for a hand.
bool getAButtonPressed () const
 Returns whether the right controller A button is currently pressed.
bool getBButtonPressed () const
 Returns whether the right controller B button is currently pressed.
bool getXButtonPressed () const
 Returns whether the left controller X button is currently pressed.
bool getYButtonPressed () const
 Returns whether the left controller Y button is currently pressed.
bool getBool (const std::string &suffix, Hand hand) const
 Returns the latest boolean value for a profile component for a hand.
float getFloat (const std::string &suffix, Hand hand) const
 Returns the latest float value for a profile component for a hand.
glm::vec2 getVec2 (const std::string &suffix, Hand hand) const
 Returns the latest vector2 value for a profile component for a hand.
void triggerHaptic (Hand hand, float amplitude, float durationSeconds)
 Triggers a short vibration pulse on a hand's haptic output.

Public Attributes

std::vector< HandPoseInfo > handPoseInfos
 Raw pose snapshots for left and right hands. Prefer getHandPoseInfo() for indexed access.

Private Member Functions

void createActions ()
 Creates the action set and all actions from the profile registry.
void suggestAllBindings ()
 Suggests interaction profile bindings for every known profile.
void attachActionSet ()
 Attaches the action set to the current session.
void createPoseSpaces ()
 Creates action spaces for pose inputs of the created actions.
void detectActiveProfiles ()
 Queries the runtime for the currently active interaction profiles.
void updateAimPoseSpaces ()
 Points handPoseInfos at the active profile's aim pose action spaces.
const XrActionInfo * findAction (const std::string &suffix, Hand hand, size_t &cacheIndex) const
 Finds the action for a component suffix and hand.

Private Attributes

XrActionSet defaultActionSet = XR_NULL_HANDLE
 The single action set owned by the handler.
std::vector< XrPath > handPaths
 User hand paths for /user/hand/left and /user/hand/right.
std::unordered_map< std::string, XrActionInfo > actions_
 Created actions keyed by full action name.
std::vector< const XrProfileDef * > activeProfiles_
 Profiles reported active by the runtime.
bool actionsCreated_ = false
 True once createActions() succeeded.
bool actionSetAttached_ = false
 True once the action set was attached to the session.
Engine::EngineKern * engine = nullptr
 Owning engine module.
const Engine::Rendering::Headset * headset_ = nullptr
 Headset that owns the session.
const Engine::Core::ApplicationContext * context_ = nullptr
 Application context that owns the OpenXR instance.

Detailed Description

Creates OpenXR controller actions from the profile registry and samples the input state.

The handler owns a single action set attached to the headset session. Bindings are suggested when the session becomes ready (bindForSession()) and re-resolved when the runtime reports an interaction profile change (rebind()). Call syncInputs() once per frame before reading values. Poses are raw OpenXR poses in the supplied player space; XrRig converts them to engine world-space poses.

This is the OpenXR implementation for the OpenXR-SDK release-1.0.28 (see code/Engine/CMakeLists.txt). The engine stays strictly on OpenXR 1.0 and requests XR_CURRENT_API_VERSION (= XR_API_VERSION_1_0), so runtimes that only certify OpenXR 1.0 (e.g. SteamVR and Monado) remain supported. Interaction profiles that are only "provided by XR_VERSION_1_1" are therefore not reported by such runtimes for a 1.0 application.

Definition at line 76 of file XrInputHandler.h.

Constructor & Destructor Documentation

◆ XrInputHandler()

Input::XrInputHandler::XrInputHandler ( )

◆ ~XrInputHandler()

Input::XrInputHandler::~XrInputHandler ( )

Destroys the OpenXR action set.

Member Function Documentation

◆ attachActionSet()

void Input::XrInputHandler::attachActionSet ( )
private

Attaches the action set to the current session.

◆ bindForSession()

void Input::XrInputHandler::bindForSession ( )

Creates actions, suggests profile bindings, attaches the action set, and detects the active profile.

Call when the XR session reaches the ready state. Safe to call multiple times.

◆ createActions()

void Input::XrInputHandler::createActions ( )
private

Creates the action set and all actions from the profile registry.

◆ createPoseSpaces()

void Input::XrInputHandler::createPoseSpaces ( )
private

Creates action spaces for pose inputs of the created actions.

◆ detectActiveProfiles()

void Input::XrInputHandler::detectActiveProfiles ( )
private

Queries the runtime for the currently active interaction profiles.

◆ findAction()

const XrActionInfo * Input::XrInputHandler::findAction ( const std::string & suffix,
Hand hand,
size_t & cacheIndex ) const
private

Finds the action for a component suffix and hand.

Parameters
suffixComponent suffix to match.
handHand to match against the action's subaction paths.
[out]cacheIndexReceives the cache index for the matched hand.
Returns
The action info for the active profile, or nullptr when none is bound.

◆ getAButtonPressed()

bool Input::XrInputHandler::getAButtonPressed ( ) const
inlinenodiscard

Returns whether the right controller A button is currently pressed.

Definition at line 163 of file XrInputHandler.h.

References getBool(), and Input::RIGHT.

Here is the call graph for this function:

◆ getBButtonPressed()

bool Input::XrInputHandler::getBButtonPressed ( ) const
inlinenodiscard

Returns whether the right controller B button is currently pressed.

Definition at line 171 of file XrInputHandler.h.

References getBool(), and Input::RIGHT.

Here is the call graph for this function:

◆ getBool()

bool Input::XrInputHandler::getBool ( const std::string & suffix,
Hand hand ) const
nodiscard

Returns the latest boolean value for a profile component for a hand.

Parameters
suffixComponent name suffix, e.g. "menu", "a_button", "select".
handHand to query.
Returns
Value of the active profile's component, or false when no component is bound.

Referenced by getAButtonPressed(), getBButtonPressed(), getXButtonPressed(), and getYButtonPressed().

Here is the caller graph for this function:

◆ getFloat()

float Input::XrInputHandler::getFloat ( const std::string & suffix,
Hand hand ) const
nodiscard

Returns the latest float value for a profile component for a hand.

Parameters
suffixComponent name suffix, e.g. "trigger_value", "grip_value".
handHand to query.
Returns
Value of the active profile's component, or 0.0f when no component is bound.

Referenced by getGripValue(), and getTriggerValue().

Here is the caller graph for this function:

◆ getGripValue()

float Input::XrInputHandler::getGripValue ( Hand hand) const
inlinenodiscard

Returns the latest grip or squeeze analog value for a hand.

Parameters
handHand to query.
Returns
Grip value in the range [0.0, 1.0].

Definition at line 155 of file XrInputHandler.h.

References getFloat().

Here is the call graph for this function:

◆ getHandPoseInfo()

HandPoseInfo Input::XrInputHandler::getHandPoseInfo ( Hand hand) const
nodiscard

Returns the latest raw pose snapshot for the specified hand.

Parameters
handHand to query.
Returns
Current pose, hand path, and action space for the hand.

◆ getLeftHandSpace()

XrSpace Input::XrInputHandler::getLeftHandSpace ( )

Returns the left hand aim-pose action space.

Returns
OpenXR space for the left hand, or XR_NULL_HANDLE before the active profile is known.

◆ getLeftThumbstick()

glm::vec2 Input::XrInputHandler::getLeftThumbstick ( ) const
inlinenodiscard

Returns the latest left thumbstick axis value.

Returns
glm::vec2 where x is left/right and y is forward/back.

Definition at line 135 of file XrInputHandler.h.

References getVec2(), and Input::LEFT.

Here is the call graph for this function:

◆ getRightHandSpace()

XrSpace Input::XrInputHandler::getRightHandSpace ( )

Returns the right hand aim-pose action space.

Returns
OpenXR space for the right hand, or XR_NULL_HANDLE before the active profile is known.

◆ getRightThumbstick()

glm::vec2 Input::XrInputHandler::getRightThumbstick ( ) const
inlinenodiscard

Returns the latest right thumbstick axis value.

Returns
glm::vec2 where x is left/right and y is forward/back.

Definition at line 126 of file XrInputHandler.h.

References getVec2(), and Input::RIGHT.

Here is the call graph for this function:

◆ getTriggerValue()

float Input::XrInputHandler::getTriggerValue ( Hand hand) const
inlinenodiscard

Returns the latest trigger analog value for a hand.

Parameters
handHand to query.
Returns
Trigger value in the range [0.0, 1.0].

Definition at line 145 of file XrInputHandler.h.

References getFloat().

Here is the call graph for this function:

◆ getVec2()

glm::vec2 Input::XrInputHandler::getVec2 ( const std::string & suffix,
Hand hand ) const
nodiscard

Returns the latest vector2 value for a profile component for a hand.

Parameters
suffixComponent name suffix, e.g. "thumbstick", "trackpad".
handHand to query.
Returns
Value of the active profile's component, or zero when no component is bound.

Referenced by getLeftThumbstick(), and getRightThumbstick().

Here is the caller graph for this function:

◆ getXButtonPressed()

bool Input::XrInputHandler::getXButtonPressed ( ) const
inlinenodiscard

Returns whether the left controller X button is currently pressed.

Definition at line 179 of file XrInputHandler.h.

References getBool(), and Input::LEFT.

Here is the call graph for this function:

◆ getYButtonPressed()

bool Input::XrInputHandler::getYButtonPressed ( ) const
inlinenodiscard

Returns whether the left controller Y button is currently pressed.

Definition at line 187 of file XrInputHandler.h.

References getBool(), and Input::LEFT.

Here is the call graph for this function:

◆ rebind()

void Input::XrInputHandler::rebind ( )

Re-detects the active interaction profile after the runtime reports a profile change.

◆ suggestAllBindings()

void Input::XrInputHandler::suggestAllBindings ( )
private

Suggests interaction profile bindings for every known profile.

The runtime only reports a profile it has suggested bindings for, so all profiles are suggested; profiles the runtime does not know return XR_ERROR_PATH_UNSUPPORTED and are logged but ignored.

◆ syncInputs()

void Input::XrInputHandler::syncInputs ( )

Samples all created OpenXR actions and updates cached poses, axes, analog values, and button states.

◆ triggerHaptic()

void Input::XrInputHandler::triggerHaptic ( Hand hand,
float amplitude,
float durationSeconds )

Triggers a short vibration pulse on a hand's haptic output.

Parameters
handHand to vibrate.
amplitudeVibration amplitude in the range [0.0, 1.0].
durationSecondsDuration of the pulse in seconds.

◆ updateAimPoseSpaces()

void Input::XrInputHandler::updateAimPoseSpaces ( )
private

Points handPoseInfos at the active profile's aim pose action spaces.

Member Data Documentation

◆ actions_

std::unordered_map<std::string, XrActionInfo> Input::XrInputHandler::actions_
private

Created actions keyed by full action name.

Definition at line 305 of file XrInputHandler.h.

◆ actionsCreated_

bool Input::XrInputHandler::actionsCreated_ = false
private

True once createActions() succeeded.

Definition at line 308 of file XrInputHandler.h.

◆ actionSetAttached_

bool Input::XrInputHandler::actionSetAttached_ = false
private

True once the action set was attached to the session.

Definition at line 309 of file XrInputHandler.h.

◆ activeProfiles_

std::vector<const XrProfileDef *> Input::XrInputHandler::activeProfiles_
private

Profiles reported active by the runtime.

Definition at line 306 of file XrInputHandler.h.

◆ context_

const Engine::Core::ApplicationContext* Input::XrInputHandler::context_ = nullptr
private

Application context that owns the OpenXR instance.

Definition at line 313 of file XrInputHandler.h.

◆ defaultActionSet

XrActionSet Input::XrInputHandler::defaultActionSet = XR_NULL_HANDLE
private

The single action set owned by the handler.

Definition at line 302 of file XrInputHandler.h.

◆ engine

Engine::EngineKern* Input::XrInputHandler::engine = nullptr
private

Owning engine module.

Definition at line 311 of file XrInputHandler.h.

◆ handPaths

std::vector<XrPath> Input::XrInputHandler::handPaths
private

User hand paths for /user/hand/left and /user/hand/right.

Definition at line 303 of file XrInputHandler.h.

◆ handPoseInfos

std::vector<HandPoseInfo> Input::XrInputHandler::handPoseInfos

Raw pose snapshots for left and right hands. Prefer getHandPoseInfo() for indexed access.

Definition at line 228 of file XrInputHandler.h.

◆ headset_

const Engine::Rendering::Headset* Input::XrInputHandler::headset_ = nullptr
private

Headset that owns the session.

Definition at line 312 of file XrInputHandler.h.


The documentation for this class was generated from the following file:
  • /workspace/magerbeton/gl3-vulkan/code/Engine/include/Engine/Input/XrInputHandler.h