1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSGCAMERA_H
5#define QSSGCAMERA_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#include <QtQuick3D/private/qquick3dnode_p.h>
19
20QT_BEGIN_NAMESPACE
21
22struct QSSGRenderCamera;
23class Q_QUICK3D_EXPORT QQuick3DCamera : public QQuick3DNode
24{
25 Q_OBJECT
26 Q_PROPERTY(bool frustumCullingEnabled READ frustumCullingEnabled WRITE setFrustumCullingEnabled NOTIFY frustumCullingEnabledChanged)
27 Q_PROPERTY(QQuick3DNode *lookAtNode READ lookAtNode WRITE setLookAtNode NOTIFY lookAtNodeChanged REVISION(6, 4))
28 Q_PROPERTY(float levelOfDetailBias READ levelOfDetailBias WRITE setLevelOfDetailBias NOTIFY levelOfDetailBiasChanged REVISION(6, 5))
29 QML_NAMED_ELEMENT(Camera)
30 QML_UNCREATABLE("Camera is Abstract")
31public:
32 Q_INVOKABLE QVector3D mapToViewport(const QVector3D &scenePos) const;
33 Q_INVOKABLE QVector3D mapFromViewport(const QVector3D &viewportPos) const;
34 QVector3D mapToViewport(const QVector3D &scenePos,
35 qreal width,
36 qreal height);
37 QVector3D mapFromViewport(const QVector3D &viewportPos,
38 qreal width,
39 qreal height);
40
41 Q_INVOKABLE void lookAt(const QVector3D &scenePos);
42 Q_INVOKABLE void lookAt(QQuick3DNode *node);
43
44 // It will be used only after the scene was drawn.
45 // It means that the spatialNode of this camera already was created.
46 void updateGlobalVariables(const QRectF &inViewport);
47
48 bool frustumCullingEnabled() const;
49 QQuick3DNode *lookAtNode() const;
50 Q_REVISION(6, 5) float levelOfDetailBias() const;
51
52public Q_SLOTS:
53 void setFrustumCullingEnabled(bool frustumCullingEnabled);
54 void setLookAtNode(QQuick3DNode *node);
55 Q_REVISION(6, 5) void setLevelOfDetailBias(float newLevelOFDetailBias);
56
57Q_SIGNALS:
58 void frustumCullingEnabledChanged();
59 Q_REVISION(6, 4) void lookAtNodeChanged();
60 Q_REVISION(6, 5) void levelOfDetailBiasChanged();
61
62protected:
63 explicit QQuick3DCamera(QQuick3DNodePrivate &dd, QQuick3DNode *parent = nullptr);
64
65 QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) override;
66
67private Q_SLOTS:
68 void updateLookAt();
69
70private:
71 bool m_frustumCullingEnabled = false;
72 QQuick3DNode *m_lookAtNode = nullptr;
73 float m_levelOfDetailBias = 1.0f;
74};
75
76QT_END_NAMESPACE
77
78#endif // QSSGCAMERA_H
79

source code of qtquick3d/src/quick3d/qquick3dcamera_p.h