blob: 5b1c572ef98148a7bbf293c51e24e4c2db3957b2 [file] [log] [blame]
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:FDL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\example basicshapes-cpp
\title Qt 3D: Basic Shapes C++ Example
\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
*/