1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QT3DRENDER_CAMERALENS_H
41#define QT3DRENDER_CAMERALENS_H
42
43#include <Qt3DCore/qcomponent.h>
44#include <Qt3DRender/qt3drender_global.h>
45
46#include <QtGui/QMatrix4x4>
47#include <QtGui/QQuaternion>
48#include <QtGui/QVector3D>
49
50QT_BEGIN_NAMESPACE
51
52namespace Qt3DRender {
53
54class QCameraLensPrivate;
55
56class Q_3DRENDERSHARED_EXPORT QCameraLens : public Qt3DCore::QComponent
57{
58 Q_OBJECT
59 Q_PROPERTY(ProjectionType projectionType READ projectionType WRITE setProjectionType NOTIFY projectionTypeChanged)
60 Q_PROPERTY(float nearPlane READ nearPlane WRITE setNearPlane NOTIFY nearPlaneChanged)
61 Q_PROPERTY(float farPlane READ farPlane WRITE setFarPlane NOTIFY farPlaneChanged)
62 Q_PROPERTY(float fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
63 Q_PROPERTY(float aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
64 Q_PROPERTY(float left READ left WRITE setLeft NOTIFY leftChanged)
65 Q_PROPERTY(float right READ right WRITE setRight NOTIFY rightChanged)
66 Q_PROPERTY(float bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
67 Q_PROPERTY(float top READ top WRITE setTop NOTIFY topChanged)
68 Q_PROPERTY(QMatrix4x4 projectionMatrix READ projectionMatrix WRITE setProjectionMatrix NOTIFY projectionMatrixChanged)
69 Q_PROPERTY(float exposure READ exposure WRITE setExposure NOTIFY exposureChanged REVISION 9)
70
71public:
72 explicit QCameraLens(QNode *parent = nullptr);
73 ~QCameraLens();
74
75 enum ProjectionType {
76 OrthographicProjection,
77 PerspectiveProjection,
78 FrustumProjection,
79 CustomProjection
80 };
81 Q_ENUM(ProjectionType) // LCOV_EXCL_LINE
82
83 ProjectionType projectionType() const;
84 float nearPlane() const;
85 float farPlane() const;
86 float fieldOfView() const;
87 float aspectRatio() const;
88 float left() const;
89 float right() const;
90 float bottom() const;
91 float top() const;
92
93 QMatrix4x4 projectionMatrix() const;
94
95 void setOrthographicProjection(float left, float right,
96 float bottom, float top,
97 float nearPlane, float farPlane);
98
99 void setFrustumProjection(float left, float right,
100 float bottom, float top,
101 float nearPlane, float farPlane);
102
103 void setPerspectiveProjection(float fieldOfView, float aspect,
104 float nearPlane, float farPlane);
105
106 float exposure() const;
107
108 void viewAll(Qt3DCore::QNodeId cameraId);
109 void viewEntity(Qt3DCore::QNodeId entityId, Qt3DCore::QNodeId cameraId);
110
111public Q_SLOTS:
112 void setProjectionType(ProjectionType projectionType);
113 void setNearPlane(float nearPlane);
114 void setFarPlane(float farPlane);
115 void setFieldOfView(float fieldOfView);
116 void setAspectRatio(float aspectRatio);
117 void setLeft(float left);
118 void setRight(float right);
119 void setBottom(float bottom);
120 void setTop(float top);
121 void setProjectionMatrix(const QMatrix4x4 &projectionMatrix);
122 void setExposure(float exposure);
123
124Q_SIGNALS:
125 void projectionTypeChanged(QCameraLens::ProjectionType projectionType);
126 void nearPlaneChanged(float nearPlane);
127 void farPlaneChanged(float farPlane);
128 void fieldOfViewChanged(float fieldOfView);
129 void aspectRatioChanged(float aspectRatio);
130 void leftChanged(float left);
131 void rightChanged(float right);
132 void bottomChanged(float bottom);
133 void topChanged(float top);
134 void projectionMatrixChanged(const QMatrix4x4 &projectionMatrix);
135 void exposureChanged(float exposure);
136 void viewSphere(const QVector3D &center, float radius);
137
138protected:
139 explicit QCameraLens(QCameraLensPrivate &dd, QNode *parent = nullptr);
140
141private:
142 Q_DECLARE_PRIVATE(QCameraLens)
143 Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const override;
144 void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override;
145};
146
147} // Qt3DRender
148
149QT_END_NAMESPACE
150
151#endif // QT3DRENDER_CAMERALENS_H
152

source code of qt3d/src/render/frontend/qcameralens.h