From 5d2cbfa6535e2594fe6f9cc71d08085973b2d908 Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Tue, 16 Jun 2015 10:54:29 +0300 Subject: Documentation for basic shapes example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the documentation for the basic shapes example. Change-Id: I9a69198ddbd188ddaa7bd4ab0fae0dc2315719a9 Reviewed-by: Tomi Korpipää Reviewed-by: Sean Harmer --- .../doc/images/basicshapes-cpp-example.jpg | Bin 0 -> 65014 bytes .../qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc | 37 +++++++++++++++++++++ examples/qt3d/basicshapes-cpp/main.cpp | 7 ++-- examples/qt3d/basicshapes-cpp/scenemodifier.cpp | 11 ++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 examples/qt3d/basicshapes-cpp/doc/images/basicshapes-cpp-example.jpg (limited to 'examples') diff --git a/examples/qt3d/basicshapes-cpp/doc/images/basicshapes-cpp-example.jpg b/examples/qt3d/basicshapes-cpp/doc/images/basicshapes-cpp-example.jpg new file mode 100644 index 000000000..cdf694427 Binary files /dev/null and b/examples/qt3d/basicshapes-cpp/doc/images/basicshapes-cpp-example.jpg differ diff --git a/examples/qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc b/examples/qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc index f408bc43b..004b06817 100644 --- a/examples/qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc +++ b/examples/qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc @@ -29,4 +29,41 @@ \example basicshapes-cpp \title Qt3D: Basic Shapes C++ Example \ingroup qt3d-examples-cpp + \brief Shows four basic shapes that Qt3D offers. + + The Basic Shapes examples shows four basic shapes that Qt3D offers, a torus, + a cylinder, a cube and a sphere. The example also shows how to embed a Qt3D scene + into a widget and connect with other widgets. + + \image basicshapes-cpp-example.jpg + + As an example let's go through how to set up a torus mesh. First instantiate + the \c QTorusMesh, and then set the mesh specific parameters, that for torus are + radius, minor radius and how many rings and slices. + + \snippet basicshapes-cpp/scenemodifier.cpp 0 + + The size and position of the torus can be adjusted with transform components. + We create scale, translation and rotation components and add them into the + \c QTransform component. + + \snippet basicshapes-cpp/scenemodifier.cpp 1 + + To change the diffuse color of the mesh we create a \c QPhongMaterial and set + its diffuse color. + + \snippet basicshapes-cpp/scenemodifier.cpp 2 + + The final step is to add the torus into an entity tree, and we do that by creating + a \c QEntity with parent entity and adding the previously created mesh, material + and transform components into it. + + \snippet basicshapes-cpp/scenemodifier.cpp 3 + + You can control the visibility of the entity by defining if it has parent + or not, i.e. whether it is part of entity tree or not. + + \snippet basicshapes-cpp/scenemodifier.cpp 4 + + */ diff --git a/examples/qt3d/basicshapes-cpp/main.cpp b/examples/qt3d/basicshapes-cpp/main.cpp index dc2317948..1e122c65e 100644 --- a/examples/qt3d/basicshapes-cpp/main.cpp +++ b/examples/qt3d/basicshapes-cpp/main.cpp @@ -76,12 +76,9 @@ int main(int argc, char **argv) QApplication app(argc, argv); Window *view = new Window(); QWidget *container = QWidget::createWindowContainer(view); - QSize screenSize = view->screen()->size(); - container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); + container->setMinimumSize(QSize(200, 100)); container->setMaximumSize(screenSize); - container->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - container->setFocusPolicy(Qt::StrongFocus); QWidget *widget = new QWidget; QHBoxLayout *hLayout = new QHBoxLayout(widget); @@ -176,7 +173,7 @@ int main(int argc, char **argv) // Show window widget->show(); - widget->resize(1280, 600); + widget->resize(1200, 800); // Update the aspect ratio QSize widgetSize = container->size(); diff --git a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp index 030db1596..b5c636b0f 100644 --- a/examples/qt3d/basicshapes-cpp/scenemodifier.cpp +++ b/examples/qt3d/basicshapes-cpp/scenemodifier.cpp @@ -41,14 +41,18 @@ SceneModifier::SceneModifier(Qt3D::QEntity *rootEntity) : m_rootEntity(rootEntity) { + // Torus shape data + //! [0] m_torus = new Qt3D::QTorusMesh(); m_torus->setRadius(1.0f); m_torus->setMinorRadius(0.4f); m_torus->setRings(100); m_torus->setSlices(20); + //! [0] // TorusMesh Transform + //! [1] Qt3D::QScaleTransform *torusScale = new Qt3D::QScaleTransform(); Qt3D::QTranslateTransform *torusTranslation = new Qt3D::QTranslateTransform(); Qt3D::QRotateTransform *torusRotation = new Qt3D::QRotateTransform(); @@ -62,15 +66,20 @@ SceneModifier::SceneModifier(Qt3D::QEntity *rootEntity) torusTransforms->addTransform(torusRotation); torusTransforms->addTransform(torusTranslation); torusTransforms->addTransform(torusScale); + //! [1] + //! [2] Qt3D::QPhongMaterial *torusMaterial = new Qt3D::QPhongMaterial(); torusMaterial->setDiffuse(QColor(QRgb(0xbeb32b))); + //! [2] // Torus + //! [3] m_torusEntity = new Qt3D::QEntity(m_rootEntity); m_torusEntity->addComponent(m_torus); m_torusEntity->addComponent(torusMaterial); m_torusEntity->addComponent(torusTransforms); + //! [3] // Cylinder shape data Qt3D::QCylinderMesh *cylinder = new Qt3D::QCylinderMesh(); @@ -157,10 +166,12 @@ SceneModifier::~SceneModifier() { } +//! [4] void SceneModifier::enableTorus(bool enabled) { m_torusEntity->setParent(enabled ? m_rootEntity : Q_NULLPTR); } +//! [4] void SceneModifier::enableCylinder(bool enabled) { -- cgit v1.2.3