/usr/share/qt5/doc/qt3drenderer/qt3drenderer-basicshapes-cpp-example.html is in qt3d5-doc-html 5.5.1-4ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- basicshapes.qdoc -->
<title>Qt3D: Basic Shapes C++ Example | Qt3D Module 5.5</title>
<link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
<div class="main">
<div class="main-rounded">
<div class="navigationbar">
<ul>
<li>Qt 5.5</li>
<li>Qt3D Module</li>
<li>Qt3D: Basic Shapes C++ Example</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
</ul>
</div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">Running the Example</a></li>
<li class="level1"><a href="#setting-up-a-torus-mesh">Setting Up a Torus Mesh</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt3D: Basic Shapes C++ Example</h1>
<span class="subtitle"></span>
<!-- $$$basicshapes-cpp-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/basicshapes-cpp-example.jpg" alt="" /></p><p><i>Basic Shapes</i> 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.</p>
<a name="running-the-example"></a>
<h2 id="running-the-example">Running the Example</h2>
<p>To run the example from Qt Creator, open the <b>Welcome</b> mode and select the example from <b>Examples</b>. For more information, visit Building and Running an Example.</p>
<a name="setting-up-a-torus-mesh"></a>
<h2 id="setting-up-a-torus-mesh">Setting Up a Torus Mesh</h2>
<p>As an example, we go through how to set up a torus mesh. First, we instantiate the <code>QTorusMesh</code>, and then we set the mesh specific parameters, which for torus are radius, minor radius, and the number of rings and slices.</p>
<pre class="cpp">m_torus <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QTorusMesh</span>();
m_torus<span class="operator">-</span><span class="operator">></span>setRadius(<span class="number">1.0f</span>);
m_torus<span class="operator">-</span><span class="operator">></span>setMinorRadius(<span class="number">0.4f</span>);
m_torus<span class="operator">-</span><span class="operator">></span>setRings(<span class="number">100</span>);
m_torus<span class="operator">-</span><span class="operator">></span>setSlices(<span class="number">20</span>);</pre>
<p>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 <code>QTransform</code> component.</p>
<pre class="cpp">Qt3D<span class="operator">::</span><span class="type">QScaleTransform</span> <span class="operator">*</span>torusScale <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QScaleTransform</span>();
Qt3D<span class="operator">::</span><span class="type">QTranslateTransform</span> <span class="operator">*</span>torusTranslation <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QTranslateTransform</span>();
Qt3D<span class="operator">::</span><span class="type">QRotateTransform</span> <span class="operator">*</span>torusRotation <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QRotateTransform</span>();
Qt3D<span class="operator">::</span><span class="type">QTransform</span> <span class="operator">*</span>torusTransforms <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QTransform</span>();
torusScale<span class="operator">-</span><span class="operator">></span>setScale3D(QVector3D(<span class="number">2.0f</span><span class="operator">,</span> <span class="number">2.0f</span><span class="operator">,</span> <span class="number">2.0f</span>));
torusTranslation<span class="operator">-</span><span class="operator">></span>setTranslation(QVector3D(<span class="number">1.7f</span><span class="operator">,</span> <span class="number">1.7f</span><span class="operator">,</span> <span class="number">0.0f</span>));
torusRotation<span class="operator">-</span><span class="operator">></span>setAngleDeg(<span class="number">25.0f</span>);
torusRotation<span class="operator">-</span><span class="operator">></span>setAxis(QVector3D(<span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>));
torusTransforms<span class="operator">-</span><span class="operator">></span>addTransform(torusRotation);
torusTransforms<span class="operator">-</span><span class="operator">></span>addTransform(torusTranslation);
torusTransforms<span class="operator">-</span><span class="operator">></span>addTransform(torusScale);</pre>
<p>To change the diffuse color of the mesh, we create a <code>QPhongMaterial</code> and set its diffuse color.</p>
<pre class="cpp">Qt3D<span class="operator">::</span><span class="type">QPhongMaterial</span> <span class="operator">*</span>torusMaterial <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QPhongMaterial</span>();
torusMaterial<span class="operator">-</span><span class="operator">></span>setDiffuse(<span class="type">QColor</span>(<span class="type">QRgb</span>(<span class="number">0xbeb32b</span>)));</pre>
<p>The final step is to add the torus into an entity tree, and we do that by creating a <code>QEntity</code> with a parent entity and adding the previously created mesh, material, and transform components into it.</p>
<pre class="cpp">m_torusEntity <span class="operator">=</span> <span class="keyword">new</span> Qt3D<span class="operator">::</span><span class="type">QEntity</span>(m_rootEntity);
m_torusEntity<span class="operator">-</span><span class="operator">></span>addComponent(m_torus);
m_torusEntity<span class="operator">-</span><span class="operator">></span>addComponent(torusMaterial);
m_torusEntity<span class="operator">-</span><span class="operator">></span>addComponent(torusTransforms);</pre>
<p>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.</p>
<pre class="cpp"><span class="type">void</span> SceneModifier<span class="operator">::</span>enableTorus(bool enabled)
{
m_torusEntity<span class="operator">-</span><span class="operator">></span>setParent(enabled <span class="operator">?</span> m_rootEntity : Q_NULLPTR);
}</pre>
<p>Files:</p>
<ul>
<li><a href="qt3drenderer-basicshapes-cpp-scenemodifier-cpp.html">basicshapes-cpp/scenemodifier.cpp</a></li>
<li><a href="qt3drenderer-basicshapes-cpp-scenemodifier-h.html">basicshapes-cpp/scenemodifier.h</a></li>
<li><a href="qt3drenderer-basicshapes-cpp-main-cpp.html">basicshapes-cpp/main.cpp</a></li>
<li><a href="qt3drenderer-basicshapes-cpp-basicshapes-cpp-pro.html">basicshapes-cpp/basicshapes-cpp.pro</a></li>
</ul>
</div>
<!-- @@@basicshapes-cpp -->
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>
<acronym title="Copyright">©</acronym> 2015 The Qt Company Ltd.
Documentation contributions included herein are the copyrights of
their respective owners.<br> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.<br> Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property
of their respective owners. </p>
</div>
</body>
</html>
|