diff options
author | Robert Brock <robert.brock@kdab.com> | 2016-05-06 10:42:29 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-05-15 13:44:20 +0000 |
commit | 4ecc8ae1349b0ad4d9614a3f325159f2ab199f60 (patch) | |
tree | afad7fdb7d9b02dec3117efe043bf9ef640a9a7c /tests/manual/bigscene-cpp | |
parent | 179cd0085ef6bfa5b0b7953129a3010c602db593 (diff) |
Moved bigscene-cpp example to manual test
Part of an examples cleanup
Change-Id: I125e84940ad2fe9170f83c31e2eba7b03709f4b8
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/manual/bigscene-cpp')
-rw-r--r-- | tests/manual/bigscene-cpp/bigscene-cpp.pro | 13 | ||||
-rw-r--r-- | tests/manual/bigscene-cpp/doc/src/bigscene-cpp.qdoc | 32 | ||||
-rw-r--r-- | tests/manual/bigscene-cpp/entity.cpp | 140 | ||||
-rw-r--r-- | tests/manual/bigscene-cpp/entity.h | 111 | ||||
-rw-r--r-- | tests/manual/bigscene-cpp/main.cpp | 133 |
5 files changed, 429 insertions, 0 deletions
diff --git a/tests/manual/bigscene-cpp/bigscene-cpp.pro b/tests/manual/bigscene-cpp/bigscene-cpp.pro new file mode 100644 index 000000000..5567f4e6a --- /dev/null +++ b/tests/manual/bigscene-cpp/bigscene-cpp.pro @@ -0,0 +1,13 @@ +!include( ../manual.pri ) { + error( "Couldn't find the manual.pri file!" ) +} + +QT += 3dcore 3drender 3dinput 3dextras + +SOURCES += \ + main.cpp \ + entity.cpp + +HEADERS += \ + entity.h + diff --git a/tests/manual/bigscene-cpp/doc/src/bigscene-cpp.qdoc b/tests/manual/bigscene-cpp/doc/src/bigscene-cpp.qdoc new file mode 100644 index 000000000..f0b4e7e28 --- /dev/null +++ b/tests/manual/bigscene-cpp/doc/src/bigscene-cpp.qdoc @@ -0,0 +1,32 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example bigscene-cpp + \title Qt 3D: Big Scene C++ Example + \ingroup qt3d-examples-cpp +*/ diff --git a/tests/manual/bigscene-cpp/entity.cpp b/tests/manual/bigscene-cpp/entity.cpp new file mode 100644 index 000000000..9a4ecae3b --- /dev/null +++ b/tests/manual/bigscene-cpp/entity.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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$ +** +****************************************************************************/ + +#include "entity.h" + +#include <Qt3DExtras/QCylinderMesh> +#include <Qt3DExtras/QPhongMaterial> +#include <Qt3DCore/QTransform> +#include <QMatrix4x4> + +Entity::Entity(Qt3DCore::QNode *parent) + : QEntity(parent) + , m_transform(new Qt3DCore::QTransform()) + , m_mesh(new Qt3DExtras::QCylinderMesh()) + , m_material(new Qt3DExtras::QPhongMaterial()) +{ + m_mesh->setRings(50.0f); + m_mesh->setSlices(30.0f); + m_mesh->setRadius(2.5f); + m_mesh->setLength(5.0f); + + addComponent(m_mesh); + addComponent(m_transform); + addComponent(m_material); +} + +void Entity::updateTransform() +{ + QMatrix4x4 m; + m.translate(m_position); + m.rotate(m_phi, QVector3D(1.0f, 0.0f, 0.0f)); + m.rotate(m_theta, QVector3D(0.0f, 0.0f, 1.0f)); + m_transform->setMatrix(m); +} + +float Entity::theta() const +{ + return m_theta; +} + +float Entity::phi() const +{ + return m_phi; +} + +QVector3D Entity::position() const +{ + return m_position; +} + +QColor Entity::diffuseColor() const +{ + return m_material->diffuse(); +} + +void Entity::setTheta(float theta) +{ + if (m_theta == theta) + return; + + m_theta = theta; + emit thetaChanged(theta); + updateTransform(); +} + +void Entity::setPhi(float phi) +{ + if (m_phi == phi) + return; + + m_phi = phi; + emit phiChanged(phi); + updateTransform(); +} + +void Entity::setPosition(QVector3D position) +{ + if (m_position == position) + return; + + m_position = position; + emit positionChanged(position); + updateTransform(); +} + +void Entity::setDiffuseColor(QColor diffuseColor) +{ + if (m_material->diffuse() == diffuseColor) + return; + + m_material->setDiffuse(diffuseColor); + emit diffuseColorChanged(diffuseColor); +} diff --git a/tests/manual/bigscene-cpp/entity.h b/tests/manual/bigscene-cpp/entity.h new file mode 100644 index 000000000..04dcbbcb3 --- /dev/null +++ b/tests/manual/bigscene-cpp/entity.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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 ENTITY_H +#define ENTITY_H + +#include <Qt3DCore/QEntity> +#include <QtGui/QColor> +#include <QtGui/QVector3D> + +QT_BEGIN_NAMESPACE + +namespace Qt3DCore { +class QTransform; +} + +namespace Qt3DExtras { +class QCylinderMesh; +class QPhongMaterial; +} + +QT_END_NAMESPACE + +class Entity : public Qt3DCore::QEntity +{ + Q_OBJECT + Q_PROPERTY(float theta READ theta WRITE setTheta NOTIFY thetaChanged) + Q_PROPERTY(float phi READ phi WRITE setPhi NOTIFY phiChanged) + Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(QColor diffuseColor READ diffuseColor WRITE setDiffuseColor NOTIFY diffuseColorChanged) + +public: + Entity(Qt3DCore::QNode *parent = 0); + + float theta() const; + float phi() const; + QVector3D position() const; + QColor diffuseColor() const; + +public slots: + void setTheta(float theta); + void setPhi(float phi); + void setPosition(QVector3D position); + void setDiffuseColor(QColor diffuseColor); + +signals: + void thetaChanged(float theta); + void phiChanged(float phi); + void positionChanged(QVector3D position); + void diffuseColorChanged(QColor diffuseColor); + +private: + void updateTransform(); + +private: + Qt3DCore::QTransform *m_transform; + Qt3DExtras::QCylinderMesh *m_mesh; + Qt3DExtras::QPhongMaterial *m_material; + float m_theta; + float m_phi; + QVector3D m_position; +}; + +#endif // ENTITY_H diff --git a/tests/manual/bigscene-cpp/main.cpp b/tests/manual/bigscene-cpp/main.cpp new file mode 100644 index 000000000..95b198f58 --- /dev/null +++ b/tests/manual/bigscene-cpp/main.cpp @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +#include "entity.h" + +#include <QGuiApplication> + +#include <QPropertyAnimation> +#include <QUrl> +#include <QTimer> +#include <Qt3DCore/QEntity> +#include <Qt3DRender/QCamera> +#include <Qt3DCore/QTransform> +#include <Qt3DCore/qaspectengine.h> +#include <Qt3DInput/QInputAspect> +#include <Qt3DRender/QParameter> +#include <Qt3DExtras//QCylinderMesh> +#include <Qt3DRender/QRenderAspect> +#include <Qt3DRender/QCameraSelector> +#include <Qt3DExtras/QPhongMaterial> +#include <Qt3DExtras/QForwardRenderer> +#include <qmath.h> +#include <Qt3DExtras/qt3dwindow.h> +#include <Qt3DExtras/qfirstpersoncameracontroller.h> + +using namespace Qt3DCore; +using namespace Qt3DRender; + +int main(int ac, char **av) +{ + QGuiApplication app(ac, av); + Qt3DExtras::Qt3DWindow view; + view.defaultFramegraph()->setClearColor(Qt::black); + + QEntity *root = new QEntity(); + + // Camera + QCamera *cameraEntity = view.camera(); + cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f); + cameraEntity->setPosition(QVector3D(0, 250.0f, 50.0f)); + cameraEntity->setUpVector(QVector3D(0, 1, 0)); + cameraEntity->setViewCenter(QVector3D(0, 0, 0)); + + // For camera controls + Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(root); + camController->setCamera(cameraEntity); + + const float radius = 100.0f; + const int max = 1000; + const float det = 1.0f / max; + + // Scene + for (int i = 0; i < max; i++) { + Entity *e = new Entity(); + const float angle = M_PI * 2.0f * i * det * 10.; + + e->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75)); + e->setPosition(QVector3D(radius * qCos(angle), -200.* i * det, radius * qSin(angle))); + e->setTheta(30.0f * i); + e->setPhi(45.0f * i); + + QPropertyAnimation *animX = new QPropertyAnimation(e, QByteArrayLiteral("theta")); + animX->setDuration(2400 * (i + 1)); + animX->setStartValue(QVariant::fromValue(i * 30.0f)); + animX->setEndValue(QVariant::fromValue((i + 1) * 390.0f)); + animX->setLoopCount(-1); + animX->start(); + + QPropertyAnimation *animZ = new QPropertyAnimation(e, QByteArrayLiteral("phi")); + animZ->setDuration(2400 * (i + 1)); + animZ->setStartValue(QVariant::fromValue(i * 20.0f)); + animZ->setEndValue(QVariant::fromValue((i + 1) * 380.0f)); + animZ->setLoopCount(-1); + animZ->start(); + + e->setParent(root); + } + + view.setRootEntity(root); + view.show(); + + if (app.arguments().contains(("--bench"))) + QTimer::singleShot(25 * 1000, &app, &QCoreApplication::quit); + + return app.exec(); +} |