summaryrefslogtreecommitdiffstats
path: root/src/extras/defaults
diff options
context:
space:
mode:
Diffstat (limited to 'src/extras/defaults')
-rw-r--r--src/extras/defaults/defaults.pri3
-rw-r--r--src/extras/defaults/qabstractcameracontroller.cpp436
-rw-r--r--src/extras/defaults/qabstractcameracontroller.h126
-rw-r--r--src/extras/defaults/qabstractcameracontroller_p.h141
-rw-r--r--src/extras/defaults/qdiffusemapmaterial.cpp4
-rw-r--r--src/extras/defaults/qdiffusespecularmapmaterial.cpp4
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller.cpp305
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller.h39
-rw-r--r--src/extras/defaults/qfirstpersoncameracontroller_p.h152
-rw-r--r--src/extras/defaults/qmetalroughmaterial.cpp30
-rw-r--r--src/extras/defaults/qmetalroughmaterial.h4
-rw-r--r--src/extras/defaults/qmetalroughmaterial_p.h3
-rw-r--r--src/extras/defaults/qnormaldiffusemapalphamaterial.cpp8
-rw-r--r--src/extras/defaults/qnormaldiffusemapmaterial.cpp4
-rw-r--r--src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp4
-rw-r--r--src/extras/defaults/qorbitcameracontroller.cpp348
-rw-r--r--src/extras/defaults/qorbitcameracontroller.h28
-rw-r--r--src/extras/defaults/qorbitcameracontroller_p.h75
-rw-r--r--src/extras/defaults/qphongalphamaterial.cpp32
-rw-r--r--src/extras/defaults/qphongalphamaterial_p.h2
-rw-r--r--src/extras/defaults/qphongmaterial.cpp5
21 files changed, 874 insertions, 879 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri
index d3fd122ae..2575de1a3 100644
--- a/src/extras/defaults/defaults.pri
+++ b/src/extras/defaults/defaults.pri
@@ -25,6 +25,8 @@ HEADERS += \
$$PWD/qphongalphamaterial_p.h \
$$PWD/qt3dwindow.h \
$$PWD/qt3dwindow_p.h \
+ $$PWD/qabstractcameracontroller.h \
+ $$PWD/qabstractcameracontroller_p.h \
$$PWD/qfirstpersoncameracontroller.h \
$$PWD/qfirstpersoncameracontroller_p.h \
$$PWD/qorbitcameracontroller.h \
@@ -58,6 +60,7 @@ SOURCES += \
$$PWD/qgoochmaterial.cpp \
$$PWD/qphongalphamaterial.cpp \
$$PWD/qt3dwindow.cpp \
+ $$PWD/qabstractcameracontroller.cpp \
$$PWD/qfirstpersoncameracontroller.cpp \
$$PWD/qorbitcameracontroller.cpp \
$$PWD/qabstractspritesheet.cpp \
diff --git a/src/extras/defaults/qabstractcameracontroller.cpp b/src/extras/defaults/qabstractcameracontroller.cpp
new file mode 100644
index 000000000..8bf57f5fa
--- /dev/null
+++ b/src/extras/defaults/qabstractcameracontroller.cpp
@@ -0,0 +1,436 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 "qabstractcameracontroller.h"
+#include "qabstractcameracontroller_p.h"
+
+#include <Qt3DRender/QCamera>
+#include <Qt3DInput/QAxis>
+#include <Qt3DInput/QAnalogAxisInput>
+#include <Qt3DInput/QButtonAxisInput>
+#include <Qt3DInput/QAction>
+#include <Qt3DInput/QActionInput>
+#include <Qt3DInput/QLogicalDevice>
+#include <Qt3DInput/QKeyboardDevice>
+#include <Qt3DInput/QMouseDevice>
+#include <Qt3DInput/QMouseEvent>
+#include <Qt3DLogic/QFrameAction>
+#include <QtCore/QtGlobal>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DExtras {
+
+QAbstractCameraControllerPrivate::QAbstractCameraControllerPrivate()
+ : Qt3DCore::QEntityPrivate()
+ , m_camera(nullptr)
+ , m_leftMouseButtonAction(new Qt3DInput::QAction())
+ , m_middleMouseButtonAction(new Qt3DInput::QAction())
+ , m_rightMouseButtonAction(new Qt3DInput::QAction())
+ , m_altButtonAction(new Qt3DInput::QAction())
+ , m_shiftButtonAction(new Qt3DInput::QAction())
+ , m_rxAxis(new Qt3DInput::QAxis())
+ , m_ryAxis(new Qt3DInput::QAxis())
+ , m_txAxis(new Qt3DInput::QAxis())
+ , m_tyAxis(new Qt3DInput::QAxis())
+ , m_tzAxis(new Qt3DInput::QAxis())
+ , m_leftMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_middleMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_rightMouseButtonInput(new Qt3DInput::QActionInput())
+ , m_altButtonInput(new Qt3DInput::QActionInput())
+ , m_shiftButtonInput(new Qt3DInput::QActionInput())
+ , m_mouseRxInput(new Qt3DInput::QAnalogAxisInput())
+ , m_mouseRyInput(new Qt3DInput::QAnalogAxisInput())
+ , m_mouseTzXInput(new Qt3DInput::QAnalogAxisInput())
+ , m_mouseTzYInput(new Qt3DInput::QAnalogAxisInput())
+ , m_keyboardTxPosInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardTyPosInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardTzPosInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardTxNegInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardTyNegInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardTzNegInput(new Qt3DInput::QButtonAxisInput())
+ , m_keyboardDevice(new Qt3DInput::QKeyboardDevice())
+ , m_mouseDevice(new Qt3DInput::QMouseDevice())
+ , m_logicalDevice(new Qt3DInput::QLogicalDevice())
+ , m_frameAction(new Qt3DLogic::QFrameAction())
+ , m_linearSpeed(10.0f)
+ , m_lookSpeed(180.0f)
+ , m_acceleration(-1.0f)
+ , m_deceleration(-1.0f)
+ , m_sceneUp(0.0f, 1.0f, 0.0f)
+{}
+
+void QAbstractCameraControllerPrivate::init()
+{
+ //// Actions
+
+ // Left Mouse Button Action
+ m_leftMouseButtonInput->setButtons(QVector<int>() << Qt::LeftButton);
+ m_leftMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_leftMouseButtonAction->addInput(m_leftMouseButtonInput);
+
+ // Middle Mouse Button Action
+ m_middleMouseButtonInput->setButtons(QVector<int>() << Qt::MiddleButton);
+ m_middleMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_middleMouseButtonAction->addInput(m_middleMouseButtonInput);
+
+ // Right Mouse Button Action
+ m_rightMouseButtonInput->setButtons(QVector<int>() << Qt::RightButton);
+ m_rightMouseButtonInput->setSourceDevice(m_mouseDevice);
+ m_rightMouseButtonAction->addInput(m_rightMouseButtonInput);
+
+ // Alt Button Action
+ m_altButtonInput->setButtons(QVector<int>() << Qt::Key_Alt);
+ m_altButtonInput->setSourceDevice(m_keyboardDevice);
+ m_altButtonAction->addInput(m_altButtonInput);
+
+ // Shift Button Action
+ m_shiftButtonInput->setButtons(QVector<int>() << Qt::Key_Shift);
+ m_shiftButtonInput->setSourceDevice(m_keyboardDevice);
+ m_shiftButtonAction->addInput(m_shiftButtonInput);
+
+ //// Axes
+
+ // Mouse X
+ m_mouseRxInput->setAxis(Qt3DInput::QMouseDevice::X);
+ m_mouseRxInput->setSourceDevice(m_mouseDevice);
+ m_rxAxis->addInput(m_mouseRxInput);
+
+ // Mouse Y
+ m_mouseRyInput->setAxis(Qt3DInput::QMouseDevice::Y);
+ m_mouseRyInput->setSourceDevice(m_mouseDevice);
+ m_ryAxis->addInput(m_mouseRyInput);
+
+ // Mouse Wheel X
+ m_mouseTzXInput->setAxis(Qt3DInput::QMouseDevice::WheelX);
+ m_mouseTzXInput->setSourceDevice(m_mouseDevice);
+ m_tzAxis->addInput(m_mouseTzXInput);
+
+ // Mouse Wheel Y
+ m_mouseTzYInput->setAxis(Qt3DInput::QMouseDevice::WheelY);
+ m_mouseTzYInput->setSourceDevice(m_mouseDevice);
+ m_tzAxis->addInput(m_mouseTzYInput);
+
+ // Keyboard Pos Tx
+ m_keyboardTxPosInput->setButtons(QVector<int>() << Qt::Key_Right);
+ m_keyboardTxPosInput->setScale(1.0f);
+ m_keyboardTxPosInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxPosInput);
+
+ // Keyboard Pos Tz
+ m_keyboardTzPosInput->setButtons(QVector<int>() << Qt::Key_PageUp);
+ m_keyboardTzPosInput->setScale(1.0f);
+ m_keyboardTzPosInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzPosInput);
+
+ // Keyboard Pos Ty
+ m_keyboardTyPosInput->setButtons(QVector<int>() << Qt::Key_Up);
+ m_keyboardTyPosInput->setScale(1.0f);
+ m_keyboardTyPosInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyPosInput);
+
+ // Keyboard Neg Tx
+ m_keyboardTxNegInput->setButtons(QVector<int>() << Qt::Key_Left);
+ m_keyboardTxNegInput->setScale(-1.0f);
+ m_keyboardTxNegInput->setSourceDevice(m_keyboardDevice);
+ m_txAxis->addInput(m_keyboardTxNegInput);
+
+ // Keyboard Neg Tz
+ m_keyboardTzNegInput->setButtons(QVector<int>() << Qt::Key_PageDown);
+ m_keyboardTzNegInput->setScale(-1.0f);
+ m_keyboardTzNegInput->setSourceDevice(m_keyboardDevice);
+ m_tzAxis->addInput(m_keyboardTzNegInput);
+
+ // Keyboard Neg Ty
+ m_keyboardTyNegInput->setButtons(QVector<int>() << Qt::Key_Down);
+ m_keyboardTyNegInput->setScale(-1.0f);
+ m_keyboardTyNegInput->setSourceDevice(m_keyboardDevice);
+ m_tyAxis->addInput(m_keyboardTyNegInput);
+
+ //// Logical Device
+
+ m_logicalDevice->addAction(m_leftMouseButtonAction);
+ m_logicalDevice->addAction(m_middleMouseButtonAction);
+ m_logicalDevice->addAction(m_rightMouseButtonAction);
+ m_logicalDevice->addAction(m_altButtonAction);
+ m_logicalDevice->addAction(m_shiftButtonAction);
+ m_logicalDevice->addAxis(m_rxAxis);
+ m_logicalDevice->addAxis(m_ryAxis);
+ m_logicalDevice->addAxis(m_txAxis);
+ m_logicalDevice->addAxis(m_tyAxis);
+ m_logicalDevice->addAxis(m_tzAxis);
+
+ applyInputAccelerations();
+
+ Q_Q(QAbstractCameraController);
+ //// FrameAction
+
+ // Disable the logical device when the entity is disabled
+ QObject::connect(q, &Qt3DCore::QEntity::enabledChanged,
+ m_logicalDevice, &Qt3DInput::QLogicalDevice::setEnabled);
+
+ q->addComponent(m_frameAction);
+ q->addComponent(m_logicalDevice);
+}
+
+void QAbstractCameraControllerPrivate::applyInputAccelerations()
+{
+ const auto inputs = {
+ m_keyboardTxPosInput,
+ m_keyboardTyPosInput,
+ m_keyboardTzPosInput,
+ m_keyboardTxNegInput,
+ m_keyboardTyNegInput,
+ m_keyboardTzNegInput
+ };
+
+ for (auto input : inputs) {
+ input->setAcceleration(m_acceleration);
+ input->setDeceleration(m_deceleration);
+ }
+}
+
+/*!
+ \class QAbstractCameraController
+
+ \brief The QAbstractCameraController class provides basic
+ functionality for camera controllers.
+
+ \inmodule Qt3DExtras
+ \since 5.10
+
+ QAbstractCameraController sets up and handles input from keyboard,
+ mouse, and other devices. QAbstractCameraController is an abstract
+ class and cannot itself be instantiated. It provides a standard
+ interface for camera controllers.
+
+ Derived classes need only implement the frameActionTriggered()
+ method to move the camera.
+*/
+
+/*!
+ \fn void QAbstractCameraController::moveCamera(const InputState &state, float dt) = 0
+
+ This method is called whenever a frame action is triggered. Derived
+ classes must override this method to implement the camera movement
+ specific to the controller.
+
+ In the base class this is a pure virtual function.
+*/
+
+QAbstractCameraController::QAbstractCameraController(Qt3DCore::QNode *parent)
+ : QAbstractCameraController(*new QAbstractCameraControllerPrivate, parent)
+{
+}
+
+/*! \internal
+ */
+QAbstractCameraController::QAbstractCameraController(QAbstractCameraControllerPrivate &dd, Qt3DCore::QNode *parent)
+ : Qt3DCore::QEntity(dd, parent)
+{
+ Q_D(QAbstractCameraController);
+ d->init();
+
+ QObject::connect(d->m_frameAction, &Qt3DLogic::QFrameAction::triggered,
+ this, [=] (float dt) {
+ InputState state;
+
+ state.rxAxisValue = d->m_rxAxis->value();
+ state.ryAxisValue = d->m_ryAxis->value();
+ state.txAxisValue = d->m_txAxis->value();
+ state.tyAxisValue = d->m_tyAxis->value();
+ state.tzAxisValue = d->m_tzAxis->value();
+
+ state.leftMouseButtonActive = d->m_leftMouseButtonAction->isActive();
+ state.middleMouseButtonActive = d->m_middleMouseButtonAction->isActive();
+ state.rightMouseButtonActive = d->m_rightMouseButtonAction->isActive();
+
+ state.altKeyActive = d->m_altButtonAction->isActive();
+ state.shiftKeyActive = d->m_shiftButtonAction->isActive();
+
+ moveCamera(state, dt);
+ });
+}
+
+QAbstractCameraController::~QAbstractCameraController()
+{
+}
+
+/*!
+ \property QAbstractCameraController::camera
+
+ Holds the currently controlled camera.
+*/
+Qt3DRender::QCamera *QAbstractCameraController::camera() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_camera;
+}
+
+/*!
+ \property QAbstractCameraController::linearSpeed
+
+ Holds the current linear speed of the camera controller. Linear speed determines the
+ movement speed of the camera.
+
+ The default is 10.0.
+*/
+float QAbstractCameraController::linearSpeed() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_linearSpeed;
+}
+
+/*!
+ \property QAbstractCameraController::lookSpeed
+
+ Holds the current look speed of the camera controller. The look speed determines the turn rate
+ of the camera pan and tilt.
+
+ The default is 180.0.
+*/
+float QAbstractCameraController::lookSpeed() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_lookSpeed;
+}
+
+/*!
+ \property QAbstractCameraController::acceleration
+
+ Holds the current acceleration of the camera controller.
+*/
+float QAbstractCameraController::acceleration() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_acceleration;
+}
+
+/*!
+ \property QAbstractCameraController::deceleration
+
+ Holds the current deceleration of the camera controller.
+*/
+float QAbstractCameraController::deceleration() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_deceleration;
+}
+
+void QAbstractCameraController::setCamera(Qt3DRender::QCamera *camera)
+{
+ Q_D(QAbstractCameraController);
+ if (d->m_camera != camera) {
+
+ if (d->m_camera)
+ d->unregisterDestructionHelper(d->m_camera);
+
+ if (camera && !camera->parent())
+ camera->setParent(this);
+
+ d->m_camera = camera;
+
+ // Ensures proper bookkeeping
+ if (d->m_camera)
+ d->registerDestructionHelper(d->m_camera, &QAbstractCameraController::setCamera, d->m_camera);
+
+ emit cameraChanged();
+ }
+}
+
+void QAbstractCameraController::setLinearSpeed(float linearSpeed)
+{
+ Q_D(QAbstractCameraController);
+ if (d->m_linearSpeed != linearSpeed) {
+ d->m_linearSpeed = linearSpeed;
+ emit linearSpeedChanged();
+ }
+}
+
+void QAbstractCameraController::setLookSpeed(float lookSpeed)
+{
+ Q_D(QAbstractCameraController);
+ if (d->m_lookSpeed != lookSpeed) {
+ d->m_lookSpeed = lookSpeed;
+ emit lookSpeedChanged();
+ }
+}
+
+void QAbstractCameraController::setAcceleration(float acceleration)
+{
+ Q_D(QAbstractCameraController);
+ if (d->m_acceleration != acceleration) {
+ d->m_acceleration = acceleration;
+ d->applyInputAccelerations();
+ emit accelerationChanged(acceleration);
+ }
+}
+
+void QAbstractCameraController::setDeceleration(float deceleration)
+{
+ Q_D(QAbstractCameraController);
+ if (d->m_deceleration != deceleration) {
+ d->m_deceleration = deceleration;
+ d->applyInputAccelerations();
+ emit decelerationChanged(deceleration);
+ }
+}
+
+/*!
+ Provides access to the keyboard device.
+*/
+
+Qt3DInput::QKeyboardDevice *QAbstractCameraController::keyboardDevice() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_keyboardDevice;
+}
+
+/*!
+ Provides access to the mouse device.
+*/
+
+Qt3DInput::QMouseDevice *QAbstractCameraController::mouseDevice() const
+{
+ Q_D(const QAbstractCameraController);
+ return d->m_mouseDevice;
+}
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#include "moc_qabstractcameracontroller.cpp"
diff --git a/src/extras/defaults/qabstractcameracontroller.h b/src/extras/defaults/qabstractcameracontroller.h
new file mode 100644
index 000000000..f13079f5f
--- /dev/null
+++ b/src/extras/defaults/qabstractcameracontroller.h
@@ -0,0 +1,126 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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 QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
+#define QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
+
+#include <Qt3DCore/QEntity>
+#include <Qt3DExtras/qt3dextras_global.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DInput {
+class QKeyboardDevice;
+class QMouseDevice;
+}
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DExtras {
+
+class QAbstractCameraControllerPrivate;
+
+class QT3DEXTRASSHARED_EXPORT QAbstractCameraController : public Qt3DCore::QEntity
+{
+ Q_OBJECT
+ Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
+ Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
+ Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
+ Q_PROPERTY(float acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
+ Q_PROPERTY(float deceleration READ deceleration WRITE setDeceleration NOTIFY decelerationChanged)
+
+public:
+ ~QAbstractCameraController();
+
+ Qt3DRender::QCamera *camera() const;
+ float linearSpeed() const;
+ float lookSpeed() const;
+
+ float acceleration() const;
+ float deceleration() const;
+
+ void setCamera(Qt3DRender::QCamera *camera);
+ void setLinearSpeed(float linearSpeed);
+ void setLookSpeed(float lookSpeed);
+
+ void setAcceleration(float acceleration);
+ void setDeceleration(float deceleration);
+
+Q_SIGNALS:
+ void cameraChanged();
+ void linearSpeedChanged();
+ void lookSpeedChanged();
+
+ void accelerationChanged(float acceleration);
+ void decelerationChanged(float deceleration);
+
+protected:
+ explicit QAbstractCameraController(Qt3DCore::QNode *parent = nullptr);
+ QAbstractCameraController(QAbstractCameraControllerPrivate &dd, Qt3DCore::QNode *parent = nullptr);
+
+ Qt3DInput::QKeyboardDevice *keyboardDevice() const;
+ Qt3DInput::QMouseDevice *mouseDevice() const;
+
+ struct InputState
+ {
+ float rxAxisValue;
+ float ryAxisValue;
+ float txAxisValue;
+ float tyAxisValue;
+ float tzAxisValue;
+
+ bool leftMouseButtonActive;
+ bool middleMouseButtonActive;
+ bool rightMouseButtonActive;
+
+ bool altKeyActive;
+ bool shiftKeyActive;
+ };
+
+private:
+ virtual void moveCamera(const InputState &state, float dt) = 0;
+
+private:
+ Q_DECLARE_PRIVATE(QAbstractCameraController)
+};
+
+} // Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_H
diff --git a/src/extras/defaults/qabstractcameracontroller_p.h b/src/extras/defaults/qabstractcameracontroller_p.h
new file mode 100644
index 000000000..00424a55b
--- /dev/null
+++ b/src/extras/defaults/qabstractcameracontroller_p.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** 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 QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_P_H
+#define QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_P_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 <Qt3DExtras/qabstractcameracontroller.h>
+#include <QtGui/QVector3D>
+
+#include <Qt3DCore/private/qentity_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+class QCamera;
+}
+
+namespace Qt3DLogic {
+class QFrameAction;
+}
+
+namespace Qt3DInput {
+class QKeyboardDevice;
+class QMouseDevice;
+class QLogicalDevice;
+class QAction;
+class QActionInput;
+class QAxis;
+class QAnalogAxisInput;
+class QButtonAxisInput;
+class QAxisActionHandler;
+}
+
+namespace Qt3DExtras {
+
+class QAbstractCameraControllerPrivate : public Qt3DCore::QEntityPrivate
+{
+public:
+ QAbstractCameraControllerPrivate();
+
+ void init();
+ void applyInputAccelerations();
+
+ Qt3DRender::QCamera *m_camera;
+
+ Qt3DInput::QAction *m_leftMouseButtonAction;
+ Qt3DInput::QAction *m_middleMouseButtonAction;
+ Qt3DInput::QAction *m_rightMouseButtonAction;
+ Qt3DInput::QAction *m_altButtonAction;
+ Qt3DInput::QAction *m_shiftButtonAction;
+
+ Qt3DInput::QAxis *m_rxAxis;
+ Qt3DInput::QAxis *m_ryAxis;
+ Qt3DInput::QAxis *m_txAxis;
+ Qt3DInput::QAxis *m_tyAxis;
+ Qt3DInput::QAxis *m_tzAxis;
+
+ Qt3DInput::QActionInput *m_leftMouseButtonInput;
+ Qt3DInput::QActionInput *m_middleMouseButtonInput;
+ Qt3DInput::QActionInput *m_rightMouseButtonInput;
+ Qt3DInput::QActionInput *m_altButtonInput;
+ Qt3DInput::QActionInput *m_shiftButtonInput;
+
+ Qt3DInput::QAnalogAxisInput *m_mouseRxInput;
+ Qt3DInput::QAnalogAxisInput *m_mouseRyInput;
+ Qt3DInput::QAnalogAxisInput *m_mouseTzXInput;
+ Qt3DInput::QAnalogAxisInput *m_mouseTzYInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTxPosInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTyPosInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTzPosInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTxNegInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTyNegInput;
+ Qt3DInput::QButtonAxisInput *m_keyboardTzNegInput;
+
+ Qt3DInput::QKeyboardDevice *m_keyboardDevice;
+ Qt3DInput::QMouseDevice *m_mouseDevice;
+
+ Qt3DInput::QLogicalDevice *m_logicalDevice;
+
+ Qt3DLogic::QFrameAction *m_frameAction;
+
+ float m_linearSpeed;
+ float m_lookSpeed;
+
+ float m_acceleration;
+ float m_deceleration;
+
+ QVector3D m_sceneUp;
+
+ Q_DECLARE_PUBLIC(QAbstractCameraController)
+};
+
+} // namespace Qt3DExtras
+
+QT_END_NAMESPACE
+
+#endif // QT3DEXTRAS_QABSTRACTCAMERACONTROLLER_P_H
diff --git a/src/extras/defaults/qdiffusemapmaterial.cpp b/src/extras/defaults/qdiffusemapmaterial.cpp
index a6da98a2e..930fbbd1f 100644
--- a/src/extras/defaults/qdiffusemapmaterial.cpp
+++ b/src/extras/defaults/qdiffusemapmaterial.cpp
@@ -98,9 +98,9 @@ void QDiffuseMapMaterialPrivate::init()
connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
this, &QDiffuseMapMaterialPrivate::handleTextureScaleChanged);
- m_diffuseMapGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/diffusemap.vert"))));
+ m_diffuseMapGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_diffuseMapGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/diffusemap.frag"))));
- m_diffuseMapGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/diffusemap.vert"))));
+ m_diffuseMapGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
m_diffuseMapGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/diffusemap.frag"))));
m_diffuseMapGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
diff --git a/src/extras/defaults/qdiffusespecularmapmaterial.cpp b/src/extras/defaults/qdiffusespecularmapmaterial.cpp
index 615ee6305..2e98bc8e7 100644
--- a/src/extras/defaults/qdiffusespecularmapmaterial.cpp
+++ b/src/extras/defaults/qdiffusespecularmapmaterial.cpp
@@ -105,9 +105,9 @@ void QDiffuseSpecularMapMaterialPrivate::init()
connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
this, &QDiffuseSpecularMapMaterialPrivate::handleTextureScaleChanged);
- m_diffuseSpecularMapGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/diffusemap.vert"))));
+ m_diffuseSpecularMapGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_diffuseSpecularMapGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/diffusespecularmap.frag"))));
- m_diffuseSpecularMapGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/diffusemap.vert"))));
+ m_diffuseSpecularMapGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
m_diffuseSpecularMapGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/diffusespecularmap.frag"))));
m_diffuseSpecularMapGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
diff --git a/src/extras/defaults/qfirstpersoncameracontroller.cpp b/src/extras/defaults/qfirstpersoncameracontroller.cpp
index 5321bfcf2..2ad997d05 100644
--- a/src/extras/defaults/qfirstpersoncameracontroller.cpp
+++ b/src/extras/defaults/qfirstpersoncameracontroller.cpp
@@ -35,188 +35,13 @@
****************************************************************************/
#include "qfirstpersoncameracontroller.h"
-#include "qfirstpersoncameracontroller_p.h"
-#include <Qt3DInput/QAction>
-#include <Qt3DInput/QActionInput>
-#include <Qt3DInput/QAnalogAxisInput>
-#include <Qt3DInput/QAxis>
-#include <Qt3DInput/QButtonAxisInput>
-#include <Qt3DLogic/QFrameAction>
-#include <Qt3DInput/QKeyboardDevice>
-#include <Qt3DInput/QLogicalDevice>
-#include <Qt3DInput/QMouseDevice>
-#include <Qt3DInput/QMouseEvent>
#include <Qt3DRender/QCamera>
QT_BEGIN_NAMESPACE
namespace Qt3DExtras {
-QFirstPersonCameraControllerPrivate::QFirstPersonCameraControllerPrivate()
- : Qt3DCore::QEntityPrivate()
- , m_camera(nullptr)
- , m_leftMouseButtonAction(new Qt3DInput::QAction())
- , m_fineMotionAction(new Qt3DInput::QAction())
- , m_rxAxis(new Qt3DInput::QAxis())
- , m_ryAxis(new Qt3DInput::QAxis())
- , m_txAxis(new Qt3DInput::QAxis())
- , m_tyAxis(new Qt3DInput::QAxis())
- , m_tzAxis(new Qt3DInput::QAxis())
- , m_leftMouseButtonInput(new Qt3DInput::QActionInput())
- , m_fineMotionKeyInput(new Qt3DInput::QActionInput())
- , m_mouseRxInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseRyInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseTzXInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseTzYInput(new Qt3DInput::QAnalogAxisInput())
- , m_keyboardTxPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTyPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTzPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTxNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTyNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTzNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardDevice(new Qt3DInput::QKeyboardDevice())
- , m_mouseDevice(new Qt3DInput::QMouseDevice())
- , m_logicalDevice(new Qt3DInput::QLogicalDevice())
- , m_frameAction(new Qt3DLogic::QFrameAction())
- , m_linearSpeed(10.0f)
- , m_lookSpeed(180.0f)
- , m_acceleration(-1.0f)
- , m_deceleration(-1.0f)
- , m_firstPersonUp(QVector3D(0.0f, 1.0f, 0.0f))
-{}
-
-void QFirstPersonCameraControllerPrivate::init()
-{
- //// Actions
-
- // Left Mouse Button Action
- m_leftMouseButtonInput->setButtons(QVector<int>() << Qt::LeftButton);
- m_leftMouseButtonInput->setSourceDevice(m_mouseDevice);
- m_leftMouseButtonAction->addInput(m_leftMouseButtonInput);
-
- // Fine Motion Action
- m_fineMotionKeyInput->setButtons(QVector<int>() << Qt::Key_Shift);
- m_fineMotionKeyInput->setSourceDevice(m_keyboardDevice);
- m_fineMotionAction->addInput(m_fineMotionKeyInput);
-
- //// Axes
-
- // Mouse X
- m_mouseRxInput->setAxis(Qt3DInput::QMouseDevice::X);
- m_mouseRxInput->setSourceDevice(m_mouseDevice);
- m_rxAxis->addInput(m_mouseRxInput);
-
- // Mouse Y
- m_mouseRyInput->setAxis(Qt3DInput::QMouseDevice::Y);
- m_mouseRyInput->setSourceDevice(m_mouseDevice);
- m_ryAxis->addInput(m_mouseRyInput);
-
- // Mouse Wheel X
- m_mouseTzXInput->setAxis(Qt3DInput::QMouseDevice::WheelX);
- m_mouseTzXInput->setSourceDevice(m_mouseDevice);
- m_tzAxis->addInput(m_mouseTzXInput);
-
- // Mouse Wheel Y
- m_mouseTzYInput->setAxis(Qt3DInput::QMouseDevice::WheelY);
- m_mouseTzYInput->setSourceDevice(m_mouseDevice);
- m_tzAxis->addInput(m_mouseTzYInput);
-
- // Keyboard Pos Tx
- m_keyboardTxPosInput->setButtons(QVector<int>() << Qt::Key_Right);
- m_keyboardTxPosInput->setScale(1.0f);
- m_keyboardTxPosInput->setSourceDevice(m_keyboardDevice);
- m_txAxis->addInput(m_keyboardTxPosInput);
-
- // Keyboard Pos Ty
- m_keyboardTyPosInput->setButtons(QVector<int>() << Qt::Key_PageUp);
- m_keyboardTyPosInput->setScale(1.0f);
- m_keyboardTyPosInput->setSourceDevice(m_keyboardDevice);
- m_tyAxis->addInput(m_keyboardTyPosInput);
-
- // Keyboard Pos Tz
- m_keyboardTzPosInput->setButtons(QVector<int>() << Qt::Key_Up);
- m_keyboardTzPosInput->setScale(1.0f);
- m_keyboardTzPosInput->setSourceDevice(m_keyboardDevice);
- m_tzAxis->addInput(m_keyboardTzPosInput);
-
- // Keyboard Neg Tx
- m_keyboardTxNegInput->setButtons(QVector<int>() << Qt::Key_Left);
- m_keyboardTxNegInput->setScale(-1.0f);
- m_keyboardTxNegInput->setSourceDevice(m_keyboardDevice);
- m_txAxis->addInput(m_keyboardTxNegInput);
-
- // Keyboard Neg Ty
- m_keyboardTyNegInput->setButtons(QVector<int>() << Qt::Key_PageDown);
- m_keyboardTyNegInput->setScale(-1.0f);
- m_keyboardTyNegInput->setSourceDevice(m_keyboardDevice);
- m_tyAxis->addInput(m_keyboardTyNegInput);
-
- // Keyboard Neg Tz
- m_keyboardTzNegInput->setButtons(QVector<int>() << Qt::Key_Down);
- m_keyboardTzNegInput->setScale(-1.0f);
- m_keyboardTzNegInput->setSourceDevice(m_keyboardDevice);
- m_tzAxis->addInput(m_keyboardTzNegInput);
-
- //// Logical Device
-
- m_logicalDevice->addAction(m_fineMotionAction);
- m_logicalDevice->addAction(m_leftMouseButtonAction);
- m_logicalDevice->addAxis(m_rxAxis);
- m_logicalDevice->addAxis(m_ryAxis);
- m_logicalDevice->addAxis(m_txAxis);
- m_logicalDevice->addAxis(m_tyAxis);
- m_logicalDevice->addAxis(m_tzAxis);
-
- applyAccelerations();
-
- Q_Q(QFirstPersonCameraController);
- //// FrameAction
-
- QObject::connect(m_frameAction, SIGNAL(triggered(float)),
- q, SLOT(_q_onTriggered(float)));
-
- // Disable the logical device when the entity is disabled
- QObject::connect(q, &Qt3DCore::QEntity::enabledChanged,
- m_logicalDevice, &Qt3DInput::QLogicalDevice::setEnabled);
-
- q->addComponent(m_frameAction);
- q->addComponent(m_logicalDevice);
-}
-
-void QFirstPersonCameraControllerPrivate::applyAccelerations()
-{
- const auto inputs = {
- m_keyboardTxPosInput,
- m_keyboardTyPosInput,
- m_keyboardTzPosInput,
- m_keyboardTxNegInput,
- m_keyboardTyNegInput,
- m_keyboardTzNegInput
- };
-
- for (auto input : inputs) {
- input->setAcceleration(m_acceleration);
- input->setDeceleration(m_deceleration);
- }
-}
-
-void QFirstPersonCameraControllerPrivate::_q_onTriggered(float dt)
-{
- if (m_camera != nullptr) {
- m_camera->translate(QVector3D(m_txAxis->value() * m_linearSpeed,
- m_tyAxis->value() * m_linearSpeed,
- m_tzAxis->value() * m_linearSpeed) * dt);
- if (m_leftMouseButtonAction->isActive()) {
- float lookSpeed = m_lookSpeed;
- if (m_fineMotionAction->isActive())
- lookSpeed *= 0.2f;
- m_camera->pan(m_rxAxis->value() * lookSpeed * dt, m_firstPersonUp);
- m_camera->tilt(m_ryAxis->value() * lookSpeed * dt);
- }
- }
-}
-
/*!
\class Qt3DExtras::QFirstPersonCameraController
\brief The QFirstPersonCameraController class allows controlling the scene camera
@@ -251,129 +76,35 @@ void QFirstPersonCameraControllerPrivate::_q_onTriggered(float dt)
*/
QFirstPersonCameraController::QFirstPersonCameraController(Qt3DCore::QNode *parent)
- : Qt3DCore::QEntity(*new QFirstPersonCameraControllerPrivate, parent)
+ : QAbstractCameraController(parent)
{
- Q_D(QFirstPersonCameraController);
- d->init();
}
QFirstPersonCameraController::~QFirstPersonCameraController()
{
}
-/*!
- \property QFirstPersonCameraController::camera
-
- Holds the currently controlled camera.
-*/
-Qt3DRender::QCamera *QFirstPersonCameraController::camera() const
-{
- Q_D(const QFirstPersonCameraController);
- return d->m_camera;
-}
-
-/*!
- \property QFirstPersonCameraController::linearSpeed
- Holds the current linear speed of the camera controller. Linear speed determines the
- movement speed of the camera.
-*/
-float QFirstPersonCameraController::linearSpeed() const
+void QFirstPersonCameraController::moveCamera(const QAbstractCameraController::InputState &state, float dt)
{
- Q_D(const QFirstPersonCameraController);
- return d->m_linearSpeed;
-}
-
-/*!
- \property QFirstPersonCameraController::lookSpeed
-
- Holds the current look speed of the camera controller. The look speed determines the turn rate
- of the camera pan and tilt.
-*/
-float QFirstPersonCameraController::lookSpeed() const
-{
- Q_D(const QFirstPersonCameraController);
- return d->m_lookSpeed;
-}
-
-/*!
- \property QFirstPersonCameraController::acceleration
-
- Holds the current acceleration of the camera controller.
-*/
-float QFirstPersonCameraController::acceleration() const
-{
- Q_D(const QFirstPersonCameraController);
- return d->m_acceleration;
-}
-
-/*!
- \property QFirstPersonCameraController::deceleration
-
- Holds the current deceleration of the camera controller.
-*/
-float QFirstPersonCameraController::deceleration() const
-{
- Q_D(const QFirstPersonCameraController);
- return d->m_deceleration;
-}
-
-void QFirstPersonCameraController::setCamera(Qt3DRender::QCamera *camera)
-{
- Q_D(QFirstPersonCameraController);
- if (d->m_camera != camera) {
-
- if (d->m_camera)
- d->unregisterDestructionHelper(d->m_camera);
-
- if (camera && !camera->parent())
- camera->setParent(this);
-
- d->m_camera = camera;
-
- // Ensures proper bookkeeping
- if (d->m_camera)
- d->registerDestructionHelper(d->m_camera, &QFirstPersonCameraController::setCamera, d->m_camera);
-
- emit cameraChanged();
- }
-}
-
-void QFirstPersonCameraController::setLinearSpeed(float linearSpeed)
-{
- Q_D(QFirstPersonCameraController);
- if (d->m_linearSpeed != linearSpeed) {
- d->m_linearSpeed = linearSpeed;
- emit linearSpeedChanged();
- }
-}
-
-void QFirstPersonCameraController::setLookSpeed(float lookSpeed)
-{
- Q_D(QFirstPersonCameraController);
- if (d->m_lookSpeed != lookSpeed) {
- d->m_lookSpeed = lookSpeed;
- emit lookSpeedChanged();
- }
-}
+ Qt3DRender::QCamera *theCamera = camera();
+
+ if (theCamera == nullptr)
+ return;
+
+ theCamera->translate(QVector3D(state.txAxisValue * linearSpeed(),
+ state.tyAxisValue * linearSpeed(),
+ state.tzAxisValue * linearSpeed()) * dt);
+ if (state.leftMouseButtonActive) {
+ float theLookSpeed = lookSpeed();
+ if (state.shiftKeyActive) {
+ theLookSpeed *= 0.2f;
+ }
-void QFirstPersonCameraController::setAcceleration(float acceleration)
-{
- Q_D(QFirstPersonCameraController);
- if (d->m_acceleration != acceleration) {
- d->m_acceleration = acceleration;
- d->applyAccelerations();
- emit accelerationChanged(acceleration);
- }
-}
+ const QVector3D upVector(0.0f, 1.0f, 0.0f);
-void QFirstPersonCameraController::setDeceleration(float deceleration)
-{
- Q_D(QFirstPersonCameraController);
- if (d->m_deceleration != deceleration) {
- d->m_deceleration = deceleration;
- d->applyAccelerations();
- emit decelerationChanged(deceleration);
+ theCamera->pan(state.rxAxisValue * theLookSpeed * dt, upVector);
+ theCamera->tilt(state.ryAxisValue * theLookSpeed * dt);
}
}
diff --git a/src/extras/defaults/qfirstpersoncameracontroller.h b/src/extras/defaults/qfirstpersoncameracontroller.h
index 3f7a6acc4..60edf7cb8 100644
--- a/src/extras/defaults/qfirstpersoncameracontroller.h
+++ b/src/extras/defaults/qfirstpersoncameracontroller.h
@@ -37,53 +37,22 @@
#ifndef QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_H
#define QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_H
-#include <Qt3DExtras/qt3dextras_global.h>
-#include <Qt3DCore/QEntity>
+#include <Qt3DExtras/qabstractcameracontroller.h>
QT_BEGIN_NAMESPACE
-namespace Qt3DRender {
-class QCamera;
-}
-
namespace Qt3DExtras {
-class QFirstPersonCameraControllerPrivate;
-
-class QT3DEXTRASSHARED_EXPORT QFirstPersonCameraController : public Qt3DCore::QEntity
+class QT3DEXTRASSHARED_EXPORT QFirstPersonCameraController : public QAbstractCameraController
{
Q_OBJECT
- Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
- Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
- Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
- Q_PROPERTY(float acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged)
- Q_PROPERTY(float deceleration READ deceleration WRITE setDeceleration NOTIFY decelerationChanged)
+
public:
explicit QFirstPersonCameraController(Qt3DCore::QNode *parent = nullptr);
~QFirstPersonCameraController();
- Qt3DRender::QCamera *camera() const;
- float linearSpeed() const;
- float lookSpeed() const;
- float acceleration() const;
- float deceleration() const;
-
- void setCamera(Qt3DRender::QCamera *camera);
- void setLinearSpeed(float linearSpeed);
- void setLookSpeed(float lookSpeed);
- void setAcceleration(float acceleration);
- void setDeceleration(float deceleration);
-
-Q_SIGNALS:
- void cameraChanged();
- void linearSpeedChanged();
- void lookSpeedChanged();
- void accelerationChanged(float acceleration);
- void decelerationChanged(float deceleration);
-
private:
- Q_DECLARE_PRIVATE(QFirstPersonCameraController)
- Q_PRIVATE_SLOT(d_func(), void _q_onTriggered(float))
+ void moveCamera(const QAbstractCameraController::InputState &state, float dt) override;
};
} // Qt3DExtras
diff --git a/src/extras/defaults/qfirstpersoncameracontroller_p.h b/src/extras/defaults/qfirstpersoncameracontroller_p.h
deleted file mode 100644
index 48a7c7998..000000000
--- a/src/extras/defaults/qfirstpersoncameracontroller_p.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt3D module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** 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 https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_P_H
-#define QT3DEXTRAS_QFIRSTPERSONCAMERACONTROLLER_P_H
-
-#include <Qt3DExtras/qfirstpersoncameracontroller.h>
-#include <QtGui/QVector3D>
-
-#include <Qt3DCore/private/qentity_p.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.
-//
-
-QT_BEGIN_NAMESPACE
-
-namespace Qt3DRender {
-class QCamera;
-}
-
-namespace Qt3DLogic {
-class QFrameAction;
-}
-
-namespace Qt3DInput {
-
-class QKeyboardDevice;
-class QMouseDevice;
-class QLogicalDevice;
-class QAction;
-class QActionInput;
-class QAxis;
-class QAnalogAxisInput;
-class QButtonAxisInput;
-class QAxisActionHandler;
-
-}
-
-namespace Qt3DExtras {
-
-class QFirstPersonCameraControllerPrivate : public Qt3DCore::QEntityPrivate
-{
-public:
- QFirstPersonCameraControllerPrivate();
-
- void init();
- void applyAccelerations();
-
- Qt3DRender::QCamera *m_camera;
-
- Qt3DInput::QAction *m_leftMouseButtonAction;
- Qt3DInput::QAction *m_fineMotionAction;
-
- Qt3DInput::QAxis *m_rxAxis;
- Qt3DInput::QAxis *m_ryAxis;
- Qt3DInput::QAxis *m_txAxis;
- Qt3DInput::QAxis *m_tyAxis;
- Qt3DInput::QAxis *m_tzAxis;
-
- Qt3DInput::QActionInput *m_leftMouseButtonInput;
- Qt3DInput::QActionInput *m_fineMotionKeyInput;
-
- Qt3DInput::QAnalogAxisInput *m_mouseRxInput;
- Qt3DInput::QAnalogAxisInput *m_mouseRyInput;
- Qt3DInput::QAnalogAxisInput *m_mouseTzXInput;
- Qt3DInput::QAnalogAxisInput *m_mouseTzYInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTxPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTyPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTzPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTxNegInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTyNegInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTzNegInput;
-
- Qt3DInput::QKeyboardDevice *m_keyboardDevice;
- Qt3DInput::QMouseDevice *m_mouseDevice;
-
- Qt3DInput::QLogicalDevice *m_logicalDevice;
-
- Qt3DLogic::QFrameAction *m_frameAction;
-
- float m_linearSpeed;
- float m_lookSpeed;
- float m_acceleration;
- float m_deceleration;
- QVector3D m_firstPersonUp;
-
- void _q_onTriggered(float);
-
- Q_DECLARE_PUBLIC(QFirstPersonCameraController)
-};
-
-} // Qt3DInput
-
-QT_END_NAMESPACE
-
-#endif // QT3DINPUT_QFIRSTPERSONCAMERACONTROLLER_P_H
diff --git a/src/extras/defaults/qmetalroughmaterial.cpp b/src/extras/defaults/qmetalroughmaterial.cpp
index c3d59d9de..ac6117101 100644
--- a/src/extras/defaults/qmetalroughmaterial.cpp
+++ b/src/extras/defaults/qmetalroughmaterial.cpp
@@ -71,6 +71,7 @@ QMetalRoughMaterialPrivate::QMetalRoughMaterialPrivate()
, m_roughnessMapParameter(new QParameter(QStringLiteral("roughnessMap"), QVariant()))
, m_ambientOcclusionMapParameter(new QParameter(QStringLiteral("ambientOcclusionMap"), QVariant()))
, m_normalMapParameter(new QParameter(QStringLiteral("normalMap"), QVariant()))
+ , m_textureScaleParameter(new QParameter(QStringLiteral("texCoordScale"), 1.0f))
, m_environmentIrradianceParameter(new QParameter(QStringLiteral("envLight.irradiance"), m_environmentIrradianceTexture))
, m_environmentSpecularParameter(new QParameter(QStringLiteral("envLight.specular"), m_environmentSpecularTexture))
, m_metalRoughEffect(new QEffect())
@@ -107,8 +108,10 @@ void QMetalRoughMaterialPrivate::init()
q, &QMetalRoughMaterial::roughnessChanged);
QObject::connect(m_normalMapParameter, &Qt3DRender::QParameter::valueChanged,
q, &QMetalRoughMaterial::roughnessChanged);
+ connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
+ this, &QMetalRoughMaterialPrivate::handleTextureScaleChanged);
- m_metalRoughGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/metalrough.vert"))));
+ m_metalRoughGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_metalRoughGL3ShaderBuilder->setParent(q);
m_metalRoughGL3ShaderBuilder->setShaderProgram(m_metalRoughGL3Shader);
@@ -136,6 +139,7 @@ void QMetalRoughMaterialPrivate::init()
m_metalRoughEffect->addParameter(m_baseColorParameter);
m_metalRoughEffect->addParameter(m_metalnessParameter);
m_metalRoughEffect->addParameter(m_roughnessParameter);
+ m_metalRoughEffect->addParameter(m_textureScaleParameter);
// Note that even though those parameters are not exposed in the API,
// they need to be kept around for now due to a bug in some drivers/GPUs
@@ -149,6 +153,12 @@ void QMetalRoughMaterialPrivate::init()
q->setEffect(m_metalRoughEffect);
}
+void QMetalRoughMaterialPrivate::handleTextureScaleChanged(const QVariant &var)
+{
+ Q_Q(QMetalRoughMaterial);
+ emit q->textureScaleChanged(var.toFloat());
+}
+
/*!
\class Qt3DExtras::QMetalRoughMaterial
\brief The QMetalRoughMaterial provides a default implementation of PBR
@@ -249,6 +259,18 @@ QVariant QMetalRoughMaterial::normal() const
return d->m_normalMapParameter->value();
}
+/*!
+ \property QMetalRoughMaterial::textureScale
+
+ Holds the current texture scale. It is applied as a multiplier to texture
+ coordinates at render time. Defaults to 1.0.
+*/
+float QMetalRoughMaterial::textureScale() const
+{
+ Q_D(const QMetalRoughMaterial);
+ return d->m_textureScaleParameter->value().toFloat();
+}
+
void QMetalRoughMaterial::setBaseColor(const QVariant &baseColor)
{
Q_D(QMetalRoughMaterial);
@@ -348,6 +370,12 @@ void QMetalRoughMaterial::setNormal(const QVariant &normal)
d->m_metalRoughGL3ShaderBuilder->setEnabledLayers(layers);
}
+void QMetalRoughMaterial::setTextureScale(float textureScale)
+{
+ Q_D(QMetalRoughMaterial);
+ d->m_textureScaleParameter->setValue(textureScale);
+}
+
} // namespace Qt3DExtras
QT_END_NAMESPACE
diff --git a/src/extras/defaults/qmetalroughmaterial.h b/src/extras/defaults/qmetalroughmaterial.h
index 6da00ec08..400437338 100644
--- a/src/extras/defaults/qmetalroughmaterial.h
+++ b/src/extras/defaults/qmetalroughmaterial.h
@@ -62,6 +62,7 @@ class QT3DEXTRASSHARED_EXPORT QMetalRoughMaterial : public Qt3DRender::QMaterial
Q_PROPERTY(QVariant roughness READ roughness WRITE setRoughness NOTIFY roughnessChanged)
Q_PROPERTY(QVariant ambientOcclusion READ ambientOcclusion WRITE setAmbientOcclusion NOTIFY ambientOcclusionChanged REVISION 10)
Q_PROPERTY(QVariant normal READ normal WRITE setNormal NOTIFY normalChanged REVISION 10)
+ Q_PROPERTY(float textureScale READ textureScale WRITE setTextureScale NOTIFY textureScaleChanged REVISION 10)
public:
explicit QMetalRoughMaterial(Qt3DCore::QNode *parent = nullptr);
@@ -72,6 +73,7 @@ public:
QVariant roughness() const;
QVariant ambientOcclusion() const;
QVariant normal() const;
+ float textureScale() const;
public Q_SLOTS:
void setBaseColor(const QVariant &baseColor);
@@ -79,6 +81,7 @@ public Q_SLOTS:
void setRoughness(const QVariant &roughness);
void setAmbientOcclusion(const QVariant &ambientOcclusion);
void setNormal(const QVariant &normal);
+ void setTextureScale(float textureScale);
Q_SIGNALS:
void baseColorChanged(const QVariant &baseColor);
@@ -86,6 +89,7 @@ Q_SIGNALS:
void roughnessChanged(const QVariant &roughness);
void ambientOcclusionChanged(const QVariant &ambientOcclusion);
void normalChanged(const QVariant &normal);
+ void textureScaleChanged(float textureScale);
protected:
explicit QMetalRoughMaterial(QMetalRoughMaterialPrivate &dd, Qt3DCore::QNode *parent = nullptr);
diff --git a/src/extras/defaults/qmetalroughmaterial_p.h b/src/extras/defaults/qmetalroughmaterial_p.h
index 8d6cbfcad..838474490 100644
--- a/src/extras/defaults/qmetalroughmaterial_p.h
+++ b/src/extras/defaults/qmetalroughmaterial_p.h
@@ -79,6 +79,8 @@ public:
void init();
+ void handleTextureScaleChanged(const QVariant &var);
+
Qt3DRender::QAbstractTexture *m_environmentIrradianceTexture;
Qt3DRender::QAbstractTexture *m_environmentSpecularTexture;
Qt3DRender::QParameter *m_baseColorParameter;
@@ -89,6 +91,7 @@ public:
Qt3DRender::QParameter *m_roughnessMapParameter;
Qt3DRender::QParameter *m_ambientOcclusionMapParameter;
Qt3DRender::QParameter *m_normalMapParameter;
+ Qt3DRender::QParameter *m_textureScaleParameter;
Qt3DRender::QParameter *m_environmentIrradianceParameter;
Qt3DRender::QParameter *m_environmentSpecularParameter;
Qt3DRender::QEffect *m_metalRoughEffect;
diff --git a/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp b/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp
index eb6398341..dd8288683 100644
--- a/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp
+++ b/src/extras/defaults/qnormaldiffusemapalphamaterial.cpp
@@ -82,10 +82,10 @@ void QNormalDiffuseMapAlphaMaterialPrivate::init()
connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
this, &QNormalDiffuseMapMaterialPrivate::handleTextureScaleChanged);
- m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemap.vert"))));
- m_normalDiffuseGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemapalpha.frag"))));
- m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemap.vert"))));
- m_normalDiffuseGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemapalpha.frag"))));
+ m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
+ m_normalDiffuseGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemap.frag"))));
+ m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
+ m_normalDiffuseGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemap.frag"))));
m_normalDiffuseGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
m_normalDiffuseGL3Technique->graphicsApiFilter()->setMajorVersion(3);
diff --git a/src/extras/defaults/qnormaldiffusemapmaterial.cpp b/src/extras/defaults/qnormaldiffusemapmaterial.cpp
index 35cea095a..ec3bd0a22 100644
--- a/src/extras/defaults/qnormaldiffusemapmaterial.cpp
+++ b/src/extras/defaults/qnormaldiffusemapmaterial.cpp
@@ -107,9 +107,9 @@ void QNormalDiffuseMapMaterialPrivate::init()
connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
this, &QNormalDiffuseMapMaterialPrivate::handleTextureScaleChanged);
- m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemap.vert"))));
+ m_normalDiffuseGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_normalDiffuseGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemap.frag"))));
- m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemap.vert"))));
+ m_normalDiffuseGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
m_normalDiffuseGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemap.frag"))));
m_normalDiffuseGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
diff --git a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp
index c6f8ced9c..eaa1491a0 100644
--- a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp
+++ b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp
@@ -115,9 +115,9 @@ void QNormalDiffuseSpecularMapMaterialPrivate::init()
connect(m_textureScaleParameter, &Qt3DRender::QParameter::valueChanged,
this, &QNormalDiffuseSpecularMapMaterialPrivate::handleTextureScaleChanged);
- m_normalDiffuseSpecularGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusemap.vert"))));
+ m_normalDiffuseSpecularGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_normalDiffuseSpecularGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/normaldiffusespecularmap.frag"))));
- m_normalDiffuseSpecularGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusemap.vert"))));
+ m_normalDiffuseSpecularGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
m_normalDiffuseSpecularGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/normaldiffusespecularmap.frag"))));
m_normalDiffuseSpecularGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
diff --git a/src/extras/defaults/qorbitcameracontroller.cpp b/src/extras/defaults/qorbitcameracontroller.cpp
index 565a75ea1..03e9a290b 100644
--- a/src/extras/defaults/qorbitcameracontroller.cpp
+++ b/src/extras/defaults/qorbitcameracontroller.cpp
@@ -38,22 +38,15 @@
#include "qorbitcameracontroller_p.h"
#include <Qt3DRender/QCamera>
-#include <Qt3DInput/QAxis>
-#include <Qt3DInput/QAnalogAxisInput>
-#include <Qt3DInput/QButtonAxisInput>
-#include <Qt3DInput/QAction>
-#include <Qt3DInput/QActionInput>
-#include <Qt3DInput/QLogicalDevice>
-#include <Qt3DInput/QKeyboardDevice>
-#include <Qt3DInput/QMouseDevice>
-#include <Qt3DInput/QMouseEvent>
-#include <Qt3DLogic/QFrameAction>
-#include <QtCore/QtGlobal>
QT_BEGIN_NAMESPACE
namespace Qt3DExtras {
+QOrbitCameraControllerPrivate::QOrbitCameraControllerPrivate()
+ : m_zoomInLimit(2.0f)
+{}
+
/*!
\class Qt3DExtras::QOrbitCameraController
\brief The QOrbitCameraController class allows controlling the scene camera along orbital path.
@@ -99,251 +92,20 @@ namespace Qt3DExtras {
\endtable
*/
-QOrbitCameraControllerPrivate::QOrbitCameraControllerPrivate()
- : Qt3DCore::QEntityPrivate()
- , m_camera(nullptr)
- , m_leftMouseButtonAction(new Qt3DInput::QAction())
- , m_rightMouseButtonAction(new Qt3DInput::QAction())
- , m_altButtonAction(new Qt3DInput::QAction())
- , m_shiftButtonAction(new Qt3DInput::QAction())
- , m_rxAxis(new Qt3DInput::QAxis())
- , m_ryAxis(new Qt3DInput::QAxis())
- , m_txAxis(new Qt3DInput::QAxis())
- , m_tyAxis(new Qt3DInput::QAxis())
- , m_tzAxis(new Qt3DInput::QAxis())
- , m_leftMouseButtonInput(new Qt3DInput::QActionInput())
- , m_rightMouseButtonInput(new Qt3DInput::QActionInput())
- , m_altButtonInput(new Qt3DInput::QActionInput())
- , m_shiftButtonInput(new Qt3DInput::QActionInput())
- , m_mouseRxInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseRyInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseTzXInput(new Qt3DInput::QAnalogAxisInput())
- , m_mouseTzYInput(new Qt3DInput::QAnalogAxisInput())
- , m_keyboardTxPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTyPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTzPosInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTxNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTyNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardTzNegInput(new Qt3DInput::QButtonAxisInput())
- , m_keyboardDevice(new Qt3DInput::QKeyboardDevice())
- , m_mouseDevice(new Qt3DInput::QMouseDevice())
- , m_logicalDevice(new Qt3DInput::QLogicalDevice())
- , m_frameAction(new Qt3DLogic::QFrameAction())
- , m_linearSpeed(10.0f)
- , m_lookSpeed(180.0f)
- , m_zoomInLimit(2.0f)
- , m_cameraUp(QVector3D(0.0f, 1.0f, 0.0f))
-{}
-
-void QOrbitCameraControllerPrivate::init()
-{
- //// Actions
-
- // Left Mouse Button Action
- m_leftMouseButtonInput->setButtons(QVector<int>() << Qt::LeftButton);
- m_leftMouseButtonInput->setSourceDevice(m_mouseDevice);
- m_leftMouseButtonAction->addInput(m_leftMouseButtonInput);
-
- // Right Mouse Button Action
- m_rightMouseButtonInput->setButtons(QVector<int>() << Qt::RightButton);
- m_rightMouseButtonInput->setSourceDevice(m_mouseDevice);
- m_rightMouseButtonAction->addInput(m_rightMouseButtonInput);
-
- // Alt Button Action
- m_altButtonInput->setButtons(QVector<int>() << Qt::Key_Alt);
- m_altButtonInput->setSourceDevice(m_keyboardDevice);
- m_altButtonAction->addInput(m_altButtonInput);
-
- // Shift Button Action
- m_shiftButtonInput->setButtons(QVector<int>() << Qt::Key_Shift);
- m_shiftButtonInput->setSourceDevice(m_keyboardDevice);
- m_shiftButtonAction->addInput(m_shiftButtonInput);
-
- //// Axes
-
- // Mouse X
- m_mouseRxInput->setAxis(Qt3DInput::QMouseDevice::X);
- m_mouseRxInput->setSourceDevice(m_mouseDevice);
- m_rxAxis->addInput(m_mouseRxInput);
-
- // Mouse Y
- m_mouseRyInput->setAxis(Qt3DInput::QMouseDevice::Y);
- m_mouseRyInput->setSourceDevice(m_mouseDevice);
- m_ryAxis->addInput(m_mouseRyInput);
-
- // Mouse Wheel X
- m_mouseTzXInput->setAxis(Qt3DInput::QMouseDevice::WheelX);
- m_mouseTzXInput->setSourceDevice(m_mouseDevice);
- m_tzAxis->addInput(m_mouseTzXInput);
-
- // Mouse Wheel Y
- m_mouseTzYInput->setAxis(Qt3DInput::QMouseDevice::WheelY);
- m_mouseTzYInput->setSourceDevice(m_mouseDevice);
- m_tzAxis->addInput(m_mouseTzYInput);
-
- // Keyboard Pos Tx
- m_keyboardTxPosInput->setButtons(QVector<int>() << Qt::Key_Right);
- m_keyboardTxPosInput->setScale(1.0f);
- m_keyboardTxPosInput->setSourceDevice(m_keyboardDevice);
- m_txAxis->addInput(m_keyboardTxPosInput);
-
- // Keyboard Pos Tz
- m_keyboardTzPosInput->setButtons(QVector<int>() << Qt::Key_PageUp);
- m_keyboardTzPosInput->setScale(1.0f);
- m_keyboardTzPosInput->setSourceDevice(m_keyboardDevice);
- m_tzAxis->addInput(m_keyboardTzPosInput);
-
- // Keyboard Pos Ty
- m_keyboardTyPosInput->setButtons(QVector<int>() << Qt::Key_Up);
- m_keyboardTyPosInput->setScale(1.0f);
- m_keyboardTyPosInput->setSourceDevice(m_keyboardDevice);
- m_tyAxis->addInput(m_keyboardTyPosInput);
-
- // Keyboard Neg Tx
- m_keyboardTxNegInput->setButtons(QVector<int>() << Qt::Key_Left);
- m_keyboardTxNegInput->setScale(-1.0f);
- m_keyboardTxNegInput->setSourceDevice(m_keyboardDevice);
- m_txAxis->addInput(m_keyboardTxNegInput);
-
- // Keyboard Neg Tz
- m_keyboardTzNegInput->setButtons(QVector<int>() << Qt::Key_PageDown);
- m_keyboardTzNegInput->setScale(-1.0f);
- m_keyboardTzNegInput->setSourceDevice(m_keyboardDevice);
- m_tzAxis->addInput(m_keyboardTzNegInput);
-
- // Keyboard Neg Ty
- m_keyboardTyNegInput->setButtons(QVector<int>() << Qt::Key_Down);
- m_keyboardTyNegInput->setScale(-1.0f);
- m_keyboardTyNegInput->setSourceDevice(m_keyboardDevice);
- m_tyAxis->addInput(m_keyboardTyNegInput);
-
- //// Logical Device
-
- m_logicalDevice->addAction(m_leftMouseButtonAction);
- m_logicalDevice->addAction(m_rightMouseButtonAction);
- m_logicalDevice->addAction(m_altButtonAction);
- m_logicalDevice->addAction(m_shiftButtonAction);
- m_logicalDevice->addAxis(m_rxAxis);
- m_logicalDevice->addAxis(m_ryAxis);
- m_logicalDevice->addAxis(m_txAxis);
- m_logicalDevice->addAxis(m_tyAxis);
- m_logicalDevice->addAxis(m_tzAxis);
-
- Q_Q(QOrbitCameraController);
- //// FrameAction
-
- QObject::connect(m_frameAction, SIGNAL(triggered(float)),
- q, SLOT(_q_onTriggered(float)));
-
- // Disable the logical device when the entity is disabled
- QObject::connect(q, &Qt3DCore::QEntity::enabledChanged,
- m_logicalDevice, &Qt3DInput::QLogicalDevice::setEnabled);
-
- q->addComponent(m_frameAction);
- q->addComponent(m_logicalDevice);
-}
-
-float clampInputs(float input1, float input2)
-{
- float axisValue = input1 + input2;
- return (axisValue < -1) ? -1 : (axisValue > 1) ? 1 : axisValue;
-}
-
-float zoomDistance(QVector3D firstPoint, QVector3D secondPoint)
-{
- return (secondPoint - firstPoint).lengthSquared();
-}
-
-void QOrbitCameraControllerPrivate::_q_onTriggered(float dt)
-{
- if (m_camera != nullptr) {
- // Mouse input
- if (m_leftMouseButtonAction->isActive()) {
- if (m_rightMouseButtonAction->isActive()) {
- if ( zoomDistance(m_camera->position(), m_camera->viewCenter()) > m_zoomInLimit * m_zoomInLimit) {
- // Dolly up to limit
- m_camera->translate(QVector3D(0, 0, m_ryAxis->value()), m_camera->DontTranslateViewCenter);
- } else {
- m_camera->translate(QVector3D(0, 0, -0.5), m_camera->DontTranslateViewCenter);
- }
- } else {
- // Translate
- m_camera->translate(QVector3D(clampInputs(m_rxAxis->value(), m_txAxis->value()) * m_linearSpeed,
- clampInputs(m_ryAxis->value(), m_tyAxis->value()) * m_linearSpeed,
- 0) * dt);
- }
- return;
- }
- else if (m_rightMouseButtonAction->isActive()) {
- // Orbit
- m_camera->panAboutViewCenter((m_rxAxis->value() * m_lookSpeed) * dt, m_cameraUp);
- m_camera->tiltAboutViewCenter((m_ryAxis->value() * m_lookSpeed) * dt);
- }
- // Keyboard Input
- if (m_altButtonAction->isActive()) {
- // Orbit
- m_camera->panAboutViewCenter((m_txAxis->value() * m_lookSpeed) * dt, m_cameraUp);
- m_camera->tiltAboutViewCenter((m_tyAxis->value() * m_lookSpeed) * dt);
- } else if (m_shiftButtonAction->isActive()) {
- if (zoomDistance(m_camera->position(), m_camera->viewCenter()) > m_zoomInLimit * m_zoomInLimit) {
- // Dolly
- m_camera->translate(QVector3D(0, 0, m_tyAxis->value()), m_camera->DontTranslateViewCenter);
- } else {
- m_camera->translate(QVector3D(0, 0, -0.5), m_camera->DontTranslateViewCenter);
- }
- } else {
- // Translate
- m_camera->translate(QVector3D(clampInputs(m_leftMouseButtonAction->isActive() ? m_rxAxis->value() : 0, m_txAxis->value()) * m_linearSpeed,
- clampInputs(m_leftMouseButtonAction->isActive() ? m_ryAxis->value() : 0, m_tyAxis->value()) * m_linearSpeed,
- m_tzAxis->value() * m_linearSpeed) * dt);
- }
- }
-}
-
QOrbitCameraController::QOrbitCameraController(Qt3DCore::QNode *parent)
- : Qt3DCore::QEntity(*new QOrbitCameraControllerPrivate, parent)
+ : QOrbitCameraController(*new QOrbitCameraControllerPrivate, parent)
{
- Q_D(QOrbitCameraController);
- d->init();
}
-QOrbitCameraController::~QOrbitCameraController()
+/*! \internal
+ */
+QOrbitCameraController::QOrbitCameraController(QOrbitCameraControllerPrivate &dd, Qt3DCore::QNode *parent)
+ : QAbstractCameraController(dd, parent)
{
}
-/*!
- \property QOrbitCameraController::camera
-
- Holds the currently controlled camera.
-*/
-Qt3DRender::QCamera *QOrbitCameraController::camera() const
-{
- Q_D(const QOrbitCameraController);
- return d->m_camera;
-}
-
-/*!
- \property QOrbitCameraController::linearSpeed
-
- Holds the current linear speed of the camera controller. Linear speed determines the
- movement speed of the camera.
-*/
-float QOrbitCameraController::linearSpeed() const
-{
- Q_D(const QOrbitCameraController);
- return d->m_linearSpeed;
-}
-
-/*!
- \property QOrbitCameraController::lookSpeed
-
- Holds the current look speed of the camera controller. The look speed determines the turn rate
- of the camera pan and tilt.
-*/
-float QOrbitCameraController::lookSpeed() const
+QOrbitCameraController::~QOrbitCameraController()
{
- Q_D(const QOrbitCameraController);
- return d->m_lookSpeed;
}
/*!
@@ -358,51 +120,77 @@ float QOrbitCameraController::zoomInLimit() const
return d->m_zoomInLimit;
}
-void QOrbitCameraController::setCamera(Qt3DRender::QCamera *camera)
+void QOrbitCameraController::setZoomInLimit(float zoomInLimit)
{
Q_D(QOrbitCameraController);
- if (d->m_camera != camera) {
-
- if (d->m_camera)
- d->unregisterDestructionHelper(d->m_camera);
-
- if (camera && !camera->parent())
- camera->setParent(this);
-
- d->m_camera = camera;
-
- // Ensures proper bookkeeping
- if (d->m_camera)
- d->registerDestructionHelper(d->m_camera, &QOrbitCameraController::setCamera, d->m_camera);
-
- emit cameraChanged();
+ if (d->m_zoomInLimit != zoomInLimit) {
+ d->m_zoomInLimit = zoomInLimit;
+ emit zoomInLimitChanged();
}
}
-void QOrbitCameraController::setLinearSpeed(float linearSpeed)
+inline float clampInputs(float input1, float input2)
{
- Q_D(QOrbitCameraController);
- if (d->m_linearSpeed != linearSpeed) {
- d->m_linearSpeed = linearSpeed;
- emit linearSpeedChanged();
- }
+ float axisValue = input1 + input2;
+ return (axisValue < -1) ? -1 : (axisValue > 1) ? 1 : axisValue;
}
-void QOrbitCameraController::setLookSpeed(float lookSpeed)
+inline float zoomDistance(QVector3D firstPoint, QVector3D secondPoint)
{
- Q_D(QOrbitCameraController);
- if (d->m_lookSpeed != lookSpeed) {
- d->m_lookSpeed = lookSpeed;
- emit lookSpeedChanged();
- }
+ return (secondPoint - firstPoint).lengthSquared();
}
-void QOrbitCameraController::setZoomInLimit(float zoomInLimit)
+void QOrbitCameraController::moveCamera(const QAbstractCameraController::InputState &state, float dt)
{
Q_D(QOrbitCameraController);
- if (d->m_zoomInLimit != zoomInLimit) {
- d->m_zoomInLimit = zoomInLimit;
- emit zoomInLimitChanged();
+
+ Qt3DRender::QCamera *theCamera = camera();
+
+ if (theCamera == nullptr)
+ return;
+
+ const QVector3D upVector(0.0f, 1.0f, 0.0f);
+
+ // Mouse input
+ if (state.leftMouseButtonActive) {
+ if (state.rightMouseButtonActive) {
+ if ( zoomDistance(camera()->position(), theCamera->viewCenter()) > d->m_zoomInLimit * d->m_zoomInLimit) {
+ // Dolly up to limit
+ theCamera->translate(QVector3D(0, 0, state.ryAxisValue), theCamera->DontTranslateViewCenter);
+ } else {
+ theCamera->translate(QVector3D(0, 0, -0.5), theCamera->DontTranslateViewCenter);
+ }
+ } else {
+ // Translate
+ theCamera->translate(QVector3D(clampInputs(state.rxAxisValue, state.txAxisValue) * linearSpeed(),
+ clampInputs(state.ryAxisValue, state.tyAxisValue) * linearSpeed(),
+ 0) * dt);
+ }
+ return;
+ }
+ else if (state.rightMouseButtonActive) {
+ // Orbit
+ theCamera->panAboutViewCenter((state.rxAxisValue * lookSpeed()) * dt, upVector);
+ theCamera->tiltAboutViewCenter((state.ryAxisValue * lookSpeed()) * dt);
+ }
+
+ // Keyboard Input
+ if (state.altKeyActive) {
+ // Orbit
+ theCamera->panAboutViewCenter((state.txAxisValue * lookSpeed()) * dt, upVector);
+ theCamera->tiltAboutViewCenter((state.tyAxisValue * lookSpeed()) * dt);
+ } else if (state.shiftKeyActive) {
+ if (zoomDistance(camera()->position(), theCamera->viewCenter()) > d->m_zoomInLimit * d->m_zoomInLimit) {
+ // Dolly
+ theCamera->translate(QVector3D(0, 0, state.tyAxisValue), theCamera->DontTranslateViewCenter);
+ } else {
+ theCamera->translate(QVector3D(0, 0, -0.5), theCamera->DontTranslateViewCenter);
+ }
+ } else {
+ // Translate
+ theCamera->translate(QVector3D(clampInputs(state.leftMouseButtonActive ? state.rxAxisValue : 0, state.txAxisValue) * linearSpeed(),
+ clampInputs(state.leftMouseButtonActive ? state.ryAxisValue : 0, state.tyAxisValue) * linearSpeed(),
+ state.tzAxisValue * linearSpeed()) * dt);
}
}
diff --git a/src/extras/defaults/qorbitcameracontroller.h b/src/extras/defaults/qorbitcameracontroller.h
index 7cb8b3eb7..684bfddf1 100644
--- a/src/extras/defaults/qorbitcameracontroller.h
+++ b/src/extras/defaults/qorbitcameracontroller.h
@@ -37,50 +37,38 @@
#ifndef QT3DEXTRAS_QORBITCAMERACONTROLLER_H
#define QT3DEXTRAS_QORBITCAMERACONTROLLER_H
-#include <Qt3DCore/QEntity>
-#include <Qt3DExtras/qt3dextras_global.h>
+#include <Qt3DExtras/qabstractcameracontroller.h>
QT_BEGIN_NAMESPACE
-namespace Qt3DRender {
-class QCamera;
-}
-
namespace Qt3DExtras {
class QOrbitCameraControllerPrivate;
-class QT3DEXTRASSHARED_EXPORT QOrbitCameraController : public Qt3DCore::QEntity
+class QT3DEXTRASSHARED_EXPORT QOrbitCameraController : public QAbstractCameraController
{
Q_OBJECT
- Q_PROPERTY(Qt3DRender::QCamera *camera READ camera WRITE setCamera NOTIFY cameraChanged)
- Q_PROPERTY(float linearSpeed READ linearSpeed WRITE setLinearSpeed NOTIFY linearSpeedChanged)
- Q_PROPERTY(float lookSpeed READ lookSpeed WRITE setLookSpeed NOTIFY lookSpeedChanged)
Q_PROPERTY(float zoomInLimit READ zoomInLimit WRITE setZoomInLimit NOTIFY zoomInLimitChanged)
public:
explicit QOrbitCameraController(Qt3DCore::QNode *parent = nullptr);
~QOrbitCameraController();
- Qt3DRender::QCamera *camera() const;
- float linearSpeed() const;
- float lookSpeed() const;
float zoomInLimit() const;
- void setCamera(Qt3DRender::QCamera *camera);
- void setLinearSpeed(float linearSpeed);
- void setLookSpeed(float lookSpeed);
void setZoomInLimit(float zoomInLimit);
Q_SIGNALS:
- void cameraChanged();
- void linearSpeedChanged();
- void lookSpeedChanged();
void zoomInLimitChanged();
+protected:
+ QOrbitCameraController(QOrbitCameraControllerPrivate &dd, Qt3DCore::QNode *parent = nullptr);
+
+private:
+ void moveCamera(const QAbstractCameraController::InputState &state, float dt) override;
+
private:
Q_DECLARE_PRIVATE(QOrbitCameraController)
- Q_PRIVATE_SLOT(d_func(), void _q_onTriggered(float))
};
} // Qt3DExtras
diff --git a/src/extras/defaults/qorbitcameracontroller_p.h b/src/extras/defaults/qorbitcameracontroller_p.h
index 8105d4375..1e4e3d4d2 100644
--- a/src/extras/defaults/qorbitcameracontroller_p.h
+++ b/src/extras/defaults/qorbitcameracontroller_p.h
@@ -48,88 +48,25 @@
// We mean it.
//
-#include <Qt3DExtras/qorbitcameracontroller.h>
-#include <QtGui/QVector3D>
-
-#include <Qt3DCore/private/qentity_p.h>
+#include <Qt3DExtras/private/qabstractcameracontroller_p.h>
QT_BEGIN_NAMESPACE
-namespace Qt3DRender {
-class QCamera;
-}
-
-namespace Qt3DLogic {
-class QFrameAction;
-}
-
-namespace Qt3DInput {
-
-class QKeyboardDevice;
-class QMouseDevice;
-class QLogicalDevice;
-class QAction;
-class QActionInput;
-class QAxis;
-class QAnalogAxisInput;
-class QButtonAxisInput;
-class QAxisActionHandler;
-
-}
-
namespace Qt3DExtras {
-class QOrbitCameraControllerPrivate : public Qt3DCore::QEntityPrivate
+class QOrbitCameraControllerPrivate : public QAbstractCameraControllerPrivate
{
+ Q_DECLARE_PUBLIC(QOrbitCameraController)
+
public:
QOrbitCameraControllerPrivate();
void init();
- Qt3DRender::QCamera *m_camera;
-
- Qt3DInput::QAction *m_leftMouseButtonAction;
- Qt3DInput::QAction *m_rightMouseButtonAction;
- Qt3DInput::QAction *m_altButtonAction;
- Qt3DInput::QAction *m_shiftButtonAction;
-
- Qt3DInput::QAxis *m_rxAxis;
- Qt3DInput::QAxis *m_ryAxis;
- Qt3DInput::QAxis *m_txAxis;
- Qt3DInput::QAxis *m_tyAxis;
- Qt3DInput::QAxis *m_tzAxis;
-
- Qt3DInput::QActionInput *m_leftMouseButtonInput;
- Qt3DInput::QActionInput *m_rightMouseButtonInput;
- Qt3DInput::QActionInput *m_altButtonInput;
- Qt3DInput::QActionInput *m_shiftButtonInput;
-
- Qt3DInput::QAnalogAxisInput *m_mouseRxInput;
- Qt3DInput::QAnalogAxisInput *m_mouseRyInput;
- Qt3DInput::QAnalogAxisInput *m_mouseTzXInput;
- Qt3DInput::QAnalogAxisInput *m_mouseTzYInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTxPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTyPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTzPosInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTxNegInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTyNegInput;
- Qt3DInput::QButtonAxisInput *m_keyboardTzNegInput;
-
- Qt3DInput::QKeyboardDevice *m_keyboardDevice;
- Qt3DInput::QMouseDevice *m_mouseDevice;
-
- Qt3DInput::QLogicalDevice *m_logicalDevice;
-
- Qt3DLogic::QFrameAction *m_frameAction;
-
- float m_linearSpeed;
- float m_lookSpeed;
float m_zoomInLimit;
- QVector3D m_cameraUp;
- void _q_onTriggered(float);
-
- Q_DECLARE_PUBLIC(QOrbitCameraController)
+private:
+ QOrbitCameraController *q_ptr;
};
} // namespace Qt3DExtras
diff --git a/src/extras/defaults/qphongalphamaterial.cpp b/src/extras/defaults/qphongalphamaterial.cpp
index d7f054d71..fd8c52525 100644
--- a/src/extras/defaults/qphongalphamaterial.cpp
+++ b/src/extras/defaults/qphongalphamaterial.cpp
@@ -65,10 +65,9 @@ QPhongAlphaMaterialPrivate::QPhongAlphaMaterialPrivate()
: QMaterialPrivate()
, m_phongEffect(new QEffect())
, m_ambientParameter(new QParameter(QStringLiteral("ka"), QColor::fromRgbF(0.05f, 0.05f, 0.05f, 1.0f)))
- , m_diffuseParameter(new QParameter(QStringLiteral("kd"), QColor::fromRgbF(0.7f, 0.7f, 0.7f, 1.0f)))
+ , m_diffuseParameter(new QParameter(QStringLiteral("kd"), QColor::fromRgbF(0.7f, 0.7f, 0.7f, 0.5f)))
, m_specularParameter(new QParameter(QStringLiteral("ks"), QColor::fromRgbF(0.01f, 0.01f, 0.01f, 1.0f)))
, m_shininessParameter(new QParameter(QStringLiteral("shininess"), 150.0f))
- , m_alphaParameter(new QParameter(QStringLiteral("alpha"), 0.5f))
, m_phongAlphaGL3Technique(new QTechnique())
, m_phongAlphaGL2Technique(new QTechnique())
, m_phongAlphaES2Technique(new QTechnique())
@@ -95,13 +94,11 @@ void QPhongAlphaMaterialPrivate::init()
this, &QPhongAlphaMaterialPrivate::handleSpecularChanged);
connect(m_shininessParameter, &Qt3DRender::QParameter::valueChanged,
this, &QPhongAlphaMaterialPrivate::handleShininessChanged);
- connect(m_alphaParameter, &Qt3DRender::QParameter::valueChanged,
- this, &QPhongAlphaMaterialPrivate::handleAlphaChanged);
- m_phongAlphaGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.vert"))));
- m_phongAlphaGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phongalpha.frag"))));
- m_phongAlphaGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.vert"))));
- m_phongAlphaGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phongalpha.frag"))));
+ m_phongAlphaGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
+ m_phongAlphaGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.frag"))));
+ m_phongAlphaGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
+ m_phongAlphaGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.frag"))));
m_phongAlphaGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
m_phongAlphaGL3Technique->graphicsApiFilter()->setMajorVersion(3);
@@ -159,7 +156,6 @@ void QPhongAlphaMaterialPrivate::init()
m_phongEffect->addParameter(m_diffuseParameter);
m_phongEffect->addParameter(m_specularParameter);
m_phongEffect->addParameter(m_shininessParameter);
- m_phongEffect->addParameter(m_alphaParameter);
q->setEffect(m_phongEffect);
}
@@ -174,6 +170,7 @@ void QPhongAlphaMaterialPrivate::handleDiffuseChanged(const QVariant &var)
{
Q_Q(QPhongAlphaMaterial);
emit q->diffuseChanged(var.value<QColor>());
+ emit q->alphaChanged(var.value<QColor>().alphaF());
}
void QPhongAlphaMaterialPrivate::handleSpecularChanged(const QVariant &var)
@@ -188,12 +185,6 @@ void QPhongAlphaMaterialPrivate::handleShininessChanged(const QVariant &var)
emit q->shininessChanged(var.toFloat());
}
-void QPhongAlphaMaterialPrivate::handleAlphaChanged(const QVariant &var)
-{
- Q_Q(QPhongAlphaMaterial);
- emit q->alphaChanged(var.toFloat());
-}
-
/*!
\class Qt3DExtras::QPhongAlphaMaterial
@@ -301,7 +292,7 @@ float QPhongAlphaMaterial::shininess() const
float QPhongAlphaMaterial::alpha() const
{
Q_D(const QPhongAlphaMaterial);
- return d->m_alphaParameter->value().toFloat();
+ return d->m_diffuseParameter->value().value<QColor>().alphaF();
}
/*!
@@ -378,7 +369,10 @@ void QPhongAlphaMaterial::setAmbient(const QColor &ambient)
void QPhongAlphaMaterial::setDiffuse(const QColor &diffuse)
{
Q_D(QPhongAlphaMaterial);
- d->m_diffuseParameter->setValue(diffuse);
+ QColor currentDiffuse = d->m_diffuseParameter->value().value<QColor>();
+ QColor newDiffuse = diffuse;
+ newDiffuse.setAlphaF(currentDiffuse.alphaF());
+ d->m_diffuseParameter->setValue(newDiffuse);
}
void QPhongAlphaMaterial::setSpecular(const QColor &specular)
@@ -396,7 +390,9 @@ void QPhongAlphaMaterial::setShininess(float shininess)
void QPhongAlphaMaterial::setAlpha(float alpha)
{
Q_D(QPhongAlphaMaterial);
- d->m_alphaParameter->setValue(alpha);
+ QColor diffuse = d->m_diffuseParameter->value().value<QColor>();
+ diffuse.setAlphaF(alpha);
+ d->m_diffuseParameter->setValue(diffuse);
}
void QPhongAlphaMaterial::setSourceRgbArg(QBlendEquationArguments::Blending sourceRgbArg)
diff --git a/src/extras/defaults/qphongalphamaterial_p.h b/src/extras/defaults/qphongalphamaterial_p.h
index 623eca0ea..84e2eead3 100644
--- a/src/extras/defaults/qphongalphamaterial_p.h
+++ b/src/extras/defaults/qphongalphamaterial_p.h
@@ -84,14 +84,12 @@ public:
void handleDiffuseChanged(const QVariant &var);
void handleSpecularChanged(const QVariant &var);
void handleShininessChanged(const QVariant &var);
- void handleAlphaChanged(const QVariant &var);
Qt3DRender::QEffect *m_phongEffect;
Qt3DRender::QParameter *m_ambientParameter;
Qt3DRender::QParameter *m_diffuseParameter;
Qt3DRender::QParameter *m_specularParameter;
Qt3DRender::QParameter *m_shininessParameter;
- Qt3DRender::QParameter *m_alphaParameter;
Qt3DRender::QTechnique *m_phongAlphaGL3Technique;
Qt3DRender::QTechnique *m_phongAlphaGL2Technique;
Qt3DRender::QTechnique *m_phongAlphaES2Technique;
diff --git a/src/extras/defaults/qphongmaterial.cpp b/src/extras/defaults/qphongmaterial.cpp
index 449eb7351..25dbf3c85 100644
--- a/src/extras/defaults/qphongmaterial.cpp
+++ b/src/extras/defaults/qphongmaterial.cpp
@@ -89,10 +89,9 @@ void QPhongMaterialPrivate::init()
connect(m_shininessParameter, &Qt3DRender::QParameter::valueChanged,
this, &QPhongMaterialPrivate::handleShininessChanged);
-
- m_phongGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.vert"))));
+ m_phongGL3Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/default.vert"))));
m_phongGL3Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/gl3/phong.frag"))));
- m_phongGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.vert"))));
+ m_phongGL2ES2Shader->setVertexShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/default.vert"))));
m_phongGL2ES2Shader->setFragmentShaderCode(QShaderProgram::loadSource(QUrl(QStringLiteral("qrc:/shaders/es2/phong.frag"))));
m_phongGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);