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_CAMERALENS_P_H |
5 | #define QT3DRENDER_CAMERALENS_P_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 for the convenience |
12 | // of other Qt classes. 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 <Qt3DRender/private/qt3drender_global_p.h> |
19 | #include <Qt3DCore/private/qcomponent_p.h> |
20 | |
21 | #include "qcameralens.h" |
22 | |
23 | #include <QtGui/qmatrix4x4.h> |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | namespace Qt3DRender { |
28 | |
29 | struct CameraLensRequest |
30 | { |
31 | Qt3DCore::QNodeId requestId; |
32 | Qt3DCore::QNodeId cameraId; |
33 | Qt3DCore::QNodeId entityId; |
34 | |
35 | inline operator bool() const { return !requestId.isNull(); } |
36 | }; |
37 | |
38 | inline bool operator ==(const CameraLensRequest &a, const CameraLensRequest &b) noexcept |
39 | { |
40 | return a.cameraId == b.cameraId && a.entityId == b.entityId && a.requestId == b.requestId; |
41 | } |
42 | |
43 | inline bool operator !=(const CameraLensRequest &a, const CameraLensRequest &b) noexcept |
44 | { |
45 | return !(a == b); |
46 | } |
47 | |
48 | class Q_3DRENDERSHARED_PRIVATE_EXPORT QCameraLensPrivate : public Qt3DCore::QComponentPrivate |
49 | { |
50 | public: |
51 | QCameraLensPrivate(); |
52 | |
53 | inline void updateProjectionMatrix() |
54 | { |
55 | switch (m_projectionType) { |
56 | case QCameraLens::OrthographicProjection: |
57 | updateOrthographicProjection(); |
58 | break; |
59 | case QCameraLens::PerspectiveProjection: |
60 | updatePerpectiveProjection(); |
61 | break; |
62 | case QCameraLens::FrustumProjection: |
63 | updateFrustumProjection(); |
64 | break; |
65 | case QCameraLens::CustomProjection: |
66 | break; |
67 | } |
68 | } |
69 | |
70 | Q_DECLARE_PUBLIC(QCameraLens) |
71 | |
72 | QCameraLens::ProjectionType m_projectionType; |
73 | |
74 | float m_nearPlane; |
75 | float m_farPlane; |
76 | |
77 | float m_fieldOfView; |
78 | float m_aspectRatio; |
79 | |
80 | float m_left; |
81 | float m_right; |
82 | float m_bottom; |
83 | float m_top; |
84 | |
85 | mutable QMatrix4x4 m_projectionMatrix; |
86 | |
87 | float m_exposure; |
88 | |
89 | CameraLensRequest m_pendingViewAllRequest; |
90 | void processViewAllResult(Qt3DCore::QNodeId requestId, const QVector3D ¢er, float radius); |
91 | |
92 | private: |
93 | inline void updatePerpectiveProjection() |
94 | { |
95 | Q_Q(QCameraLens); |
96 | m_projectionMatrix.setToIdentity(); |
97 | m_projectionMatrix.perspective(verticalAngle: m_fieldOfView, aspectRatio: m_aspectRatio, nearPlane: m_nearPlane, farPlane: m_farPlane); |
98 | Q_EMIT q->projectionMatrixChanged(projectionMatrix: m_projectionMatrix); |
99 | } |
100 | |
101 | inline void updateOrthographicProjection() |
102 | { |
103 | Q_Q(QCameraLens); |
104 | m_projectionMatrix.setToIdentity(); |
105 | m_projectionMatrix.ortho(left: m_left, right: m_right, bottom: m_bottom, top: m_top, nearPlane: m_nearPlane, farPlane: m_farPlane); |
106 | Q_EMIT q->projectionMatrixChanged(projectionMatrix: m_projectionMatrix); |
107 | } |
108 | |
109 | inline void updateFrustumProjection() |
110 | { |
111 | Q_Q(QCameraLens); |
112 | m_projectionMatrix.setToIdentity(); |
113 | m_projectionMatrix.frustum(left: m_left, right: m_right, bottom: m_bottom, top: m_top, nearPlane: m_nearPlane, farPlane: m_farPlane); |
114 | Q_EMIT q->projectionMatrixChanged(projectionMatrix: m_projectionMatrix); |
115 | } |
116 | }; |
117 | |
118 | struct QCameraLensData |
119 | { |
120 | QMatrix4x4 projectionMatrix; |
121 | float exposure; |
122 | }; |
123 | |
124 | } // namespace Qt3DRender |
125 | |
126 | QT_END_NAMESPACE |
127 | |
128 | #endif // QT3DRENDER_CAMERALENS_P_H |
129 | |