1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QT3DRENDER_CAMERA_H |
5 | #define QT3DRENDER_CAMERA_H |
6 | |
7 | #include <Qt3DCore/qentity.h> |
8 | #include <Qt3DCore/qtransform.h> |
9 | #include <Qt3DRender/qt3drender_global.h> |
10 | #include <Qt3DRender/qcameralens.h> |
11 | #include <QtGui/QMatrix4x4> |
12 | #include <QtGui/QQuaternion> |
13 | #include <QtGui/QVector3D> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | namespace Qt3DRender { |
18 | |
19 | class QCameraPrivate; |
20 | |
21 | class Q_3DRENDERSHARED_EXPORT QCamera : public Qt3DCore::QEntity |
22 | { |
23 | Q_OBJECT |
24 | // CameraLens |
25 | Q_PROPERTY(Qt3DRender::QCameraLens::ProjectionType projectionType READ projectionType WRITE setProjectionType NOTIFY projectionTypeChanged) |
26 | Q_PROPERTY(float nearPlane READ nearPlane WRITE setNearPlane NOTIFY nearPlaneChanged) |
27 | Q_PROPERTY(float farPlane READ farPlane WRITE setFarPlane NOTIFY farPlaneChanged) |
28 | Q_PROPERTY(float fieldOfView READ fieldOfView WRITE setFieldOfView NOTIFY fieldOfViewChanged) |
29 | Q_PROPERTY(float aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged) |
30 | Q_PROPERTY(float left READ left WRITE setLeft NOTIFY leftChanged) |
31 | Q_PROPERTY(float right READ right WRITE setRight NOTIFY rightChanged) |
32 | Q_PROPERTY(float bottom READ bottom WRITE setBottom NOTIFY bottomChanged) |
33 | Q_PROPERTY(float top READ top WRITE setTop NOTIFY topChanged) |
34 | Q_PROPERTY(QMatrix4x4 projectionMatrix READ projectionMatrix WRITE setProjectionMatrix NOTIFY projectionMatrixChanged) |
35 | Q_PROPERTY(float exposure READ exposure WRITE setExposure NOTIFY exposureChanged REVISION 9) |
36 | // LookAt |
37 | Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) |
38 | Q_PROPERTY(QVector3D upVector READ upVector WRITE setUpVector NOTIFY upVectorChanged) |
39 | Q_PROPERTY(QVector3D viewCenter READ viewCenter WRITE setViewCenter NOTIFY viewCenterChanged) |
40 | Q_PROPERTY(QVector3D viewVector READ viewVector NOTIFY viewVectorChanged) |
41 | Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix NOTIFY viewMatrixChanged) |
42 | |
43 | Q_PROPERTY(Qt3DRender::QCameraLens *lens READ lens CONSTANT REVISION 14) |
44 | Q_PROPERTY(Qt3DCore::QTransform *transform READ transform CONSTANT REVISION 14) |
45 | |
46 | public: |
47 | explicit QCamera(QNode *parent = nullptr); |
48 | ~QCamera(); |
49 | |
50 | enum CameraTranslationOption { |
51 | TranslateViewCenter, |
52 | DontTranslateViewCenter |
53 | }; |
54 | Q_ENUM(CameraTranslationOption) // LCOV_EXCL_LINE |
55 | |
56 | QCameraLens *lens() const; |
57 | Qt3DCore::QTransform *transform() const; |
58 | |
59 | Q_INVOKABLE QQuaternion tiltRotation(float angle) const; |
60 | Q_INVOKABLE QQuaternion panRotation(float angle) const; |
61 | Q_INVOKABLE QQuaternion rollRotation(float angle) const; |
62 | Q_INVOKABLE QQuaternion rotation(float angle, const QVector3D &axis) const; |
63 | |
64 | // Translate relative to camera orientation axes |
65 | Q_INVOKABLE void translate(const QVector3D& vLocal, CameraTranslationOption option = TranslateViewCenter); |
66 | |
67 | // Translate relative to world axes |
68 | Q_INVOKABLE void translateWorld(const QVector3D& vWorld, CameraTranslationOption option = TranslateViewCenter); |
69 | |
70 | Q_INVOKABLE void tilt(float angle); |
71 | Q_INVOKABLE void pan(float angle); |
72 | Q_INVOKABLE void pan(float angle, const QVector3D &axis); |
73 | Q_INVOKABLE void roll(float angle); |
74 | |
75 | Q_INVOKABLE void tiltAboutViewCenter(float angle); |
76 | Q_INVOKABLE void panAboutViewCenter(float angle); |
77 | Q_INVOKABLE void panAboutViewCenter(float angle, const QVector3D &axis); |
78 | Q_INVOKABLE void rollAboutViewCenter(float angle); |
79 | |
80 | Q_INVOKABLE void rotate(const QQuaternion& q); |
81 | Q_INVOKABLE void rotateAboutViewCenter(const QQuaternion& q); |
82 | |
83 | QCameraLens::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 | QMatrix4x4 projectionMatrix() const; |
93 | float exposure() const; |
94 | QVector3D position() const; |
95 | QVector3D upVector() const; |
96 | QVector3D viewCenter() const; |
97 | QVector3D viewVector() const; |
98 | QMatrix4x4 viewMatrix() const; |
99 | |
100 | public Q_SLOTS: |
101 | void setProjectionType(QCameraLens::ProjectionType type); |
102 | void setNearPlane(float nearPlane); |
103 | void setFarPlane(float farPlane); |
104 | void setFieldOfView(float fieldOfView); |
105 | void setAspectRatio(float aspectRatio); |
106 | void setLeft(float left); |
107 | void setRight(float right); |
108 | void setBottom(float bottom); |
109 | void setTop(float top); |
110 | void setProjectionMatrix(const QMatrix4x4 &projectionMatrix); |
111 | void setExposure(float exposure); |
112 | void setPosition(const QVector3D &position); |
113 | void setUpVector(const QVector3D &upVector); |
114 | void setViewCenter(const QVector3D &viewCenter); |
115 | |
116 | void viewAll(); |
117 | void viewSphere(const QVector3D ¢er, float radius); |
118 | void viewEntity(Qt3DCore::QEntity *entity); |
119 | |
120 | Q_SIGNALS: |
121 | void projectionTypeChanged(QCameraLens::ProjectionType projectionType); |
122 | void nearPlaneChanged(float nearPlane); |
123 | void farPlaneChanged(float farPlane); |
124 | void fieldOfViewChanged(float fieldOfView); |
125 | void aspectRatioChanged(float aspectRatio); |
126 | void leftChanged(float left); |
127 | void rightChanged(float right); |
128 | void bottomChanged(float bottom); |
129 | void topChanged(float top); |
130 | void projectionMatrixChanged(const QMatrix4x4 &projectionMatrix); |
131 | void exposureChanged(float exposure); |
132 | void positionChanged(const QVector3D &position); |
133 | void upVectorChanged(const QVector3D &upVector); |
134 | void viewCenterChanged(const QVector3D &viewCenter); |
135 | void viewVectorChanged(const QVector3D &viewVector); |
136 | void viewMatrixChanged(); |
137 | |
138 | protected: |
139 | Q_DECLARE_PRIVATE(QCamera) |
140 | explicit QCamera(QCameraPrivate &dd, QNode *parent = nullptr); |
141 | }; |
142 | |
143 | } // namespace Qt3DRender |
144 | |
145 | QT_END_NAMESPACE |
146 | |
147 | #endif // QT3DRENDER_CAMERA_H |
148 | |