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