2022-06-08 12:47:24 +00:00
|
|
|
// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
|
2024-02-23 14:41:04 +00:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
2015-01-05 11:22:57 +00:00
|
|
|
|
|
|
|
#include "examplescene.h"
|
|
|
|
#include "boxentity.h"
|
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <qmath.h>
|
|
|
|
|
2015-10-12 19:45:19 +00:00
|
|
|
ExampleScene::ExampleScene(Qt3DCore::QNode *parent)
|
|
|
|
: Qt3DCore::QEntity(parent)
|
2015-01-05 11:22:57 +00:00
|
|
|
, m_timer(new QTimer(this))
|
|
|
|
, m_even(true)
|
|
|
|
{
|
2016-04-15 14:29:58 +00:00
|
|
|
buildScene();
|
2015-01-05 11:22:57 +00:00
|
|
|
QObject::connect(m_timer, SIGNAL(timeout()), SLOT(updateScene()));
|
2015-06-09 13:34:18 +00:00
|
|
|
m_timer->setInterval(1200);
|
2015-01-05 11:22:57 +00:00
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExampleScene::~ExampleScene()
|
|
|
|
{
|
|
|
|
qDeleteAll(m_entities);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleScene::updateScene()
|
|
|
|
{
|
2016-04-15 14:29:58 +00:00
|
|
|
for (int i = 0; i < m_entities.size(); ++i) {
|
2016-09-30 12:34:48 +00:00
|
|
|
const bool visible = (i % 2) ^ static_cast<int>(m_even);
|
2016-04-15 14:29:58 +00:00
|
|
|
m_entities[i]->setParent(visible ? this : nullptr);
|
2015-01-05 11:22:57 +00:00
|
|
|
}
|
2016-04-15 14:29:58 +00:00
|
|
|
m_even = !m_even;
|
2015-01-05 11:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExampleScene::buildScene()
|
|
|
|
{
|
|
|
|
int count = 20;
|
|
|
|
const float radius = 5.0f;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
BoxEntity *entity = new BoxEntity;
|
|
|
|
const float angle = M_PI * 2.0f * float(i) / count;
|
|
|
|
entity->setAngle(angle);
|
|
|
|
entity->setRadius(radius);
|
2015-02-14 09:23:27 +00:00
|
|
|
entity->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75));
|
2015-01-05 11:22:57 +00:00
|
|
|
m_entities.append(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|