1// Copyright (C) 2016 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 QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
5#define QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
6
7#include <Qt3DCore/QEntity>
8#include <Qt3DExtras/qt3dextras_global.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace Qt3DInput {
13class QKeyboardDevice;
14class QMouseDevice;
15}
16
17namespace Qt3DRender {
18class QCamera;
19}
20
21namespace Qt3DExtras {
22
23class QAbstractCameraControllerPrivate;
24
25class Q_3DEXTRASSHARED_EXPORT QAbstractCameraController : public Qt3DCore::QEntity
26{
27 Q_OBJECT
28 Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
29 Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
30 Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
31 Q_PROPERTY(float acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
32 Q_PROPERTY(float deceleration READ deceleration WRITE setDeceleration NOTIFY decelerationChanged)
33
34public:
35 ~QAbstractCameraController();
36
37 Qt3DRender::QCamera *camera() const;
38 float linearSpeed() const;
39 float lookSpeed() const;
40
41 float acceleration() const;
42 float deceleration() const;
43
44 void setCamera(Qt3DRender::QCamera *camera);
45 void setLinearSpeed(float linearSpeed);
46 void setLookSpeed(float lookSpeed);
47
48 void setAcceleration(float acceleration);
49 void setDeceleration(float deceleration);
50
51Q_SIGNALS:
52 void cameraChanged();
53 void linearSpeedChanged();
54 void lookSpeedChanged();
55
56 void accelerationChanged(float acceleration);
57 void decelerationChanged(float deceleration);
58
59protected:
60 explicit QAbstractCameraController(Qt3DCore::QNode *parent = nullptr);
61 QAbstractCameraController(QAbstractCameraControllerPrivate &dd, Qt3DCore::QNode *parent = nullptr);
62
63 Qt3DInput::QKeyboardDevice *keyboardDevice() const;
64 Qt3DInput::QMouseDevice *mouseDevice() const;
65
66public:
67 struct InputState
68 {
69 float rxAxisValue;
70 float ryAxisValue;
71 float txAxisValue;
72 float tyAxisValue;
73 float tzAxisValue;
74
75 bool leftMouseButtonActive;
76 bool middleMouseButtonActive;
77 bool rightMouseButtonActive;
78
79 bool altKeyActive;
80 bool shiftKeyActive;
81 };
82
83private:
84 virtual void moveCamera(const InputState &state, float dt) = 0;
85
86private:
87 Q_DECLARE_PRIVATE(QAbstractCameraController)
88};
89
90} // Qt3DExtras
91
92QT_END_NAMESPACE
93
94#endif // QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
95

source code of qt3d/src/extras/defaults/qabstractcameracontroller.h