summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/basicshapes-cpp/doc/src/basicshapes.qdoc
blob: d5a412a794cd13e306a9f61259586f44782fda99 (plain)
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
42
43
44
45
46
47
48
49
50
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
    \example basicshapes-cpp
    \title Qt 3D: Basic Shapes C++ Example
    \examplecategory {3D}
    \ingroup qt3d-examples-cpp
    \brief Shows four basic shapes that Qt 3D offers and sets up a mesh for each of them.

    \image basicshapes-cpp-example.jpg

    \e {Basic Shapes} shows four basic shapes that Qt 3D offers: a torus, a cylinder,
    a cube, and a sphere. The example also shows how to embed a Qt 3D scene
    into a widget and connect with other widgets.

    \include examples-run.qdocinc

    \section1 Setting Up a Torus Mesh

    As an example, we go through how to set up a torus mesh. First, we instantiate
    the \c QTorusMesh, and then we set the mesh specific parameters, which for torus are
    radius, minor radius, and the number of 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 a parent entity and adding the previously created mesh, material,
    and transform components into it.

    \snippet basicshapes-cpp/scenemodifier.cpp 3

    We can control the visibility of the entity by defining whether it has a parent
    or not. That is, whether it is part of an entity tree or not.

    \snippet basicshapes-cpp/scenemodifier.cpp 4


*/