Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qopenxrinputmanager_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QOPENXRINPUTMANAGER_H
5#define QOPENXRINPUTMANAGER_H
6
7#include <QObject>
8
9#include <openxr/openxr.h>
10#include <functional>
12
13#include <private/qquick3dmodel_p.h>
14
15//
16// W A R N I N G
17// -------------
18//
19// This file is not part of the Qt API. It exists purely as an
20// implementation detail. This header file may change from version to
21// version without notice, or even be removed.
22//
23// We mean it.
24//
25
27
32
34{
36public:
38
39 void init(XrInstance instance, XrSession session);
40 void teardown();
41
42 enum Hand {
45 };
46
47 void pollActions();
48 void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace);
49 void updateHandtracking(XrTime predictedDisplayTime, XrSpace appSpace, bool aimExtensionEnabled);
50
51 XrSpace handSpace(Hand hand);
52 bool isHandActive(Hand hand);
53
54 XrSpace handTrackerSpace(Hand handtracker);
55 bool isHandTrackerActive(Hand handtracker);
56
57 void setPosePosition(Hand hand, const QVector3D &position);
58 void setPoseRotation(Hand hand, const QQuaternion &rotation);
59
65
66 PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT_;
67 PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT_;
68 PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT_;
69
70 PFN_xrGetHandMeshFB xrGetHandMeshFB_;
71
72 XrHandTrackerEXT handTracker[2] = {XR_NULL_HANDLE, XR_NULL_HANDLE};
73
74 XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT];
75 XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT];
76
77private:
80
81 void setupHandTracking();
82 bool queryHandMesh(Hand hand);
83 void setupActions();
84 void destroyActions();
85 bool checkXrResult(const XrResult &result, const char *debugText = nullptr);
86 void setPath(XrPath &path, const QByteArray &pathString);
87
88 void createAction(XrActionType type,
89 const char *name,
90 const char *localizedName,
91 int numSubactions,
92 XrPath *subactionPath,
93 XrAction &action);
94 void getBoolInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(bool)> setter);
95 void getFloatInputState(XrActionStateGetInfo &getInfo, const XrAction &action, std::function<void(float)> setter);
96
97 XrInstance m_instance{XR_NULL_HANDLE};
98 XrSession m_session{XR_NULL_HANDLE};
99
100 enum SubPathSelector {NoSubPath = 0, LeftHandSubPath = 1, RightHandSubPath = 2, BothHandsSubPath = 3};
101
102 struct QXRHandComponentPath
103 {
104 XrPath paths[2] = {{}, {}};
105 QByteArray componentPathString;
106 };
107 QXRHandComponentPath makeHandInputPaths(const QByteArrayView path);
108 XrPath makeInputPath(const QByteArrayView path);
109
110 struct InputActionInfo {
112 const char *shortName;
113 const char *localizedName;
114 XrActionType type;
115 };
116
117 QList<InputActionInfo> m_handInputActionDefs;
118 QList<InputActionInfo> m_gamepadInputActionDefs;
119
120 struct HandActions {
121 XrAction gripPoseAction{XR_NULL_HANDLE};
122 XrAction aimPoseAction{XR_NULL_HANDLE};
123 XrAction hapticAction{XR_NULL_HANDLE};
124 };
125
126 struct GamepadActions {
127 XrAction hapticLeftAction{XR_NULL_HANDLE};
128 XrAction hapticRightAction{XR_NULL_HANDLE};
129 XrAction hapticLeftTriggerAction{XR_NULL_HANDLE};
130 XrAction hapticRightTriggerAction{XR_NULL_HANDLE};
131 };
132
133 // Input State
134 XrActionSet m_actionSet{XR_NULL_HANDLE};
135 XrPath m_handSubactionPath[2];
136 XrSpace m_handGripSpace[2];
137 XrSpace m_handAimSpace[2];
138
139 QOpenXRHandInput *m_handInputState[2];
140 QOpenXRHandTrackerInput *m_handTrackerInputState[2];
141 QOpenXRGamepadInput *m_gamepadInputState;
142 XrPath m_gamepadSubactionPath;
143 HandActions m_handActions;
144 GamepadActions m_gamepadActions;
145 XrAction m_inputActions[QOpenXRActionMapper::NumActions] = {};
146
147 uint m_aimStateFlags[2] = {};
148 bool m_initialized = false;
149 bool m_disableGamepad = false;
150 bool m_validAimStateFromUpdatePoses[2] = {false, false};
151
152 // Hand Mesh Data
153 struct HandMeshData {
154 QVector<XrVector3f> vertexPositions;
155 QVector<XrVector3f> vertexNormals;
156 QVector<XrVector2f> vertexUVs;
157 QVector<XrVector4sFB> vertexBlendIndices;
158 QVector<XrVector4f> vertexBlendWeights;
159 QVector<int16_t> indices;
160 XrPosef jointBindPoses[XR_HAND_JOINT_COUNT_EXT];
161 XrHandJointEXT jointParents[XR_HAND_JOINT_COUNT_EXT];
162 float jointRadii[XR_HAND_JOINT_COUNT_EXT];
163 } m_handMeshData[2];
164
165
166 struct HandGeometryData {
167 QQuick3DGeometry *geometry = nullptr;
168 } m_handGeometryData[2];
169
170 QQuick3DGeometry *createHandMeshGeometry(const HandMeshData &handMeshData);
171 void createHandModelData(Hand hand);
172 friend class QOpenXrHandModel;
173};
174
176
177#endif // QOPENXRINPUTMANAGER_H
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qobject.h:103
XrHandTrackerEXT handTracker[2]
bool isHandTrackerActive(Hand handtracker)
XrHandJointLocationEXT jointLocations[2][XR_HAND_JOINT_COUNT_EXT]
XrHandJointVelocityEXT jointVelocities[2][XR_HAND_JOINT_COUNT_EXT]
PFN_xrCreateHandTrackerEXT xrCreateHandTrackerEXT_
PFN_xrGetHandMeshFB xrGetHandMeshFB_
PFN_xrDestroyHandTrackerEXT xrDestroyHandTrackerEXT_
QOpenXRHandTrackerInput * leftHandTrackerInput() const
void setPosePosition(Hand hand, const QVector3D &position)
void updatePoses(XrTime predictedDisplayTime, XrSpace appSpace)
static QOpenXRInputManager * instance()
QOpenXRGamepadInput * gamepadInput() const
XrSpace handTrackerSpace(Hand handtracker)
QOpenXRHandInput * leftHandInput() const
void setPoseRotation(Hand hand, const QQuaternion &rotation)
XrSpace handSpace(Hand hand)
QOpenXRHandInput * rightHandInput() const
PFN_xrLocateHandJointsEXT xrLocateHandJointsEXT_
void init(XrInstance instance, XrSession session)
void updateHandtracking(XrTime predictedDisplayTime, XrSpace appSpace, bool aimExtensionEnabled)
QOpenXRHandTrackerInput * rightHandTrackerInput() const
The QQuaternion class represents a quaternion consisting of a vector and scalar.
\qmltype Geometry \inherits Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DGeometry
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
GLenum GLuint id
[7]
GLenum GLsizei const void * pathString
GLenum type
GLsizei const GLuint * paths
GLuint name
GLsizei GLenum const void * indices
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_OBJECT
unsigned int uint
Definition qtypes.h:34