2022-06-08 12:47:24 +00:00
|
|
|
// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
|
2024-02-23 14:41:04 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2014-11-01 14:08:16 +00:00
|
|
|
|
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>
|
2020-02-11 14:14:30 +00:00
|
|
|
#include <Qt3DRender/QGeometryRenderer>
|
2015-10-18 08:58:19 +00:00
|
|
|
#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>
|
2020-04-09 10:52:48 +00:00
|
|
|
#include <Qt3DRender/QRenderSurfaceSelector>
|
|
|
|
#include <Qt3DRender/QCameraSelector>
|
|
|
|
#include <Qt3DRender/QViewport>
|
|
|
|
#include <Qt3DRender/QNoDraw>
|
2020-04-10 09:32:53 +00:00
|
|
|
#include <Qt3DRender/QDebugOverlay>
|
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;
|
2020-04-09 10:52:48 +00:00
|
|
|
|
|
|
|
// FrameGraph
|
|
|
|
{
|
|
|
|
QRenderSurfaceSelector *surfaceSelector = new QRenderSurfaceSelector();
|
|
|
|
QCameraSelector *cameraSelector = new Qt3DRender::QCameraSelector(surfaceSelector);
|
|
|
|
cameraSelector->setCamera(view.camera());
|
|
|
|
QClearBuffers *clearBuffers = new Qt3DRender::QClearBuffers(cameraSelector);
|
|
|
|
clearBuffers->setClearColor(QColor(Qt::gray));
|
|
|
|
clearBuffers->setBuffers(QClearBuffers::ColorDepthBuffer);
|
|
|
|
new QNoDraw(clearBuffers);
|
|
|
|
|
|
|
|
const QRectF viewports[] = {
|
|
|
|
{0.0f, 0.0f, 0.25f, 0.25f},
|
|
|
|
{0.25f, 0.0f, 0.25f, 0.25f},
|
|
|
|
{0.5f, 0.0f, 0.25f, 0.25f},
|
|
|
|
{0.75f, 0.0f, 0.25f, 0.25f},
|
|
|
|
{0.0f, 0.25f, 0.25f, 0.25f},
|
|
|
|
{0.25f, 0.25f, 0.25f, 0.25f},
|
|
|
|
{0.5f, 0.25f, 0.25f, 0.25f},
|
|
|
|
{0.75f, 0.25f, 0.25f, 0.25f},
|
|
|
|
{0.0f, 0.5f, 0.25f, 0.25f},
|
|
|
|
{0.25f, 0.5f, 0.25f, 0.25f},
|
|
|
|
{0.5f, 0.5f, 0.25f, 0.25f},
|
|
|
|
{0.75f, 0.5f, 0.25f, 0.25f},
|
|
|
|
{0.0f, 0.75f, 0.25f, 0.25f},
|
|
|
|
{0.25f, 0.75f, 0.25f, 0.25f},
|
|
|
|
{0.5f, 0.75f, 0.25f, 0.25f},
|
|
|
|
{0.75f, 0.75f, 0.25f, 0.25f},
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const QRectF &vp : viewports) {
|
|
|
|
QViewport *viewport = new Qt3DRender::QViewport(cameraSelector);
|
|
|
|
viewport->setNormalizedRect(vp);
|
|
|
|
}
|
|
|
|
|
2020-04-10 09:32:53 +00:00
|
|
|
new QDebugOverlay(qobject_cast<Qt3DCore::QNode *>(cameraSelector->children().last()));
|
|
|
|
|
2020-04-09 10:52:48 +00:00
|
|
|
view.setActiveFrameGraph(surfaceSelector);
|
|
|
|
}
|
|
|
|
|
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);
|
2020-07-30 11:03: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();
|
|
|
|
}
|