From aa6371900b038199b04a7977b199098c2d2b83da Mon Sep 17 00:00:00 2001 From: Robert Brock Date: Mon, 18 Jan 2016 17:32:57 +0000 Subject: Cone and Plane added to Basic shapes Existing shapes have been moved outward to 5 and -5 x. Cone and plane were then added at x: 0 Task-number: QTBUG-41548 Change-Id: I65a3a1998b010179e4171686f71d52ce42e112ec Reviewed-by: Sean Harmer --- examples/qt3d/basicshapes-cpp/main.cpp | 19 +++++++- examples/qt3d/basicshapes-cpp/scenemodifier.cpp | 61 +++++++++++++++++++++++-- examples/qt3d/basicshapes-cpp/scenemodifier.h | 6 +++ 3 files changed, 81 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/qt3d/basicshapes-cpp/main.cpp b/examples/qt3d/basicshapes-cpp/main.cpp index 90c926ac3..4c3ea2e90 100644 --- a/examples/qt3d/basicshapes-cpp/main.cpp +++ b/examples/qt3d/basicshapes-cpp/main.cpp @@ -116,13 +116,18 @@ int main(int argc, char **argv) // Create control widgets QCommandLinkButton *info = new QCommandLinkButton(); info->setText(QStringLiteral("Qt3D ready-made meshes")); - info->setDescription(QStringLiteral("Qt3D provides several ready-made meshes, like torus, cylinder, cube and sphere.")); + info->setDescription(QString::fromLatin1("Qt3D provides several ready-made meshes, like torus, cylinder, cone, " + "cube, plane and sphere.")); info->setIconSize(QSize(0,0)); QCheckBox *torusCB = new QCheckBox(widget); torusCB->setChecked(true); torusCB->setText(QStringLiteral("Torus")); + QCheckBox *coneCB = new QCheckBox(widget); + coneCB->setChecked(true); + coneCB->setText(QStringLiteral("Cone")); + QCheckBox *cylinderCB = new QCheckBox(widget); cylinderCB->setChecked(true); cylinderCB->setText(QStringLiteral("Cylinder")); @@ -131,28 +136,40 @@ int main(int argc, char **argv) cuboidCB->setChecked(true); cuboidCB->setText(QStringLiteral("Cuboid")); + QCheckBox *planeCB = new QCheckBox(widget); + planeCB->setChecked(true); + planeCB->setText(QStringLiteral("Plane")); + QCheckBox *sphereCB = new QCheckBox(widget); sphereCB->setChecked(true); sphereCB->setText(QStringLiteral("Sphere")); vLayout->addWidget(info); vLayout->addWidget(torusCB); + vLayout->addWidget(coneCB); vLayout->addWidget(cylinderCB); vLayout->addWidget(cuboidCB); + vLayout->addWidget(planeCB); vLayout->addWidget(sphereCB); QObject::connect(torusCB, &QCheckBox::stateChanged, modifier, &SceneModifier::enableTorus); + QObject::connect(coneCB, &QCheckBox::stateChanged, + modifier, &SceneModifier::enableCone); QObject::connect(cylinderCB, &QCheckBox::stateChanged, modifier, &SceneModifier::enableCylinder); QObject::connect(cuboidCB, &QCheckBox::stateChanged, modifier, &SceneModifier::enableCuboid); + QObject::connect(planeCB, &QCheckBox::stateChanged, + modifier, &SceneModifier::enablePlane); QObject::connect(sphereCB, &QCheckBox::stateChanged, modifier, &SceneModifier::enableSphere); torusCB->setChecked(true); + coneCB->setChecked(true); cylinderCB->setChecked(true); cuboidCB->setChecked(true); + planeCB->setChecked(true); sphereCB->setChecked(true); // Show window diff --git a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp index 48977fc0b..735b724fc 100644 --- a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp +++ b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp @@ -56,7 +56,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) Qt3DCore::QTransform *torusTransform = new Qt3DCore::QTransform(); torusTransform->setScale(2.0f); torusTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(0.0f, 1.0f, 0.0f), 25.0f)); - torusTransform->setTranslation(QVector3D(4.0f, 4.0f, 0.0f)); + torusTransform->setTranslation(QVector3D(5.0f, 4.0f, 0.0f)); //! [1] //! [2] @@ -72,6 +72,29 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_torusEntity->addComponent(torusTransform); //! [3] + // Cone shape data + Qt3DRender::QConeMesh *cone = new Qt3DRender::QConeMesh(); + cone->setTopRadius(0.5); + cone->setBottomRadius(1); + cone->setLength(3); + cone->setRings(50); + cone->setSlices(20); + + // ConeMesh Transform + Qt3DCore::QTransform *coneTransform = new Qt3DCore::QTransform(); + coneTransform->setScale(1.5f); + coneTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f)); + coneTransform->setTranslation(QVector3D(0.0f, 4.0f, -1.5)); + + Qt3DRender::QPhongMaterial *coneMaterial = new Qt3DRender::QPhongMaterial(); + coneMaterial->setDiffuse(QColor(QRgb(0x928327))); + + // Cone + m_coneEntity = new Qt3DCore::QEntity(m_rootEntity); + m_coneEntity->addComponent(cone); + m_coneEntity->addComponent(coneMaterial); + m_coneEntity->addComponent(coneTransform); + // Cylinder shape data Qt3DRender::QCylinderMesh *cylinder = new Qt3DRender::QCylinderMesh(); cylinder->setRadius(1); @@ -83,7 +106,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) Qt3DCore::QTransform *cylinderTransform = new Qt3DCore::QTransform(); cylinderTransform->setScale(1.5f); cylinderTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f)); - cylinderTransform->setTranslation(QVector3D(-4.0f, 4.0f, -1.5)); + cylinderTransform->setTranslation(QVector3D(-5.0f, 4.0f, -1.5)); Qt3DRender::QPhongMaterial *cylinderMaterial = new Qt3DRender::QPhongMaterial(); cylinderMaterial->setDiffuse(QColor(QRgb(0x928327))); @@ -100,7 +123,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) // CuboidMesh Transform Qt3DCore::QTransform *cuboidTransform = new Qt3DCore::QTransform(); cuboidTransform->setScale(4.0f); - cuboidTransform->setTranslation(QVector3D(4.0f, -4.0f, 0.0f)); + cuboidTransform->setTranslation(QVector3D(5.0f, -4.0f, 0.0f)); Qt3DRender::QPhongMaterial *cuboidMaterial = new Qt3DRender::QPhongMaterial(); cuboidMaterial->setDiffuse(QColor(QRgb(0x665423))); @@ -111,6 +134,26 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) m_cuboidEntity->addComponent(cuboidMaterial); m_cuboidEntity->addComponent(cuboidTransform); + // Plane shape data + Qt3DRender::QPlaneMesh *planeMesh = new Qt3DRender::QPlaneMesh(); + planeMesh->setWidth(2); + planeMesh->setHeight(2); + + // Plane mesh transform + Qt3DCore::QTransform *planeTransform = new Qt3DCore::QTransform(); + planeTransform->setScale(1.3f); + planeTransform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1.0f, 0.0f, 0.0f), 45.0f)); + planeTransform->setTranslation(QVector3D(0.0f, -4.0f, 0.0f)); + + Qt3DRender::QPhongMaterial *planeMaterial = new Qt3DRender::QPhongMaterial(); + planeMaterial->setDiffuse(QColor(QRgb(0xa69929))); + + // Plane + m_planeEntity = new Qt3DCore::QEntity(m_rootEntity); + m_planeEntity->addComponent(planeMesh); + m_planeEntity->addComponent(planeMaterial); + m_planeEntity->addComponent(planeTransform); + // Sphere shape data Qt3DRender::QSphereMesh *sphereMesh = new Qt3DRender::QSphereMesh(); sphereMesh->setRings(20); @@ -121,7 +164,7 @@ SceneModifier::SceneModifier(Qt3DCore::QEntity *rootEntity) Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform(); sphereTransform->setScale(1.3f); - sphereTransform->setTranslation(QVector3D(-4.0f, -4.0f, 0.0f)); + sphereTransform->setTranslation(QVector3D(-5.0f, -4.0f, 0.0f)); Qt3DRender::QPhongMaterial *sphereMaterial = new Qt3DRender::QPhongMaterial(); sphereMaterial->setDiffuse(QColor(QRgb(0xa69929))); @@ -144,6 +187,11 @@ void SceneModifier::enableTorus(bool enabled) } //! [4] +void SceneModifier::enableCone(bool enabled) +{ + m_coneEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); +} + void SceneModifier::enableCylinder(bool enabled) { m_cylinderEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); @@ -154,6 +202,11 @@ void SceneModifier::enableCuboid(bool enabled) m_cuboidEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); } +void SceneModifier::enablePlane(bool enabled) +{ + m_planeEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); +} + void SceneModifier::enableSphere(bool enabled) { m_sphereEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); diff --git a/examples/qt3d/basicshapes-cpp/scenemodifier.h b/examples/qt3d/basicshapes-cpp/scenemodifier.h index 7ef8dd198..4e65222d4 100644 --- a/examples/qt3d/basicshapes-cpp/scenemodifier.h +++ b/examples/qt3d/basicshapes-cpp/scenemodifier.h @@ -43,8 +43,10 @@ #include #include +#include #include #include +#include #include #include @@ -58,16 +60,20 @@ public: public slots: void enableTorus(bool enabled); + void enableCone(bool enabled); void enableCylinder(bool enabled); void enableCuboid(bool enabled); + void enablePlane(bool enabled); void enableSphere(bool enabled); private: Qt3DCore::QEntity *m_rootEntity; Qt3DRender::QTorusMesh *m_torus; + Qt3DCore::QEntity *m_coneEntity; Qt3DCore::QEntity *m_cylinderEntity; Qt3DCore::QEntity *m_torusEntity; Qt3DCore::QEntity *m_cuboidEntity; + Qt3DCore::QEntity *m_planeEntity; Qt3DCore::QEntity *m_sphereEntity; }; -- cgit v1.2.3