Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qopenxrinputmanager_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DXINPUTMANAGER_OPENXR_P_H
5#define QQUICK3DXINPUTMANAGER_OPENXR_P_H
6
7#include <QObject>
8
9#include <openxr/openxr.h>
10#include <functional>
12#include <QtQuick3DXr/private/qtquick3dxrglobal_p.h>
13
14#include <private/qquick3dmodel_p.h>
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. It exists purely as an
21// implementation detail. This header file may change from version to
22// version without notice, or even be removed.
23//
24// We mean it.
25//
26
28
29class QQuaternion;
33class QQuick3DXrController;
34
36{
37 Q_OBJECT
38 Q_DECLARE_PUBLIC(QQuick3DXrInputManager)
39public:
42
43 void init(XrInstance instance, XrSession session);
44 void teardown();
45
46 bool isValid() const { return m_initialized; }
47
49
52
53 void pollActions();
54 void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace);
55 void updateHandtracking(XrTime predictedDisplayTime, XrSpace appSpace, bool aimExtensionEnabled);
56
57 XrSpace handSpace(Hand hand, HandPoseSpace poseSpace);
58 bool isHandActive(Hand hand);
59 bool isHandTrackerActive(Hand hand);
60
61 void setPosePositionAndRotation(Hand hand, HandPoseSpace poseSpace, const QVector3D &position, const QQuaternion &rotation);
62
65
67 void registerController(QQuick3DXrController *controller);
68 void unregisterController(QQuick3DXrController *controller);
69
70 bool isPoseInUse(Hand hand, HandPoseSpace poseSpace);
71
72 // NOTE: Static for now...
73 qsizetype getPokeJointIndex() const { return qsizetype(XR_HAND_JOINT_INDEX_TIP_EXT); }
74
78
80
81 XrHandTrackerEXT handTracker[2] = {XR_NULL_HANDLE, XR_NULL_HANDLE};
82
83 XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT];
84 XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT];
85
86private:
87 void setupHandModelInternal(QQuick3DXrHandModel *model, Hand hand);
88
89 void setupHandTracking();
90 bool queryHandMesh(Hand hand);
91 void setupActions();
92 void destroyActions();
93 [[nodiscard]] bool checkXrResult(const XrResult &result);
94 void setPath(XrPath &path, const QByteArray &pathString);
95
96 void createAction(XrActionType type,
97 const char *name,
98 const char *localizedName,
99 int numSubactions,
100 XrPath *subactionPath,
101 XrAction &action);
102 void getBoolInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(bool)> setter);
103 void getFloatInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(float)> setter);
104
105 void setInputValue(Hand hand, int id, const char *shortName, float value);
106
107 QQuick3DXrInputManager *q_ptr = nullptr;
108
109 XrInstance m_instance{XR_NULL_HANDLE};
110 XrSession m_session{XR_NULL_HANDLE};
111
112 enum SubPathSelector {NoSubPath = 0, LeftHandSubPath = 1, RightHandSubPath = 2, BothHandsSubPath = 3};
113
114 struct QXRHandComponentPath
115 {
116 XrPath paths[2] = {{}, {}};
117 QByteArray componentPathString;
118 };
119 QXRHandComponentPath makeHandInputPaths(const QByteArrayView path);
120 XrPath makeInputPath(const QByteArrayView path);
121
122 struct InputActionInfo {
123 QQuick3DXrInputAction::Action id;
124 const char *shortName;
125 const char *localizedName;
126 XrActionType type;
127 };
128
129 QList<InputActionInfo> m_handInputActionDefs;
130
131 struct HandActions {
132 XrAction gripPoseAction{XR_NULL_HANDLE};
133 XrAction aimPoseAction{XR_NULL_HANDLE};
134 XrAction hapticAction{XR_NULL_HANDLE};
135 };
136
137 enum class ActionPaths {
138 leftGripPose, // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
139 leftAimPose, // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
140 leftHaptic, // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
141 rightGripPose, // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
142 rightAimPose, // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
143 rightHaptic // OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
144 };
146
147 enum class InputNames {
148 AClick, // OCULUS_TOUCH (right) | VALVE_INDEX (right + left)
149 BClick, // OCULUS_TOUCH (right) | VALVE_INDEX (right + left)
150 ATouch, // OCULUS_TOUCH (right) | VALVE_INDEX (right + left)
151 BTouch, // OCULUS_TOUCH (right) | VALVE_INDEX (right + left)
152
153 XClick, // OCULUS_TOUCH (left)
154 YClick, // OCULUS_TOUCH (left)
155 XTouch, // OCULUS_TOUCH (left)
156 YTouch, // OCULUS_TOUCH (left)
157
158 MenuClick, // OCULUS_TOUCH (left) | MICROSOFT_MRM (right + left) | HTC_VIVE (right + left)
159 SystemClick, // OCULUS_TOUCH (right) | VALVE_INDEX (right + left) | HTC_VIVE (right + left)
160 SystemTouch, // VALVE_INDEX (right + left)
161
162 SqueezeValue, // right + left: OCULUS_TOUCH | VALVE_INDEX
163 SqueezeForce, // right + left: VALVE_INDEX
164 SqueezeClick, // right + left: MICROSOFT_MRM | HTC_VIVE
165
166 TriggerValue, // right + left: OCULUS_TOUCH | VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
167 TriggerTouch, // right + left: OCULUS_TOUCH | VALVE_INDEX
168 TriggerClick, // right + left: VALVE_INDEX | HTC_VIVE
169
170 ThumbstickX, // OCULUS_TOUCH (right + left) | VALVE_INDEX (right + left) | MICROSOFT_MRM (left)
171 ThumbstickY, // OCULUS_TOUCH (right + left) | VALVE_INDEX (right + left) | MICROSOFT_MRM (left)
172 ThumbstickClick, // OCULUS_TOUCH (right + left) | VALVE_INDEX (right + left) | MICROSOFT_MRM (left)
173 ThumbstickTouch, // OCULUS_TOUCH (right + left) | VALVE_INDEX (right + left)
174 ThumbrestTouch, // OCULUS_TOUCH (right + left)
175
176 TrackpadX, // right + left: VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
177 TrackpadY, // right + left: VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
178 TrackpadForce, // right + left: VALVE_INDEX
179 TrackpadClick, // right + left: VALVE_INDEX | MICROSOFT_MRM | HTC_VIVE
180 TrackpadTouch // right + left: MICROSOFT_MRM | HTC_VIVE
181 };
182 Q_ENUM(InputNames)
183
184 struct InputMapping {
188 };
189
190 struct ControllerBindings {
191 QByteArray profileName;
192 QByteArray profilePath;
193 QList<InputMapping> profileMappingDefs;
194 QList<ActionPaths> supportedActionPaths;
195 };
196
197 // Input State
198 XrActionSet m_actionSet{XR_NULL_HANDLE};
199 XrPath m_handSubactionPath[2] = {XR_NULL_PATH, XR_NULL_PATH};
200 XrSpace m_handGripSpace[2] {XR_NULL_HANDLE, XR_NULL_HANDLE};
201 XrSpace m_handAimSpace[2] {XR_NULL_HANDLE, XR_NULL_HANDLE};
202
203 QQuick3DXrHandInput *m_handInputState[2];
204 HandActions m_handActions;
205 XrAction m_inputActions[QQuick3DXrInputAction::NumActions] = {};
206 QSet<QQuick3DXrController *> m_controllers;
207 bool m_poseInUse[2][2] = {};
208 bool m_poseUsageDirty = true;
209
210 uint m_aimStateFlags[2] = {};
211 bool m_initialized = false;
212 bool m_validAimStateFromUpdatePoses[2] = {false, false};
213
214 void loadBindings(QList<ControllerBindings>* controllerBindingsList);
215 void setUpBindings(QList<ControllerBindings>* controllerBindingsList, QMap<InputNames, QXRHandComponentPath>* handComponentPaths);
216
217 // Hand Mesh Data
218 struct HandMeshData {
219 QVector<XrVector3f> vertexPositions;
220 QVector<XrVector3f> vertexNormals;
221 QVector<XrVector2f> vertexUVs;
222 QVector<XrVector4sFB> vertexBlendIndices;
223 QVector<XrVector4f> vertexBlendWeights;
224 QVector<int16_t> indices;
225 XrPosef jointBindPoses[XR_HAND_JOINT_COUNT_EXT];
226 XrHandJointEXT jointParents[XR_HAND_JOINT_COUNT_EXT];
227 float jointRadii[XR_HAND_JOINT_COUNT_EXT];
228 } m_handMeshData[2];
229
230
231 struct HandGeometryData {
232 QQuick3DGeometry *geometry = nullptr;
233 } m_handGeometryData[2];
234
235 QQuick3DGeometry *createHandMeshGeometry(const HandMeshData &handMeshData);
236 void createHandModelData(Hand hand);
237 friend class QOpenXrHandModel;
238};
239
240QT_END_NAMESPACE
241
242#endif // QQUICK3DXINPUTMANAGER_OPENXR_P_H
void init(XrInstance instance, XrSession session)
XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT]
bool isPoseInUse(Hand hand, HandPoseSpace poseSpace)
void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace)
PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT_
void setPosePositionAndRotation(Hand hand, HandPoseSpace poseSpace, const QVector3D &position, const QQuaternion &rotation)
QQuick3DXrHandInput * rightHandInput() const
static QQuick3DXrInputManagerPrivate * get(QQuick3DXrInputManager *inputManager)
void updateHandtracking(XrTime predictedDisplayTime, XrSpace appSpace, bool aimExtensionEnabled)
QQuick3DXrInputManagerPrivate(QQuick3DXrInputManager &manager)
void setupHandModel(QQuick3DXrHandModel *model)
void registerController(QQuick3DXrController *controller)
PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT_
QQuick3DXrHandInput * leftHandInput() const
XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT]
void unregisterController(QQuick3DXrController *controller)
XrSpace handSpace(Hand hand, HandPoseSpace poseSpace)
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT_
void registerController(QQuick3DXrController *controller)
void unregisterController(QQuick3DXrController *controller)
QQuick3DXrHandInput * leftHandInput() const
QQuick3DXrHandInput * rightHandInput() const
static QQuick3DXrInputManager * instance()
Combined button and popup list for selecting options.
static QMatrix4x4 transformMatrix(const QVector3D &position, const QQuaternion &rotation)