| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICK3DXRCAMERA_P_H |
| 5 | #define QQUICK3DXRCAMERA_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | |
| 19 | #include <QtQuick3DXr/qtquick3dxrglobal.h> |
| 20 | |
| 21 | #include <QObject> |
| 22 | #include <QtQuick3D/private/qquick3dcamera_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuick3DXrOrigin; |
| 27 | |
| 28 | class Q_QUICK3DXR_EXPORT QQuick3DXrEyeCamera : public QQuick3DCamera |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | Q_PROPERTY(float leftTangent READ leftTangent WRITE setLeftTangent NOTIFY leftTangentChanged) |
| 32 | Q_PROPERTY(float rightTangent READ rightTangent WRITE setRightTangent NOTIFY rightTangentChanged) |
| 33 | Q_PROPERTY(float upTangent READ upTangent WRITE setUpTangent NOTIFY upTangentChanged) |
| 34 | Q_PROPERTY(float downTangent READ downTangent WRITE setDownTangent NOTIFY downTangentChanged) |
| 35 | Q_PROPERTY(float clipNear READ clipNear WRITE setClipNear NOTIFY clipNearChanged) |
| 36 | Q_PROPERTY(float clipFar READ clipFar WRITE setClipFar NOTIFY clipFarChanged) |
| 37 | |
| 38 | public: |
| 39 | explicit QQuick3DXrEyeCamera(QQuick3DXrOrigin *parent = nullptr); |
| 40 | |
| 41 | float leftTangent() const; |
| 42 | float rightTangent() const; |
| 43 | float upTangent() const; |
| 44 | float downTangent() const; |
| 45 | float clipNear() const; |
| 46 | float clipFar() const; |
| 47 | |
| 48 | public Q_SLOTS: |
| 49 | void setLeftTangent(float leftTangent); |
| 50 | void setRightTangent(float rightTangent); |
| 51 | void setUpTangent(float upTangent); |
| 52 | void setDownTangent(float downTangent); |
| 53 | void setClipNear(float clipNear); |
| 54 | void setClipFar(float clipFar); |
| 55 | void setProjection(const QMatrix4x4 &projection); |
| 56 | |
| 57 | Q_SIGNALS: |
| 58 | void leftTangentChanged(float leftTangent); |
| 59 | void rightTangentChanged(float rightTangent); |
| 60 | void upTangentChanged(float upTangent); |
| 61 | void downTangentChanged(float downTangent); |
| 62 | void clipNearChanged(float clipNear); |
| 63 | void clipFarChanged(float clipFar); |
| 64 | |
| 65 | public: |
| 66 | QMatrix4x4 m_projection; |
| 67 | |
| 68 | protected: |
| 69 | QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override; |
| 70 | |
| 71 | private: |
| 72 | enum DirtyFlag : quint8 |
| 73 | { |
| 74 | ProjectionDirty = 0x1, // Camera projection matrix needs to be recalculated |
| 75 | ProjectionChanged = 0x2, // A camera projection matrix has changed (no recalculation needed) |
| 76 | ClipChanged = 0x4, // Camera clip planes have changed |
| 77 | }; |
| 78 | using DirtyFlagT = std::underlying_type_t<DirtyFlag>; |
| 79 | |
| 80 | void markDirty(DirtyFlag flag); |
| 81 | void maybeUpdateProjection(); |
| 82 | float m_leftTangent = -0.017455064928218f; // tan(-1) |
| 83 | float m_rightTangent = 0.017455064928218f; // tan(1) |
| 84 | float m_upTangent = 0.017455064928218f; // tan(1) |
| 85 | float m_downTangent = -0.017455064928218f; // tan(-1) |
| 86 | float m_clipNear = 1.0f; |
| 87 | float m_clipFar = 10000.0f; |
| 88 | DirtyFlagT m_dirtyFlags = 0; |
| 89 | }; |
| 90 | |
| 91 | class Q_QUICK3DXR_EXPORT QQuick3DXrCamera : public QQuick3DNode |
| 92 | { |
| 93 | Q_OBJECT |
| 94 | Q_PROPERTY(float clipNear READ clipNear WRITE setClipNear NOTIFY clipNearChanged FINAL) |
| 95 | Q_PROPERTY(float clipFar READ clipFar WRITE setClipFar NOTIFY clipFarChanged FINAL) |
| 96 | QML_NAMED_ELEMENT(XrCamera) |
| 97 | QML_ADDED_IN_VERSION(6, 8) |
| 98 | |
| 99 | public: |
| 100 | explicit QQuick3DXrCamera(QQuick3DXrOrigin *parent = nullptr); |
| 101 | ~QQuick3DXrCamera(); |
| 102 | float clipNear() const; |
| 103 | float clipFar() const; |
| 104 | |
| 105 | public Q_SLOTS: |
| 106 | void setClipNear(float clipNear); |
| 107 | void setClipFar(float clipFar); |
| 108 | |
| 109 | Q_SIGNALS: |
| 110 | void clipNearChanged(float clipNear); |
| 111 | void clipFarChanged(float clipFar); |
| 112 | |
| 113 | protected: |
| 114 | void itemChange(ItemChange change, const ItemChangeData &data) override; |
| 115 | |
| 116 | private: |
| 117 | void syncCameraSettings(); |
| 118 | |
| 119 | float m_clipNear = 1.0f; |
| 120 | float m_clipFar = 10000.0f; |
| 121 | }; |
| 122 | |
| 123 | |
| 124 | QT_END_NAMESPACE |
| 125 | |
| 126 | #endif // QQUICK3DXRCAMERA_P_H |
| 127 | |