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_CAMERA_H
41#define QT3DRENDER_CAMERA_H
42
43#include <Qt3DCore/qentity.h>
44#include <Qt3DRender/qt3drender_global.h>
45#include <Qt3DRender/qcameralens.h>
46#include <QtGui/QMatrix4x4>
47#include <QtGui/QQuaternion>
48#include <QtGui/QVector3D>
49
50QT_BEGIN_NAMESPACE
51
52namespace Qt3DCore {
53class QEntity;
54class QTransform;
55}
56
57namespace Qt3DRender {
58
59class QCameraPrivate;
60
61class Q_3DRENDERSHARED_EXPORT QCamera : public Qt3DCore::QEntity
62{
63 Q_OBJECT
64 // CameraLens
65 Q_PROPERTY(Qt3DRender::QCameraLens::ProjectionType projectionType READ projectionType WRITE setProjectionType NOTIFY projectionTypeChanged)
66 Q_PROPERTY(float nearPlane READ nearPlane WRITE setNearPlane NOTIFY nearPlaneChanged)
67 Q_PROPERTY(float farPlane READ farPlane WRITE setFarPlane NOTIFY farPlaneChanged)
68 Q_PROPERTY(float fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged)
69 Q_PROPERTY(float aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
70 Q_PROPERTY(float left READ left WRITE setLeft NOTIFY leftChanged)
71 Q_PROPERTY(float right READ right WRITE setRight NOTIFY rightChanged)
72 Q_PROPERTY(float bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
73 Q_PROPERTY(float top READ top WRITE setTop NOTIFY topChanged)
74 Q_PROPERTY(QMatrix4x4 projectionMatrix READ projectionMatrix WRITE setProjectionMatrix NOTIFY projectionMatrixChanged)
75 Q_PROPERTY(float exposure READ exposure WRITE setExposure NOTIFY exposureChanged REVISION 9)
76 // LookAt
77 Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
78 Q_PROPERTY(QVector3D upVector READ upVector WRITE setUpVector NOTIFY upVectorChanged)
79 Q_PROPERTY(QVector3D viewCenter READ viewCenter WRITE setViewCenter NOTIFY viewCenterChanged)
80 Q_PROPERTY(QVector3D viewVector READ viewVector NOTIFY viewVectorChanged)
81 Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix NOTIFY viewMatrixChanged)
82
83public:
84 explicit QCamera(QNode *parent = nullptr);
85 ~QCamera();
86
87 enum CameraTranslationOption {
88 TranslateViewCenter,
89 DontTranslateViewCenter
90 };
91 Q_ENUM(CameraTranslationOption) // LCOV_EXCL_LINE
92
93 QCameraLens *lens() const;
94 Qt3DCore::QTransform *transform() const;
95
96 Q_INVOKABLE QQuaternion tiltRotation(float angle) const;
97 Q_INVOKABLE QQuaternion panRotation(float angle) const;
98 Q_INVOKABLE QQuaternion rollRotation(float angle) const;
99 Q_INVOKABLE QQuaternion rotation(float angle, const QVector3D &axis) const;
100
101 // Translate relative to camera orientation axes
102 Q_INVOKABLE void translate(const QVector3D& vLocal, CameraTranslationOption option = TranslateViewCenter);
103
104 // Translate relative to world axes
105 Q_INVOKABLE void translateWorld(const QVector3D& vWorld, CameraTranslationOption option = TranslateViewCenter);
106
107 Q_INVOKABLE void tilt(float angle);
108 Q_INVOKABLE void pan(float angle);
109 Q_INVOKABLE void pan(float angle, const QVector3D &axis);
110 Q_INVOKABLE void roll(float angle);
111
112 Q_INVOKABLE void tiltAboutViewCenter(float angle);
113 Q_INVOKABLE void panAboutViewCenter(float angle);
114 Q_INVOKABLE void panAboutViewCenter(float angle, const QVector3D &axis);
115 Q_INVOKABLE void rollAboutViewCenter(float angle);
116
117 Q_INVOKABLE void rotate(const QQuaternion& q);
118 Q_INVOKABLE void rotateAboutViewCenter(const QQuaternion& q);
119
120 QCameraLens::ProjectionType projectionType() const;
121 float nearPlane() const;
122 float farPlane() const;
123 float fieldOfView() const;
124 float aspectRatio() const;
125 float left() const;
126 float right() const;
127 float bottom() const;
128 float top() const;
129 QMatrix4x4 projectionMatrix() const;
130 float exposure() const;
131 QVector3D position() const;
132 QVector3D upVector() const;
133 QVector3D viewCenter() const;
134 QVector3D viewVector() const;
135 QMatrix4x4 viewMatrix() const;
136
137public Q_SLOTS:
138 void setProjectionType(QCameraLens::ProjectionType type);
139 void setNearPlane(float nearPlane);
140 void setFarPlane(float farPlane);
141 void setFieldOfView(float fieldOfView);
142 void setAspectRatio(float aspectRatio);
143 void setLeft(float left);
144 void setRight(float right);
145 void setBottom(float bottom);
146 void setTop(float top);
147 void setProjectionMatrix(const QMatrix4x4 &projectionMatrix);
148 void setExposure(float exposure);
149 void setPosition(const QVector3D &position);
150 void setUpVector(const QVector3D &upVector);
151 void setViewCenter(const QVector3D &viewCenter);
152
153 void viewAll();
154 void viewSphere(const QVector3D &center, float radius);
155 void viewEntity(Qt3DCore::QEntity *entity);
156
157Q_SIGNALS:
158 void projectionTypeChanged(QCameraLens::ProjectionType projectionType);
159 void nearPlaneChanged(float nearPlane);
160 void farPlaneChanged(float farPlane);
161 void fieldOfViewChanged(float fieldOfView);
162 void aspectRatioChanged(float aspectRatio);
163 void leftChanged(float left);
164 void rightChanged(float right);
165 void bottomChanged(float bottom);
166 void topChanged(float top);
167 void projectionMatrixChanged(const QMatrix4x4 &projectionMatrix);
168 void exposureChanged(float exposure);
169 void positionChanged(const QVector3D &position);
170 void upVectorChanged(const QVector3D &upVector);
171 void viewCenterChanged(const QVector3D &viewCenter);
172 void viewVectorChanged(const QVector3D &viewVector);
173 void viewMatrixChanged();
174
175protected:
176 Q_DECLARE_PRIVATE(QCamera)
177 explicit QCamera(QCameraPrivate &dd, QNode *parent = nullptr);
178};
179
180} // namespace Qt3DRender
181
182QT_END_NAMESPACE
183
184#endif // QT3DRENDER_CAMERA_H
185