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
qopenxrcontroller.cpp
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
5#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
7#endif
8
9#include "qopenxrview_p.h"
10
12
14{
15#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
16 m_inputManager = QOpenXRInputManager::instance();
17#endif
18}
19
21{
22 return m_controller;
23}
24
26{
27 if (m_controller == newController)
28 return;
29 m_controller = newController;
32
33 disconnect(m_posePositionConnection);
34 disconnect(m_poseRotationConnection);
35 disconnect(m_isActiveConnection);
36 disconnect(m_inputActionConnection);
37
38 auto *input = handInput();
39 if (input) {
40 setPosition(input->posePosition());
41 setRotation(input->poseRotation());
42 setVisible(input->isActive());
43
44 m_posePositionConnection = connect(input, &QOpenXRHandInput::posePositionChanged, this, [this, input]{
45 setPosition(input->posePosition());
46 });
47 m_poseRotationConnection = connect(input, &QOpenXRHandInput::poseRotationChanged, this, [this, input]{
48 setRotation(input->poseRotation());
49 });
50 m_isActiveConnection = connect(input, &QOpenXRHandInput::isActiveChanged, this, [this, input]{
51 setVisible(input->isActive());
52 });
53 m_inputActionConnection = connect(input, &QOpenXRHandInput::inputValueChange,
54 this, [this](int id, const char *shortName, float value) {
55 if (m_actionMapper)
56 m_actionMapper->handleInput(QOpenXRActionMapper::InputAction(id), shortName, value);
57 });
58 } else {
59 setVisible(false);
60 //TODO handle gamepad connections
61 }
62}
63
65{
66#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
67 if (m_controller == ControllerRight)
68 return m_inputManager->rightHandInput();
69 else if (m_controller == ControllerLeft)
70 return m_inputManager->leftHandInput();
71#endif
72 return nullptr;
73}
74
76{
77#if defined(Q_NO_TEMPORARY_DISABLE_XR_API)
78 return m_inputManager->gamepadInput();
79#else
80 return nullptr;
81#endif
82}
83
85{
86 return m_actionMapper;
87}
88
90{
91 if (m_actionMapper == newActionMapper)
92 return;
93
94 if (m_actionMapperConnection) {
95 QObject::disconnect(m_actionMapperConnection);
96 m_actionMapperConnection = {};
97 }
98
99 if (newActionMapper)
100 m_actionMapperConnection = QObject::connect(newActionMapper, &QObject::destroyed, this, [this](QObject *destroyedMapper) {
101 if (m_actionMapper == destroyedMapper) {
102 m_actionMapper = nullptr;
104 }
105 });
106
107 m_actionMapper = newActionMapper;
109}
110
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
Definition qobject.cpp:3236
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void handleInput(InputAction id, const char *shortName, float value)
void setController(QOpenXRController::Controller newController)
Q_INVOKABLE QOpenXRGamepadInput * gamepadInput() const
void setActionMapper(QOpenXRActionMapper *newActionMapper)
QOpenXRHandInput * handInput
void controllerChanged()
void actionMapperChanged()
QOpenXRActionMapper * actionMapper
void isActiveChanged()
void poseRotationChanged()
void inputValueChange(int id, const char *shortName, float value)
void posePositionChanged()
static QOpenXRInputManager * instance()
void setRotation(const QQuaternion &rotation)
void setVisible(bool visible)
Combined button and popup list for selecting options.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
n void setPosition(void) \n\
GLenum GLenum GLenum input
#define emit
myObject disconnect()
[26]