1/****************************************************************************
2**
3** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
38#define QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
39
40#include <Qt3DCore/QEntity>
41#include <Qt3DExtras/qt3dextras_global.h>
42
43QT_BEGIN_NAMESPACE
44
45namespace Qt3DInput {
46class QKeyboardDevice;
47class QMouseDevice;
48}
49
50namespace Qt3DRender {
51class QCamera;
52}
53
54namespace Qt3DExtras {
55
56class QAbstractCameraControllerPrivate;
57
58class Q_3DEXTRASSHARED_EXPORT QAbstractCameraController : public Qt3DCore::QEntity
59{
60 Q_OBJECT
61 Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
62 Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
63 Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
64 Q_PROPERTY(float acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
65 Q_PROPERTY(float deceleration READ deceleration WRITE setDeceleration NOTIFY decelerationChanged)
66
67public:
68 ~QAbstractCameraController();
69
70 Qt3DRender::QCamera *camera() const;
71 float linearSpeed() const;
72 float lookSpeed() const;
73
74 float acceleration() const;
75 float deceleration() const;
76
77 void setCamera(Qt3DRender::QCamera *camera);
78 void setLinearSpeed(float linearSpeed);
79 void setLookSpeed(float lookSpeed);
80
81 void setAcceleration(float acceleration);
82 void setDeceleration(float deceleration);
83
84Q_SIGNALS:
85 void cameraChanged();
86 void linearSpeedChanged();
87 void lookSpeedChanged();
88
89 void accelerationChanged(float acceleration);
90 void decelerationChanged(float deceleration);
91
92protected:
93 explicit QAbstractCameraController(Qt3DCore::QNode *parent = nullptr);
94 QAbstractCameraController(QAbstractCameraControllerPrivate &dd, Qt3DCore::QNode *parent = nullptr);
95
96 Qt3DInput::QKeyboardDevice *keyboardDevice() const;
97 Qt3DInput::QMouseDevice *mouseDevice() const;
98
99public:
100 struct InputState
101 {
102 float rxAxisValue;
103 float ryAxisValue;
104 float txAxisValue;
105 float tyAxisValue;
106 float tzAxisValue;
107
108 bool leftMouseButtonActive;
109 bool middleMouseButtonActive;
110 bool rightMouseButtonActive;
111
112 bool altKeyActive;
113 bool shiftKeyActive;
114 };
115
116private:
117 virtual void moveCamera(const InputState &state, float dt) = 0;
118
119private:
120 Q_DECLARE_PRIVATE(QAbstractCameraController)
121};
122
123} // Qt3DExtras
124
125QT_END_NAMESPACE
126
127#endif // QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
128

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