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
qopenxrhandtrackerinput.cpp
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
5
6#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
7#include "qopenxrhelpers_p.h"
9#endif
10
12
18
20{
21 return m_isActive;
22}
23
28
30{
31 if (m_isActive == isActive)
32 return;
33
34 m_isActive = isActive;
36}
37
39{
40 if (poseSpace == m_poseSpace)
41 return;
42
43 m_poseSpace = poseSpace;
45}
46
48{
49 return m_posePosition;
50}
51
53{
54 return m_poseRotation;
55}
56
58{
59 return m_jointPositions;
60}
61
62void QOpenXRHandTrackerInput::setJointPositionsAndRotations(const QList<QVector3D> &newJointPositions, const QList<QQuaternion> &newJointRotations)
63{
64 m_jointPositions = newJointPositions;
66 m_jointRotations = newJointRotations;
69#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
70 setPokePosition(m_jointPositions[XR_HAND_JOINT_INDEX_TIP_EXT]);
71#endif
72}
73
75{
76 return m_jointRotations;
77}
78
80{
81 return m_pokePosition;
82}
83
85{
86 if (m_pokePosition == newPokePosition)
87 return;
88 m_pokePosition = newPokePosition;
90}
91
92#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
93static inline QMatrix4x4 transformMatrix(const QVector3D &position, const QQuaternion &rotation)
94{
95 QMatrix4x4 transform = QMatrix4x4{rotation.toRotationMatrix()};
96
97 transform(0, 3) += position[0];
98 transform(1, 3) += position[1];
99 transform(2, 3) += position[2];
100
101 return transform;
102}
103#endif
104
110
111void QOpenXrHandModel::updatePose()
112{
113 auto *skin = QQuick3DModel::skin();
114 auto jointListProp = skin->joints();
115 int count = jointListProp.count(&jointListProp);
116 const auto positions = m_handTracker->jointPositions();
117 const auto rotations = m_handTracker->jointRotations();
118 for (int i = 0; i < count; ++i) {
119 auto *joint = jointListProp.at(&jointListProp, i);
120 joint->setPosition(positions.at(i));
121 joint->setRotation(rotations.at(i));
122 }
123}
124
125void QOpenXrHandModel::setupModel()
126{
127 if (!m_handTracker) {
128 return;
129 }
130 if (m_initialized) {
131 qWarning() << "XrHandModel does not support changing hand tracker";
132 return;
133 }
134#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
136 auto *inputMan = QOpenXRInputManager::instance();
137 QOpenXRInputManager::Hand hand = m_handTracker == inputMan->leftHandTrackerInput()
139 const auto &handGeometryData = inputMan->m_handGeometryData[hand];
140 const auto &handMeshData = inputMan->m_handMeshData[hand];
141
142 Q_ASSERT(handGeometryData.geometry);
143
144 setGeometry(handGeometryData.geometry);
145
146 //TODO: support changing hands
147
148 auto *skin = new QQuick3DSkin(this);
149 auto jointListProp = skin->joints();
150 QList<QMatrix4x4> inverseBindPoses;
151 inverseBindPoses.reserve(XR_HAND_JOINT_COUNT_EXT);
152
153 for (int i = 0; i < XR_HAND_JOINT_COUNT_EXT; ++i) {
154 const auto &pose = handMeshData.jointBindPoses[i];
155 const QVector3D pos = OpenXRHelpers::toQVector(pose.position);
156 const QQuaternion rot = OpenXRHelpers::toQQuaternion(pose.orientation);
157 inverseBindPoses.append(transformMatrix(pos, rot).inverted());
158 auto *joint = new QQuick3DNode(this);
159 joint->setPosition(pos);
160 joint->setRotation(rot);
161 jointListProp.append(&jointListProp, joint);
162 }
164 setSkin(skin);
165
166 connect(m_handTracker, &QOpenXRHandTrackerInput::jointDataUpdated, this, &QOpenXrHandModel::updatePose);
167 connect(m_handTracker, &QOpenXRHandTrackerInput::isActiveChanged, this, [this](){
168 setVisible(m_handTracker->isActive());
169 });
170 setVisible(m_handTracker->isActive());
171 m_initialized = true;
172#endif
173}
174
180
182{
183 return m_handTracker;
184}
185
187{
188 if (m_handTracker == newHandTracker)
189 return;
190 m_handTracker = newHandTracker;
191 //TODO: setupModel()
193}
194
bool isActive
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
void reserve(qsizetype size)
Definition qlist.h:753
void append(parameter_type t)
Definition qlist.h:458
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore
Definition qobject.h:103
QList< QQuaternion > jointRotations
void setPokePosition(const QVector3D &newPokePosition)
void setPoseSpace(HandPoseSpace poseSpace)
QOpenXRHandTrackerInput(QObject *parent=nullptr)
const QQuaternion & poseRotation() const
void setJointPositionsAndRotations(const QList< QVector3D > &newJointPositions, const QList< QQuaternion > &newJointRotations)
static QOpenXRInputManager * instance()
void handTrackerChanged()
QOpenXrHandModel(QQuick3DNode *parent=nullptr)
QOpenXRHandTrackerInput * handTracker
void setHandTracker(QOpenXRHandTrackerInput *newHandTracker)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
QQuick3DSkin * skin
\qmlproperty Skin Model::skin
void setGeometry(QQuick3DGeometry *geometry)
QList< QMatrix4x4 > inverseBindPoses
void setVisible(bool visible)
QQuick3DNode(QQuick3DNode *parent=nullptr)
\qmltype Node \inherits Object3D \inqmlmodule QtQuick3D
void setInverseBindPoses(const QList< QMatrix4x4 > &poses)
QQmlListProperty< QQuick3DNode > joints
\qmlproperty List<QtQuick3D::Node> Skin::joints
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
QQuaternion toQQuaternion(const XrQuaternionf &q)
QVector3D toQVector(const XrVector3f &v)
Combined button and popup list for selecting options.
static const QCssKnownValue positions[NumKnownPositionModes - 1]
#define qWarning
Definition qlogging.h:166
GLenum GLenum GLsizei count
GLuint GLenum GLenum transform
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define emit
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)