Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
XrInputHandler.h
1#pragma once
2
3#include <Engine/Core/OpenXrHelper.h>
4#include <Engine/Input/XrProfile.h>
5#include <Engine/Renderer/Headset.h>
6#include <glm/glm.hpp>
7#include <openxr/openxr.h>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
27
28namespace Engine
29{
30 class EngineKern;
31} // namespace Engine
32
33namespace Input
34{
38 enum class Hand
39 {
40 LEFT = 0,
41 RIGHT = 1
42 };
43
53 {
54 glm::mat4 matrix{};
56
57 XrPath handPath{};
58 XrSpace space = XR_NULL_HANDLE;
59 };
60
77 {
78 public:
80
85
92
96 void rebind();
97
102
108
114
120 [[nodiscard]] HandPoseInfo getHandPoseInfo( Hand hand ) const;
121
126 [[nodiscard]] glm::vec2 getRightThumbstick() const
127 {
128 return getVec2( "thumbstick", Hand::RIGHT );
129 }
130
135 [[nodiscard]] glm::vec2 getLeftThumbstick() const
136 {
137 return getVec2( "thumbstick", Hand::LEFT );
138 }
139
145 [[nodiscard]] float getTriggerValue( Hand hand ) const
146 {
147 return getFloat( "trigger_value", hand );
148 }
149
155 [[nodiscard]] float getGripValue( Hand hand ) const
156 {
157 return getFloat( "grip_value", hand );
158 }
159
163 [[nodiscard]] bool getAButtonPressed() const
164 {
165 return getBool( "a_button", Hand::RIGHT );
166 }
167
171 [[nodiscard]] bool getBButtonPressed() const
172 {
173 return getBool( "b_button", Hand::RIGHT );
174 }
175
179 [[nodiscard]] bool getXButtonPressed() const
180 {
181 return getBool( "x_button", Hand::LEFT );
182 }
183
187 [[nodiscard]] bool getYButtonPressed() const
188 {
189 return getBool( "y_button", Hand::LEFT );
190 }
191
199 [[nodiscard]] bool getBool( const std::string & suffix, Hand hand ) const;
200
208 [[nodiscard]] float getFloat( const std::string & suffix, Hand hand ) const;
209
217 [[nodiscard]] glm::vec2 getVec2( const std::string & suffix, Hand hand ) const;
218
225 void triggerHaptic( Hand hand, float amplitude, float durationSeconds );
226
228 std::vector<HandPoseInfo> handPoseInfos;
229
230 private:
235 {
236 bool active = false;
237 bool boolValue = false;
238 float floatValue = 0.0f;
239 glm::vec2 vec2Value = glm::vec2( 0.0f );
240 XrSpace space = XR_NULL_HANDLE;
241 glm::mat4 matrix = glm::mat4( 1.0f );
243 };
244
249 {
250 std::string name;
251 std::string suffix;
252 XrAction handle = XR_NULL_HANDLE;
254 std::vector<XrPath> subactionPaths;
255 std::vector<XrPath> bindingPaths;
256 std::vector<XrActionCache> cache;
257 };
258
263
272
277
282
287
292
300 const XrActionInfo * findAction( const std::string & suffix, Hand hand, size_t & cacheIndex ) const;
301
302 XrActionSet defaultActionSet = XR_NULL_HANDLE;
303 std::vector<XrPath> handPaths;
304
305 std::unordered_map<std::string, XrActionInfo> actions_;
306 std::vector<const XrProfileDef *> activeProfiles_;
307
308 bool actionsCreated_ = false;
309 bool actionSetAttached_ = false;
310
314 };
315} // namespace Input
The application context is the core class which stores the basic openxr and vulkan objects.
Owns the engine runtime and provides access to engine subsystems.
Definition Engine.h:67
Owns the OpenXR session, XR swapchain, eye transforms, and per-frame XR submission state.
Definition Headset.h:55
XrActionSet defaultActionSet
The single action set owned by the handler.
bool getXButtonPressed() const
Returns whether the left controller X 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.
std::unordered_map< std::string, XrActionInfo > actions_
Created actions keyed by full action name.
void triggerHaptic(Hand hand, float amplitude, float durationSeconds)
Triggers a short vibration pulse on a hand's haptic output.
void syncInputs()
Samples all created OpenXR actions and updates cached poses, axes, analog values, and button states.
void rebind()
Re-detects the active interaction profile after the runtime reports a profile change.
HandPoseInfo getHandPoseInfo(Hand hand) const
Returns the latest raw pose snapshot for the specified hand.
void createPoseSpaces()
Creates action spaces for pose inputs of the created actions.
Engine::EngineKern * engine
Owning engine module.
bool getYButtonPressed() const
Returns whether the left controller Y button is currently pressed.
float getFloat(const std::string &suffix, Hand hand) const
Returns the latest float value for a profile component for a hand.
float getTriggerValue(Hand hand) const
Returns the latest trigger analog value for a hand.
void suggestAllBindings()
Suggests interaction profile bindings for every known profile.
float getGripValue(Hand hand) const
Returns the latest grip or squeeze analog value for a hand.
const XrActionInfo * findAction(const std::string &suffix, Hand hand, size_t &cacheIndex) const
Finds the action for a component suffix and hand.
std::vector< XrPath > handPaths
User hand paths for /user/hand/left and /user/hand/right.
void createActions()
Creates the action set and all actions from the profile registry.
glm::vec2 getRightThumbstick() const
Returns the latest right thumbstick axis value.
const Engine::Rendering::Headset * headset_
Headset that owns the session.
bool getAButtonPressed() const
Returns whether the right controller A button is currently pressed.
XrSpace getLeftHandSpace()
Returns the left hand aim-pose action space.
void detectActiveProfiles()
Queries the runtime for the currently active interaction profiles.
bool actionSetAttached_
True once the action set was attached to the session.
void attachActionSet()
Attaches the action set to the current session.
glm::vec2 getLeftThumbstick() const
Returns the latest left thumbstick axis value.
glm::vec2 getVec2(const std::string &suffix, Hand hand) const
Returns the latest vector2 value for a profile component for a hand.
bool actionsCreated_
True once createActions() succeeded.
std::vector< const XrProfileDef * > activeProfiles_
Profiles reported active by the runtime.
void bindForSession()
Creates actions, suggests profile bindings, attaches the action set, and detects the active profile.
~XrInputHandler()
Destroys the OpenXR action set.
bool getBButtonPressed() const
Returns whether the right controller B button is currently pressed.
std::vector< HandPoseInfo > handPoseInfos
Raw pose snapshots for left and right hands. Prefer getHandPoseInfo() for indexed access.
void updateAimPoseSpaces()
Points handPoseInfos at the active profile's aim pose action spaces.
const Engine::Core::ApplicationContext * context_
Application context that owns the OpenXR instance.
XrSpace getRightHandSpace()
Returns the right hand aim-pose action space.
XrInputType
OpenXR action type for an interaction-profile input component.
Definition XrProfile.h:23
@ Boolean
XR_ACTION_TYPE_BOOLEAN_INPUT.
Definition XrProfile.h:24
Hand
Index of a tracked hand in hand-indexed input arrays.
@ RIGHT
Right hand, stored at index 1.
@ LEFT
Left hand, stored at index 0.
A glm based posef struct.
Raw pose data for one tracked OpenXR hand.
glm::mat4 matrix
Pose matrix located relative to the last synced player space.
XrSpace space
Action space created for this hand's aim pose action.
Engine::OpenXrHelper::posef handPose
Position and orientation located relative to the last synced player space.
XrPath handPath
OpenXR user hand path for this pose, such as /user/hand/left.
Cached sampled state for one subaction path of an action.
XrSpace space
Action space for pose inputs.
Engine::OpenXrHelper::posef pose
Cached pose for pose inputs.
bool active
Whether the runtime reports the action active.
glm::vec2 vec2Value
Cached vector2 input value.
float floatValue
Cached float input value.
bool boolValue
Cached boolean input value.
glm::mat4 matrix
Cached pose matrix for pose inputs.
Runtime state for one created OpenXR action.
XrInputType type
OpenXR action type.
std::string name
Full action name, <slug>_<suffix>.
std::string suffix
Component suffix, e.g. "trigger_value".
XrAction handle
OpenXR action handle.
std::vector< XrActionCache > cache
Sampled state per subaction path.
std::vector< XrPath > bindingPaths
Full input paths used for suggested bindings.
std::vector< XrPath > subactionPaths
User subaction paths (empty for head/gamepad).