summaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2016-01-15 15:09:44 +0100
committerSean Harmer <sean.harmer@kdab.com>2016-01-16 17:17:49 +0000
commitb0404a42ced2ea5a583e1c6ddc22940ffdc1e48e (patch)
treeb073c3c680e388bda00228b204743b092b11de6a /src/input
parent8656b95ffb67efe7dd1cc3a65b12d277e83e1d22 (diff)
Move QCamera/QCameraLens to Qt3DRender
Also get rid of Qt3DRender::QWindow and of the hard codes camera controller. Change-Id: I307735d01caf97b7a690b28de8dc99fc9866c35f Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/input')
-rw-r--r--src/input/backend/backend.pri2
-rw-r--r--src/input/backend/cameracontroller.cpp365
-rw-r--r--src/input/backend/cameracontroller_p.h175
-rw-r--r--src/input/backend/updatehandlerjob.cpp6
-rw-r--r--src/input/frontend/qinputaspect.cpp15
-rw-r--r--src/input/frontend/qinputaspect.h11
-rw-r--r--src/input/frontend/qinputaspect_p.h2
7 files changed, 4 insertions, 572 deletions
diff --git a/src/input/backend/backend.pri b/src/input/backend/backend.pri
index a1fcedd0e..5f7f7b51b 100644
--- a/src/input/backend/backend.pri
+++ b/src/input/backend/backend.pri
@@ -1,5 +1,4 @@
HEADERS += \
- $$PWD/cameracontroller_p.h \
$$PWD/keyboardcontroller_p.h \
$$PWD/keyboardinput_p.h \
$$PWD/inputhandler_p.h \
@@ -32,7 +31,6 @@ HEADERS += \
$$PWD/inputsequence_p.h
SOURCES += \
- $$PWD/cameracontroller.cpp \
$$PWD/keyboardcontroller.cpp \
$$PWD/keyboardinput.cpp \
$$PWD/inputhandler.cpp \
diff --git a/src/input/backend/cameracontroller.cpp b/src/input/backend/cameracontroller.cpp
deleted file mode 100644
index 7001a9020..000000000
--- a/src/input/backend/cameracontroller.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "cameracontroller_p.h"
-
-#include <QMouseEvent>
-#include <QKeyEvent>
-#include <QTimer>
-
-#include <qcamera.h>
-#include <qcameralens.h>
-#include <qentity.h>
-
-QT_BEGIN_NAMESPACE
-
-using namespace Qt3DCore;
-
-namespace Qt3DInput {
-namespace Input {
-
-CameraController::CameraController(QObject *parent) :
- QObject(parent),
- m_camera( 0 ),
- m_vx( 0.0f ),
- m_vy( 0.0f ),
- m_vz( 0.0f ),
- m_viewCenterFixed( false ),
- m_panAngle( 0.0f ),
- m_tiltAngle( 0.0f ),
- m_leftButtonPressed( false ),
- m_orbitMode( false ),
- m_linearSpeed( 40.0f ),
- m_time( 0.0f ),
- m_orbitRate( -0.3f ),
- m_lookRate( 0.1f ),
- m_translateFast( false ),
- m_multisampleEnabled( true ),
- m_controlMode( FirstPerson ),
- m_firstPersonUp( QVector3D( 0.0f, 1.0f, 0.0f ) ),
- m_updateTimer(new QTimer(this))
-{
- m_updateTimer->setInterval(16);
- connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(onUpdate()));
-}
-
-/*!
- * CameraController expects to find a Camera entity.
- * That means if you have built you Camera yourself using
- * an Entity, a CameraLens and a Transform instead of using the
- * ready made Camera element, it won't work.
- */
-void CameraController::setCamera( Qt3DCore::QCamera* cam )
-{
- m_camera = cam;
- m_cameraEntity = cam;
-
- if (m_camera)
- m_updateTimer->start();
- else
- m_updateTimer->stop();
-}
-
-Qt3DCore::QCamera *CameraController::camera() const
-{
- return m_camera;
-}
-
-void CameraController::setLinearSpeed( float speed )
-{
- if ( qFuzzyCompare( m_linearSpeed, speed ) )
- return;
- m_linearSpeed = speed;
- emit linearSpeedChanged(speed);
-}
-
-float CameraController::linearSpeed() const
-{
- return m_linearSpeed;
-}
-
-float CameraController::orbitRate() const
-{
- return m_orbitRate;
-}
-
-void CameraController::setOrbitRate( float rate )
-{
- if ( qFuzzyCompare( m_orbitRate, rate ) )
- return;
- m_orbitRate = rate;
- emit orbitRateChanged(rate);
-}
-
-float CameraController::lookRate() const
-{
- return m_lookRate;
-}
-
-void CameraController::setLookRate( float rate )
-{
- if ( qFuzzyCompare( m_lookRate, rate ) )
- return;
- m_lookRate = rate;
- emit lookRateChanged(rate);
-}
-
-void CameraController::update(double dt)
-{
- if ( !m_camera )
- return;
-
- if (m_translateFast)
- dt *= 10;
-
- // Update the camera position and orientation
- QCamera::CameraTranslationOption option = m_viewCenterFixed
- ? QCamera::DontTranslateViewCenter
- : QCamera::TranslateViewCenter;
- m_camera->translate(dt * QVector3D(m_vx, m_vy, m_vz), option);
-
- if (!qFuzzyIsNull(m_panAngle)) {
- m_camera->pan(m_panAngle);
- m_panAngle = 0.0f;
- }
-
- if (!qFuzzyIsNull(m_tiltAngle)) {
- m_camera->tilt(m_tiltAngle);
- m_tiltAngle = 0.0f;
- }
-}
-
-bool CameraController::keyPressEvent( QT_PREPEND_NAMESPACE(QKeyEvent*) e )
-{
- m_translateFast = e->modifiers().testFlag(Qt::AltModifier);
- m_viewCenterFixed = e->modifiers().testFlag(Qt::ShiftModifier);
-
- switch ( e->key() )
- {
- case Qt::Key_Right:
- m_vx = m_linearSpeed;
- break;
-
- case Qt::Key_Left:
- m_vx = -m_linearSpeed;
- break;
-
- case Qt::Key_Up:
- m_vz = m_linearSpeed;
- break;
-
- case Qt::Key_Down:
- m_vz = -m_linearSpeed;
- break;
-
- case Qt::Key_PageUp:
- m_vy = m_linearSpeed;
- break;
-
- case Qt::Key_PageDown:
- m_vy = -m_linearSpeed;
- break;
-
- case Qt::Key_A:
- toggleMSAA();
- break;
-
- default:
- return false;
- }
-
- return true;
-}
-
-bool CameraController::keyReleaseEvent( QT_PREPEND_NAMESPACE(QKeyEvent*) e )
-{
- switch ( e->key() )
- {
- case Qt::Key_Right:
- case Qt::Key_Left:
- m_vx = 0.0;
- break;
-
- case Qt::Key_Up:
- case Qt::Key_Down:
- m_vz = 0.0;
- break;
-
- case Qt::Key_PageUp:
- case Qt::Key_PageDown:
- m_vy = 0.0;
- break;
-
- default:
- return false;
- }
-
- return true;
-}
-
-void CameraController::mousePressEvent( QT_PREPEND_NAMESPACE(QMouseEvent*) e )
-{
- if ( e->button() == Qt::LeftButton )
- {
- m_leftButtonPressed = true;
- m_pos = m_prevPos = e->pos();
- }
- else if ( e->button() == Qt::RightButton )
- {
- m_orbitMode = true;
- m_pos = m_prevPos = e->pos();
- }
-}
-
-void CameraController::mouseReleaseEvent( QT_PREPEND_NAMESPACE(QMouseEvent*) e )
-{
- if ( e->button() == Qt::LeftButton )
- {
- m_leftButtonPressed = false;
- }
- else if ( e->button() == Qt::RightButton )
- {
- m_orbitMode = false;
- }
-}
-
-void CameraController::mouseMoveEvent( QT_PREPEND_NAMESPACE(QMouseEvent*) e )
-{
- if (!m_camera )
- return;
-
- if (!m_leftButtonPressed && !m_orbitMode)
- return;
-
- m_pos = e->pos();
- float dx = m_pos.x() - m_prevPos.x();
- float dy = -(m_pos.y() - m_prevPos.y());
- m_prevPos = m_pos;
-
- if (m_leftButtonPressed) {
- switch (m_controlMode) {
- case FreeLook:
- m_camera->pan(dx * m_lookRate);
- break;
-
- case FirstPerson:
- m_camera->pan(dx * m_lookRate, m_firstPersonUp);
- break;
- }
-
- m_camera->tilt(dy * m_lookRate);
- } else if (m_orbitMode) {
- switch (m_controlMode) {
- case FreeLook:
- m_camera->panAboutViewCenter(dx * m_orbitRate);
- break;
-
- case FirstPerson:
- m_camera->panAboutViewCenter(dx * m_orbitRate, m_firstPersonUp);
- break;
- }
-
- m_camera->tiltAboutViewCenter(dy * m_orbitRate);
- }
-}
-
-bool CameraController::isMultisampleEnabled() const
-{
- return m_multisampleEnabled;
-}
-
-void CameraController::toggleMSAA()
-{
- m_multisampleEnabled = !m_multisampleEnabled;
- emit multisampleEnabledChanged(m_multisampleEnabled);
-}
-
-void CameraController::setControlMode(ControlMode controlMode)
-{
- if (controlMode != m_controlMode) {
- m_controlMode = controlMode;
- emit controlModeChanged(controlMode);
- }
-}
-
-CameraController::ControlMode CameraController::controlMode() const
-{
- return m_controlMode;
-}
-
-void CameraController::setFirstPersonUpVector(const QVector3D &up)
-{
- if (m_firstPersonUp != up) {
- m_firstPersonUp = up;
- emit firstPersonUpVectorChanged(up);
- }
-}
-
-QVector3D CameraController::firstPersonUpVector() const
-{
- return m_firstPersonUp;
-}
-
-bool CameraController::eventFilter(QObject *receiver, QEvent *event)
-{
- switch (event->type()) {
- case QEvent::MouseButtonPress:
- mousePressEvent(static_cast<QT_PREPEND_NAMESPACE(QMouseEvent*)>(event));
- return true;
- case QEvent::MouseButtonRelease:
- mouseReleaseEvent(static_cast<QT_PREPEND_NAMESPACE(QMouseEvent*)>(event));
- return true;
- case QEvent::MouseMove:
- mouseMoveEvent(static_cast<QT_PREPEND_NAMESPACE(QMouseEvent*)>(event));
- return true;
- case QEvent::KeyPress:
- return keyPressEvent(static_cast<QT_PREPEND_NAMESPACE(QKeyEvent)*>(event));
- case QEvent::KeyRelease:
- return keyReleaseEvent(static_cast<QT_PREPEND_NAMESPACE(QKeyEvent)*>(event));
- default:
- return QObject::eventFilter(receiver, event);
- }
-}
-
-void CameraController::onUpdate()
-{
- update(1.0 / 60.0);
-}
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
diff --git a/src/input/backend/cameracontroller_p.h b/src/input/backend/cameracontroller_p.h
deleted file mode 100644
index a539aa586..000000000
--- a/src/input/backend/cameracontroller_p.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL3$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef CAMERA_CONTROLLER_H
-#define CAMERA_CONTROLLER_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QObject>
-
-#include <QPoint>
-#include <QtGui/qvector3d.h>
-
-QT_BEGIN_NAMESPACE
-
-class QMouseEvent;
-class QWheelEvent;
-class QKeyEvent;
-class QTimer;
-
-namespace Qt3DCore {
-class QCamera;
-class QEntity;
-}
-
-namespace Qt3DInput {
-namespace Input {
-
-class CameraController : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY( float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged )
- Q_PROPERTY( float orbitRate READ orbitRate WRITE setOrbitRate NOTIFY orbitRateChanged )
- Q_PROPERTY( float lookRate READ lookRate WRITE setLookRate NOTIFY lookRateChanged )
- Q_PROPERTY( bool multisampleEnabled READ isMultisampleEnabled NOTIFY multisampleEnabledChanged )
-
- Q_PROPERTY( ControlMode controlMode READ controlMode WRITE setControlMode NOTIFY controlModeChanged )
- Q_PROPERTY( QVector3D firstPersonUpVector READ firstPersonUpVector WRITE setFirstPersonUpVector NOTIFY firstPersonUpVectorChanged )
-
-public:
- explicit CameraController(QObject *parent = 0);
-
- void setCamera( Qt3DCore::QCamera* cam );
- Qt3DCore::QCamera *camera() const;
-
- void setLinearSpeed( float speed );
- float linearSpeed() const;
-
- float orbitRate() const;
- void setOrbitRate( float rate );
-
- float lookRate() const;
- void setLookRate( float rate );
-
- void mousePressEvent( QMouseEvent* aEvent );
- void mouseReleaseEvent( QMouseEvent* aEvent );
- void mouseMoveEvent( QMouseEvent* aEvent );
-
- bool keyPressEvent( QKeyEvent* aEvent );
- bool keyReleaseEvent( QKeyEvent* aEvent );
-
- void update( double t );
-
- bool isMultisampleEnabled() const;
-
- enum ControlMode {
- FreeLook,
- FirstPerson
- };
- Q_ENUM(ControlMode)
-
- void setControlMode( ControlMode controlMode );
- ControlMode controlMode() const;
-
- void setFirstPersonUpVector( const QVector3D &up );
- QVector3D firstPersonUpVector() const;
-
-public Q_SLOTS:
- void toggleMSAA();
-
-protected:
- bool eventFilter(QObject *receiver, QEvent *event) Q_DECL_OVERRIDE;
-
-Q_SIGNALS:
- void linearSpeedChanged(float speed);
- void orbitRateChanged(float rate);
- void lookRateChanged(float rate);
-
- void multisampleEnabledChanged(bool enabled);
-
- void controlModeChanged(ControlMode controlMode);
- void firstPersonUpVectorChanged(const QVector3D &up);
-
-private Q_SLOTS:
- void onUpdate();
-
-private:
- Qt3DCore::QCamera* m_camera;
- Qt3DCore::QEntity* m_cameraEntity;
-
- float m_vx;
- float m_vy;
- float m_vz;
- bool m_viewCenterFixed;
- float m_panAngle;
- float m_tiltAngle;
-
- bool m_leftButtonPressed;
- QPoint m_prevPos;
- QPoint m_pos;
- bool m_orbitMode;
-
- float m_linearSpeed;
- float m_time;
- float m_orbitRate;
- float m_lookRate;
-
- bool m_translateFast;
- bool m_multisampleEnabled;
-
- ControlMode m_controlMode;
- QVector3D m_firstPersonUp;
-
- QTimer *m_updateTimer;
-};
-
-} // namespace Input
-} // namespace Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // of CAMERA_CONTROLLER_H
diff --git a/src/input/backend/updatehandlerjob.cpp b/src/input/backend/updatehandlerjob.cpp
index 08b2633cb..3f9dec326 100644
--- a/src/input/backend/updatehandlerjob.cpp
+++ b/src/input/backend/updatehandlerjob.cpp
@@ -86,8 +86,10 @@ void UpdateHandlerJob::run()
// If so -> add to notification payload
LogicalDevice *logicalDevice = m_handler->logicalDeviceManager()->data(m_logicalDeviceHandle);
- updateActions(logicalDevice);
- updateAxes(logicalDevice);
+ if (logicalDevice) {
+ updateActions(logicalDevice);
+ updateAxes(logicalDevice);
+ }
}
void UpdateHandlerJob::updateAxes(LogicalDevice *device)
diff --git a/src/input/frontend/qinputaspect.cpp b/src/input/frontend/qinputaspect.cpp
index 942ac9250..b1889be66 100644
--- a/src/input/frontend/qinputaspect.cpp
+++ b/src/input/frontend/qinputaspect.cpp
@@ -36,7 +36,6 @@
#include "qinputaspect.h"
#include "qinputaspect_p.h"
-#include "cameracontroller_p.h"
#include "inputhandler_p.h"
#include "keyboardcontroller_p.h"
#include "keyboardinput_p.h"
@@ -95,7 +94,6 @@ namespace Qt3DInput {
QInputAspectPrivate::QInputAspectPrivate()
: QAbstractAspectPrivate()
, m_inputHandler(new Input::InputHandler())
- , m_cameraController(new Input::CameraController())
, m_keyboardMouseIntegration(new Input::KeyboardMouseGenericDeviceIntegration(m_inputHandler.data()))
{
}
@@ -149,12 +147,6 @@ void QInputAspect::loadInputDevicePlugins()
}
}
-Qt3DCore::QCamera *QInputAspect::camera() const
-{
- Q_D(const QInputAspect);
- return d->m_cameraController->camera();
-}
-
// Note: caller is responsible for ownership
QAbstractPhysicalDevice *QInputAspect::createPhysicalDevice(const QString &name)
{
@@ -167,12 +159,6 @@ QAbstractPhysicalDevice *QInputAspect::createPhysicalDevice(const QString &name)
return device;
}
-void QInputAspect::setCamera(Qt3DCore::QCamera *camera)
-{
- Q_D(QInputAspect);
- d->m_cameraController->setCamera(camera);
-}
-
QVector<QAspectJobPtr> QInputAspect::jobsToExecute(qint64 time)
{
Q_UNUSED(time);
@@ -219,7 +205,6 @@ void QInputAspect::onInitialize(const QVariantMap &)
{
Q_D(QInputAspect);
Qt3DCore::QEventFilterService *eventService = d->services()->eventFilterService();
- eventService->registerEventFilter(d->m_cameraController.data(), 128);
d->m_inputHandler->registerEventFilters(eventService);
}
diff --git a/src/input/frontend/qinputaspect.h b/src/input/frontend/qinputaspect.h
index 7a5b298af..91d8e25d9 100644
--- a/src/input/frontend/qinputaspect.h
+++ b/src/input/frontend/qinputaspect.h
@@ -42,10 +42,6 @@
QT_BEGIN_NAMESPACE
-namespace Qt3DCore {
-class QCamera;
-}
-
namespace Qt3DInput {
class QAbstractPhysicalDevice;
@@ -55,18 +51,11 @@ class QInputDeviceIntegration;
class QT3DINPUTSHARED_EXPORT QInputAspect : public Qt3DCore::QAbstractAspect
{
Q_OBJECT
- Q_PROPERTY(Qt3DCore::QCamera* camera READ camera WRITE setCamera)
public:
explicit QInputAspect(QObject *parent = 0);
-
- Qt3DCore::QCamera *camera() const;
QAbstractPhysicalDevice *createPhysicalDevice(const QString &name);
-
QVector<Qt3DCore::QAspectJobPtr> jobsToExecute(qint64 time) Q_DECL_OVERRIDE;
-public Q_SLOTS:
- void setCamera(Qt3DCore::QCamera *camera);
-
private:
void onInitialize(const QVariantMap &data) Q_DECL_OVERRIDE;
void onCleanup() Q_DECL_OVERRIDE;
diff --git a/src/input/frontend/qinputaspect_p.h b/src/input/frontend/qinputaspect_p.h
index 4a21cb253..b7a5117ee 100644
--- a/src/input/frontend/qinputaspect_p.h
+++ b/src/input/frontend/qinputaspect_p.h
@@ -57,7 +57,6 @@ namespace Qt3DInput {
class QInputAspect;
namespace Input {
-class CameraController;
class InputHandler;
class KeyboardMouseGenericDeviceIntegration;
}
@@ -69,7 +68,6 @@ public:
Q_DECLARE_PUBLIC(QInputAspect)
QScopedPointer<Input::InputHandler> m_inputHandler;
- QScopedPointer<Input::CameraController> m_cameraController;
QScopedPointer<Input::KeyboardMouseGenericDeviceIntegration> m_keyboardMouseIntegration;
};