forked from gpiasenza/Qt3DTests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityWrapper.cpp
More file actions
41 lines (34 loc) · 990 Bytes
/
EntityWrapper.cpp
File metadata and controls
41 lines (34 loc) · 990 Bytes
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
#include "EntityWrapper.h"
#include <Qt3DCore/QComponent>
#include <Qt3DCore/QEntity>
#include <Qt3DCore/QTransform>
#include <Qt3DExtras/QPhongMaterial>
EntityWrapper::EntityWrapper(Qt3DCore::QEntity *entity)
{
this->entity = entity;
for(auto comp: entity->components())
{
if(!transform)
transform = qobject_cast<Qt3DCore::QTransform *>(comp);
if(!mat)
mat = qobject_cast<Qt3DExtras::QPhongMaterial *>(comp);
}
for(auto childNode: entity->childNodes())
{
auto childEntity = qobject_cast<Qt3DCore::QEntity *>(childNode);
if (childEntity)
children.push_back(new EntityWrapper(childEntity));
}
}
void EntityWrapper::Move(double x, double y, double z)
{
if(transform)
transform->setTranslation(QVector3D(x, y, z));
}
void EntityWrapper::setSpecular(const QColor &col)
{
if(mat)
mat->setSpecular(col);
for(auto child: children)
child->setSpecular(col);
}