| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | // |
| 5 | // W A R N I N G |
| 6 | // ------------- |
| 7 | // |
| 8 | // This file is not part of the QtDataVisualization API. It exists purely as an |
| 9 | // implementation detail. This header file may change from version to |
| 10 | // version without notice, or even be removed. |
| 11 | // |
| 12 | // We mean it. |
| 13 | |
| 14 | #ifndef CAMERAHELPER_P_H |
| 15 | #define CAMERAHELPER_P_H |
| 16 | |
| 17 | #include "datavisualizationglobal_p.h" |
| 18 | #include "q3dcamera.h" |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | class QMatrix4x4; |
| 22 | class QPoint; |
| 23 | QT_END_NAMESPACE |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | class CameraHelper : public QObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | private: |
| 32 | QVector3D m_position; |
| 33 | QVector3D m_target; |
| 34 | QVector3D m_up; |
| 35 | |
| 36 | QPoint m_previousMousePos; |
| 37 | |
| 38 | GLfloat m_xRotation; |
| 39 | GLfloat m_yRotation; |
| 40 | GLfloat m_defaultXRotation; |
| 41 | GLfloat m_defaultYRotation; |
| 42 | |
| 43 | GLfloat m_rotationSpeed; |
| 44 | |
| 45 | public: |
| 46 | explicit CameraHelper(QObject *parent = 0); |
| 47 | ~CameraHelper(); |
| 48 | |
| 49 | // How fast camera rotates when mouse is dragged. Default is 100. |
| 50 | void setRotationSpeed(int speed); |
| 51 | // Set camera rotation in degrees |
| 52 | void setCameraRotation(const QPointF &rotation); |
| 53 | // Get camera rotations |
| 54 | QPointF getCameraRotations(); |
| 55 | // Set default camera orientation. Position's x and y should be 0. |
| 56 | void setDefaultCameraOrientation(const QVector3D &defaultPosition, |
| 57 | const QVector3D &defaultTarget, |
| 58 | const QVector3D &defaultUp); |
| 59 | // Calculate view matrix based on rotation and zoom |
| 60 | QMatrix4x4 calculateViewMatrix(const QPoint &mousePos, int zoom, |
| 61 | int screenWidth, int screenHeight, |
| 62 | bool showUnder = false); |
| 63 | // Calcluate light position based on rotation. Call after calling calculateViewMatrix to get |
| 64 | // up-to-date position |
| 65 | QVector3D calculateLightPosition(const QVector3D &lightPosition, |
| 66 | GLfloat fixedRotation = 0.0f, |
| 67 | GLfloat distanceModifier = 0.0f); |
| 68 | void updateMousePos(const QPoint &mousePos); |
| 69 | void setCameraPreset(Q3DCamera::CameraPreset preset); |
| 70 | }; |
| 71 | |
| 72 | QT_END_NAMESPACE |
| 73 | |
| 74 | #endif |
| 75 |
