summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-10-05 14:26:26 +0100
committerSean Harmer <sean.harmer@kdab.com>2017-10-05 14:26:26 +0100
commite743158b0b17335ef321c2c378bacfe2697ba5f1 (patch)
treeaadf16da9ddc60ce0b2e84c1b0777e87f9cd080e /tests
parentd4fb24c0871320667640f100b743f34f702db6cf (diff)
parent835db3b72e0f14ef80afb22dd084bfc038383481 (diff)
Merge branch '5.9' into 5.10
Conflicts: src/animation/backend/animationutils.cpp Change-Id: I6bd0d1d15da00537a0bb064fc828b2460584b8e8
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/bigscene-cpp/entity.cpp33
-rw-r--r--tests/manual/bigscene-cpp/entity.h14
-rw-r--r--tests/manual/bigscene-cpp/main.cpp30
3 files changed, 48 insertions, 29 deletions
diff --git a/tests/manual/bigscene-cpp/entity.cpp b/tests/manual/bigscene-cpp/entity.cpp
index 9a4ecae3b..876a2d171 100644
--- a/tests/manual/bigscene-cpp/entity.cpp
+++ b/tests/manual/bigscene-cpp/entity.cpp
@@ -51,22 +51,21 @@
#include "entity.h"
#include <Qt3DExtras/QCylinderMesh>
-#include <Qt3DExtras/QPhongMaterial>
+#include <Qt3DRender/QMaterial>
+#include <Qt3DRender/QParameter>
#include <Qt3DCore/QTransform>
#include <QMatrix4x4>
-Entity::Entity(Qt3DCore::QNode *parent)
+Entity::Entity(Qt3DRender::QEffect *effect, Qt3DCore::QNode *parent)
: QEntity(parent)
, m_transform(new Qt3DCore::QTransform())
- , m_mesh(new Qt3DExtras::QCylinderMesh())
- , m_material(new Qt3DExtras::QPhongMaterial())
+ , m_material(new Qt3DRender::QMaterial())
+ , m_diffuseColorParam(new Qt3DRender::QParameter())
{
- m_mesh->setRings(50.0f);
- m_mesh->setSlices(30.0f);
- m_mesh->setRadius(2.5f);
- m_mesh->setLength(5.0f);
+ m_diffuseColorParam->setName(QLatin1String("kd"));
+ m_material->addParameter(m_diffuseColorParam);
+ m_material->setEffect(effect);
- addComponent(m_mesh);
addComponent(m_transform);
addComponent(m_material);
}
@@ -97,26 +96,30 @@ QVector3D Entity::position() const
QColor Entity::diffuseColor() const
{
- return m_material->diffuse();
+ return m_diffuseColorParam->value().value<QColor>();
}
void Entity::setTheta(float theta)
{
- if (m_theta == theta)
+ if (qFuzzyCompare(m_theta, theta))
return;
m_theta = theta;
+ const bool wasBlocked = blockNotifications(true);
emit thetaChanged(theta);
+ blockNotifications(wasBlocked);
updateTransform();
}
void Entity::setPhi(float phi)
{
- if (m_phi == phi)
+ if (qFuzzyCompare(m_phi, phi))
return;
m_phi = phi;
+ const bool wasBlocked = blockNotifications(true);
emit phiChanged(phi);
+ blockNotifications(wasBlocked);
updateTransform();
}
@@ -132,9 +135,11 @@ void Entity::setPosition(QVector3D position)
void Entity::setDiffuseColor(QColor diffuseColor)
{
- if (m_material->diffuse() == diffuseColor)
+ if (m_diffuseColorParam->value().value<QColor>() == diffuseColor)
return;
- m_material->setDiffuse(diffuseColor);
+ m_diffuseColorParam->setValue(QVariant::fromValue(diffuseColor));
+ const bool wasBlocked = blockNotifications(true);
emit diffuseColorChanged(diffuseColor);
+ blockNotifications(wasBlocked);
}
diff --git a/tests/manual/bigscene-cpp/entity.h b/tests/manual/bigscene-cpp/entity.h
index 04dcbbcb3..656511cdc 100644
--- a/tests/manual/bigscene-cpp/entity.h
+++ b/tests/manual/bigscene-cpp/entity.h
@@ -61,9 +61,11 @@ namespace Qt3DCore {
class QTransform;
}
-namespace Qt3DExtras {
-class QCylinderMesh;
-class QPhongMaterial;
+namespace Qt3DRender {
+class QEffect;
+class QGeometryRenderer;
+class QMaterial;
+class QParameter;
}
QT_END_NAMESPACE
@@ -77,7 +79,7 @@ class Entity : public Qt3DCore::QEntity
Q_PROPERTY(QColor diffuseColor READ diffuseColor WRITE setDiffuseColor NOTIFY diffuseColorChanged)
public:
- Entity(Qt3DCore::QNode *parent = 0);
+ Entity(Qt3DRender::QEffect *effect, Qt3DCore::QNode *parent = 0);
float theta() const;
float phi() const;
@@ -101,8 +103,8 @@ private:
private:
Qt3DCore::QTransform *m_transform;
- Qt3DExtras::QCylinderMesh *m_mesh;
- Qt3DExtras::QPhongMaterial *m_material;
+ Qt3DRender::QMaterial *m_material;
+ Qt3DRender::QParameter *m_diffuseColorParam;
float m_theta;
float m_phi;
QVector3D m_position;
diff --git a/tests/manual/bigscene-cpp/main.cpp b/tests/manual/bigscene-cpp/main.cpp
index 791aeb19d..ef296e04d 100644
--- a/tests/manual/bigscene-cpp/main.cpp
+++ b/tests/manual/bigscene-cpp/main.cpp
@@ -81,6 +81,17 @@ int main(int ac, char **av)
QEntity *root = new QEntity();
+ // Mesh
+ auto *mesh = new Qt3DExtras::QCylinderMesh(root);
+ mesh->setRings(50.0f);
+ mesh->setSlices(30.0f);
+ mesh->setRadius(2.5f);
+ mesh->setLength(5.0f);
+
+ // Material
+ auto phongMaterial = new Qt3DExtras::QPhongMaterial(root);
+ auto effect = phongMaterial->effect();
+
// Camera
QCamera *cameraEntity = view.camera();
cameraEntity->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
@@ -92,17 +103,20 @@ int main(int ac, char **av)
Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(root);
camController->setCamera(cameraEntity);
- const float radius = 100.0f;
+ const double radius = 100.0;
const int max = 1000;
- const float det = 1.0f / max;
+ const double det = 1.0 / max;
// Scene
for (int i = 0; i < max; i++) {
- Entity *e = new Entity();
- const float angle = M_PI * 2.0f * i * det * 10.;
-
- e->setDiffuseColor(QColor(qFabs(qCos(angle)) * 255, 204, 75));
- e->setPosition(QVector3D(radius * qCos(angle), -200.* i * det, radius * qSin(angle)));
+ Entity *e = new Entity(effect, root);
+ e->addComponent(mesh);
+ const double angle = M_PI * 2.0 * double(i) * det * 10.;
+
+ 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))));
e->setTheta(30.0f * i);
e->setPhi(45.0f * i);
@@ -119,8 +133,6 @@ int main(int ac, char **av)
animZ->setEndValue(QVariant::fromValue((i + 1) * 380.0f));
animZ->setLoopCount(-1);
animZ->start();
-
- e->setParent(root);
}
view.setRootEntity(root);