2014-11-01 14:08:16 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
|
2016-01-25 07:49:25 +00:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-11-01 14:08:16 +00:00
|
|
|
**
|
|
|
|
** This file is part of the Qt3D module of the Qt Toolkit.
|
|
|
|
**
|
2016-01-25 07:49:25 +00:00
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2014-11-01 14:08:16 +00:00
|
|
|
** 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
|
2015-02-09 13:58:07 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-25 07:49:25 +00:00
|
|
|
** 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."
|
2014-11-01 14:08:16 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-11-07 19:02:14 +00:00
|
|
|
#include "entity.h"
|
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
#include <QGuiApplication>
|
2015-06-11 12:23:22 +00:00
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
#include <QPropertyAnimation>
|
2014-12-03 13:41:14 +00:00
|
|
|
#include <QUrl>
|
2015-01-13 11:35:21 +00:00
|
|
|
#include <QTimer>
|
2014-11-01 14:08:16 +00:00
|
|
|
#include <Qt3DCore/QEntity>
|
2016-01-15 14:09:44 +00:00
|
|
|
#include <Qt3DRender/QCamera>
|
2014-11-01 14:08:16 +00:00
|
|
|
#include <Qt3DCore/QTransform>
|
2014-10-31 10:35:45 +00:00
|
|
|
#include <Qt3DCore/qaspectengine.h>
|
2015-01-20 14:16:21 +00:00
|
|
|
#include <Qt3DInput/QInputAspect>
|
2015-10-18 08:58:19 +00:00
|
|
|
#include <Qt3DRender/QParameter>
|
2016-09-05 07:40:10 +00:00
|
|
|
#include <Qt3DExtras/QCylinderMesh>
|
2015-10-18 08:58:19 +00:00
|
|
|
#include <Qt3DRender/QRenderAspect>
|
|
|
|
#include <Qt3DRender/QCameraSelector>
|
2016-04-11 12:58:17 +00:00
|
|
|
#include <Qt3DExtras/QPhongMaterial>
|
|
|
|
#include <Qt3DExtras/QForwardRenderer>
|
2014-11-01 14:08:16 +00:00
|
|
|
#include <qmath.h>
|
2016-04-26 06:38:15 +00:00
|
|
|
#include <Qt3DExtras/qt3dwindow.h>
|
|
|
|
#include <Qt3DExtras/qfirstpersoncameracontroller.h>
|
2014-11-01 14:08:16 +00:00
|
|
|
|
2015-10-12 19:45:19 +00:00
|
|
|
using namespace Qt3DCore;
|
2015-08-31 14:14:17 +00:00
|
|
|
using namespace Qt3DRender;
|
2014-11-01 14:08:16 +00:00
|
|
|
|
|
|
|
int main(int ac, char **av)
|
|
|
|
{
|
|
|
|
QGuiApplication app(ac, av);
|
2016-04-26 06:38:15 +00:00
|
|
|
Qt3DExtras::Qt3DWindow view;
|
2016-08-11 10:21:55 +00:00
|
|
|
view.defaultFrameGraph()->setClearColor(Qt::black);
|
2016-01-17 13:54:04 +00:00
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
QEntity *root = new QEntity();
|
|
|
|
|
2017-09-10 10:49:46 +00:00
|
|
|
// Mesh
|
|
|
|
auto *mesh = new Qt3DExtras::QCylinderMesh(root);
|
|
|
|
mesh->setRings(50.0f);
|
|
|
|
mesh->setSlices(30.0f);
|
|
|
|
mesh->setRadius(2.5f);
|
|
|
|
mesh->setLength(5.0f);
|
|
|
|
|
2017-09-10 11:17:32 +00:00
|
|
|
// Material
|
|
|
|
auto phongMaterial = new Qt3DExtras::QPhongMaterial(root);
|
|
|
|
auto effect = phongMaterial->effect();
|
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
// Camera
|
2016-01-15 14:09:44 +00:00
|
|
|
QCamera *cameraEntity = view.camera();
|
2014-11-01 14:08:16 +00:00
|
|
|
cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
|
2016-01-05 08:52:37 +00:00
|
|
|
cameraEntity->setPosition(QVector3D(0, 250.0f, 50.0f));
|
2014-11-01 14:08:16 +00:00
|
|
|
cameraEntity->setUpVector(QVector3D(0, 1, 0));
|
|
|
|
cameraEntity->setViewCenter(QVector3D(0, 0, 0));
|
2016-01-15 14:09:44 +00:00
|
|
|
|
|
|
|
// For camera controls
|
2016-04-26 06:38:15 +00:00
|
|
|
Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(root);
|
2016-01-15 14:09:44 +00:00
|
|
|
camController->setCamera(cameraEntity);
|
2014-11-01 14:08:16 +00:00
|
|
|
|
2017-09-10 11:17:32 +00:00
|
|
|
const double radius = 100.0;
|
2014-11-05 12:31:21 +00:00
|
|
|
const int max = 1000;
|
2017-09-10 11:17:32 +00:00
|
|
|
const double det = 1.0 / max;
|
2015-11-07 19:02:14 +00:00
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
// Scene
|
|
|
|
for (int i = 0; i < max; i++) {
|
2017-09-10 11:17:32 +00:00
|
|
|
Entity *e = new Entity(effect, root);
|
2017-09-10 10:49:46 +00:00
|
|
|
e->addComponent(mesh);
|
2017-09-10 11:17:32 +00:00
|
|
|
const double angle = M_PI * 2.0 * double(i) * det * 10.;
|
2014-11-01 14:08:16 +00:00
|
|
|
|
2017-09-10 11:17:32 +00:00
|
|
|
e->setDiffuseColor(QColor(int(qFabs(qCos(angle)) * 255.0), 204, 75));
|
|
|
|
e->setPosition(QVector3D(float(radius * qCos(angle)),
|
|
|
|
float(-200.0 * i * det),
|
|
|
|
float(radius * qSin(angle))));
|
2015-11-07 19:02:14 +00:00
|
|
|
e->setTheta(30.0f * i);
|
|
|
|
e->setPhi(45.0f * i);
|
2014-11-01 14:08:16 +00:00
|
|
|
|
2015-11-07 19:02:14 +00:00
|
|
|
QPropertyAnimation *animX = new QPropertyAnimation(e, QByteArrayLiteral("theta"));
|
|
|
|
animX->setDuration(2400 * (i + 1));
|
2014-11-05 12:31:21 +00:00
|
|
|
animX->setStartValue(QVariant::fromValue(i * 30.0f));
|
|
|
|
animX->setEndValue(QVariant::fromValue((i + 1) * 390.0f));
|
2014-11-01 14:08:16 +00:00
|
|
|
animX->setLoopCount(-1);
|
|
|
|
animX->start();
|
|
|
|
|
2015-11-07 19:02:14 +00:00
|
|
|
QPropertyAnimation *animZ = new QPropertyAnimation(e, QByteArrayLiteral("phi"));
|
|
|
|
animZ->setDuration(2400 * (i + 1));
|
2014-11-05 12:31:21 +00:00
|
|
|
animZ->setStartValue(QVariant::fromValue(i * 20.0f));
|
|
|
|
animZ->setEndValue(QVariant::fromValue((i + 1) * 380.0f));
|
2014-11-01 14:08:16 +00:00
|
|
|
animZ->setLoopCount(-1);
|
|
|
|
animZ->start();
|
|
|
|
}
|
|
|
|
|
2015-12-28 07:12:34 +00:00
|
|
|
view.setRootEntity(root);
|
2014-11-01 14:08:16 +00:00
|
|
|
view.show();
|
2015-01-13 11:35:21 +00:00
|
|
|
|
|
|
|
if (app.arguments().contains(("--bench")))
|
|
|
|
QTimer::singleShot(25 * 1000, &app, &QCoreApplication::quit);
|
|
|
|
|
2014-11-01 14:08:16 +00:00
|
|
|
return app.exec();
|
|
|
|
}
|