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