blob: b9491e9d9d44487d868d1ee03013c183710bfb76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include "examplescene.h"
#include "boxentity.h"
#include <QTimer>
#include <qmath.h>
ExampleScene::ExampleScene(Qt3DCore::QNode *parent)
: Qt3DCore::QEntity(parent)
, m_timer(new QTimer(this))
, m_even(true)
{
buildScene();
QObject::connect(m_timer, SIGNAL(timeout()), SLOT(updateScene()));
m_timer->setInterval(1200);
m_timer->start();
}
ExampleScene::~ExampleScene()
{
qDeleteAll(m_entities);
}
void ExampleScene::updateScene()
{
for (int i = 0; i < m_entities.size(); ++i) {
const bool visible = (i % 2) ^ static_cast<int>(m_even);
m_entities[i]->setParent(visible ? this : nullptr);
}
m_even = !m_even;
}
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);
entity->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75));
m_entities.append(entity);
}
}
|