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 "boxentity.h"
|
2020-02-11 14:14:30 +00:00
|
|
|
#include <Qt3DRender/QGeometryRenderer>
|
2015-01-05 11:22:57 +00:00
|
|
|
|
|
|
|
#include <qmath.h>
|
|
|
|
|
|
|
|
BoxEntity::BoxEntity(QNode *parent)
|
2015-10-12 19:45:19 +00:00
|
|
|
: Qt3DCore::QEntity(parent)
|
|
|
|
, m_transform(new Qt3DCore::QTransform())
|
2016-04-11 12:58:17 +00:00
|
|
|
, m_mesh(new Qt3DExtras::QCuboidMesh())
|
|
|
|
, m_material(new Qt3DExtras::QPhongMaterial())
|
2015-01-05 11:22:57 +00:00
|
|
|
, m_angle(0.0f)
|
|
|
|
, m_radius(1.0f)
|
|
|
|
{
|
2025-06-03 21:32:40 +00:00
|
|
|
connect(m_material, SIGNAL(diffuseChanged(QColor)),
|
|
|
|
this, SIGNAL(diffuseColorChanged(QColor)));
|
2015-01-05 11:22:57 +00:00
|
|
|
m_material->setAmbient(Qt::gray);
|
|
|
|
m_material->setSpecular(Qt::white);
|
|
|
|
m_material->setShininess(150.0f);
|
|
|
|
|
|
|
|
addComponent(m_transform);
|
2020-07-30 11:03:46 +00:00
|
|
|
addComponent(m_mesh);
|
2015-01-05 11:22:57 +00:00
|
|
|
addComponent(m_material);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxEntity::setDiffuseColor(const QColor &diffuseColor)
|
|
|
|
{
|
|
|
|
m_material->setDiffuse(diffuseColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxEntity::setAngle(float arg)
|
|
|
|
{
|
|
|
|
if (m_angle == arg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_angle = arg;
|
|
|
|
emit angleChanged();
|
|
|
|
updateTransformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxEntity::setRadius(float arg)
|
|
|
|
{
|
|
|
|
if (m_radius == arg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_radius = arg;
|
|
|
|
emit radiusChanged();
|
|
|
|
updateTransformation();
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor BoxEntity::diffuseColor()
|
|
|
|
{
|
|
|
|
return m_material->diffuse();
|
|
|
|
}
|
|
|
|
|
|
|
|
float BoxEntity::angle() const
|
|
|
|
{
|
|
|
|
return m_angle;
|
|
|
|
}
|
|
|
|
|
|
|
|
float BoxEntity::radius() const
|
|
|
|
{
|
|
|
|
return m_radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BoxEntity::updateTransformation()
|
|
|
|
{
|
2015-11-07 19:02:14 +00:00
|
|
|
m_transform->setTranslation(QVector3D(qCos(m_angle) * m_radius,
|
2015-01-05 11:22:57 +00:00
|
|
|
1.0f,
|
2015-02-14 09:23:27 +00:00
|
|
|
qSin(m_angle) * m_radius));
|
2015-01-05 11:22:57 +00:00
|
|
|
}
|
|
|
|
|