Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-release > by-pkgid > c936229ef0138f42857f36beadbeda30 > files > 501

qt3d5-doc-5.12.2-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- planets-qml.qdoc -->
  <title>Qt 3D: Planets QML Example | Qt 3D 5.12.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qt3d-index.html">Qt 3D</a></td><td >Qt 3D: Planets QML Example</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qt3d-index.html">Qt 5.12.2 Reference Documentation</a></td>
        </tr></table>
      </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="#qt-quick-2d-implementation">Qt Quick 2D Implementation</a></li>
<li class="level1"><a href="#qt-3d-implementation">Qt 3D Implementation</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt 3D: Planets QML Example</h1>
<span class="subtitle"></span>
<!-- $$$planets-qml-brief -->
<p>Demonstrates combining Qt 3D rendering and Qt Quick 2 elements.</p>
<!-- @@@planets-qml -->
<!-- $$$planets-qml-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/planets-qml-example.jpg" alt="" /></p><p><i>Planets</i> demonstrates how to implement an application that combines the use of Qt 3D rendering with Qt Quick 2D elements. The example shows the eight planets of our Solar System with the Sun.</p>
<p>Planet texture maps are Copyright (c) by James Hastings-Trew <a href="http://planetpixelemporium.com/planets.html">http://planetpixelemporium.com/planets.html</a> used with permission.</p>
<p>The planets are rotating around the Sun based on their orbit at a given time. The rotation starts at 2000 Jan 0.0 UT. The planet positions are calculated based on the formulas found here: <a href="http://www.stjarnhimlen.se/comp/ppcomp.html">http://www.stjarnhimlen.se/comp/ppcomp.html</a> and <a href="http://www.davidcolarusso.com/astro/">http://www.davidcolarusso.com/astro/</a>.</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="qt-quick-2d-implementation"></a>
<h2 id="qt-quick-2d-implementation">Qt Quick 2D Implementation</h2>
<p>The Qt Quick Implementation <a href="qt3d-planets-qml-planetsmain-qml.html">PlanetsMain.qml</a> of the example renders the 3D content using the <code>Scene3D</code> type.</p>
<pre class="qml">

  Scene3D {
      anchors.fill: parent
      aspects: ["render", "logic", "input"]

      SolarSystem { id: solarsystem }
  }

</pre>
<p>The planet related information is stored into a <code>ListModel</code>. The selection buttons for the planets and the information sheet are created based on the model. The 2D elements, selection buttons and sliders, are implemented in the <a href="qt3d-planets-qml-planetsmain-qml.html">PlanetsMain.qml</a>.</p>
<p>The selection buttons change the <code>focusedPlanet</code> property of the <code>mainview</code>. As the property changes, the planet information is updated, and the camera is animated to the new position.</p>
<pre class="qml">

  onFocusedPlanetChanged: {
      if (focusedPlanet == 100) {
          info.opacity = 0
          updatePlanetInfo()
      } else {
          updatePlanetInfo()
          info.opacity = 1
      }

      solarsystem.changePlanetFocus(oldPlanet, focusedPlanet)
      oldPlanet = focusedPlanet
  }

</pre>
<p>The camera position and the camera look at point are updated based on values that are animated in the <a href="qt3d-planets-qml-solarsystem-qml.html">SolarSystem.qml</a>, triggered from the <code>changePlanetFocus()</code> function.</p>
<pre class="qml">

  QQ2.NumberAnimation {
      id: lookAtOffsetAnimation
      target: sceneRoot
      properties: "xLookAtOffset, yLookAtOffset, zLookAtOffset"
      to: 0
      easing.type: Easing.InOutQuint
      duration: 1250
  }

  QQ2.NumberAnimation {
      id: cameraOffsetAnimation
      target: sceneRoot
      properties: "xCameraOffset, yCameraOffset, zCameraOffset"
      to: 0
      easing.type: Easing.InOutQuint
      duration: 2500
  }

</pre>
<p>The sliders are used to adjust the rotation speed, the planet size, and the viewing distance. When a slider value changes, a JavaScript function in <a href="qt3d-planets-qml-solarsystem-qml.html">SolarSystem.qml</a> is called to adjust the given property. For example, changing the value of the <i>Viewing Distance</i> slider calls the <code>changeCameraDistance()</code> method.</p>
<pre class="qml">

  onValueChanged: solarsystem.changeCameraDistance(value)

</pre>
<a name="qt-3d-implementation"></a>
<h2 id="qt-3d-implementation">Qt 3D Implementation</h2>
<p>The main part of the implementation, including the movement and rotation maths for the planets, is done in the <a href="qt3d-planets-qml-solarsystem-qml.html">SolarSystem.qml</a>.</p>
<p>First, a <code>Camera</code>, a <code>Light</code>, and a <code>Configuration</code> are added, followed by <code>Effect</code>s for the planet <code>Material</code>s, and finally the planets themselves. For example, Earth is constructed as follows:</p>
<pre class="qml">

  Entity {
      id: earthEntity

      Planet {
          id: earth
          tilt: planetData[Planets.EARTH].tilt
      }

      PlanetMaterial {
          id: materialEarth
          effect: effectDSB
          ambientLight: ambientStrengthPlanet
          diffuseMap: "qrc:/images/solarsystemscope/earthmap2k.jpg"
          specularMap: "qrc:/images/solarsystemscope/earthspec2k.jpg"
          normalMap: "qrc:/images/solarsystemscope/earthnormal2k.jpg"
          shininess: shininessSpecularMap
      }

      property Transform transformEarth: Transform {
          matrix: {
              var m = Qt.matrix4x4()
              m.translate(Qt.vector3d(earth.x, earth.y, earth.z))
              m.rotate(earth.tilt, tiltAxis)
              m.rotate(earth.roll, rollAxis)
              m.scale(earth.r)
              return m
          }
      }

      components: [ earth, materialEarth, transformEarth ]
  }

</pre>
<p>Planet data, which is needed for the movement and rotation calculations, among other things, is constructed with JavaScript in <a href="qt3d-planets-qml-planets-js.html">planets.js</a> by calling <code>loadPlanetData()</code> as the component completes. Other initializations, such as inserting the planets into an array for easier handling, calculating the ring radii for Saturn and Uranus rings, and setting the default scale, speed, and camera offset, are done as well:</p>
<pre class="qml">

  QQ2.Component.onCompleted: {
      planetData = Planets.loadPlanetData()
      // Push in the correct order
      planets.push(sun)
      planets.push(mercury)
      planets.push(venus)
      planets.push(earth)
      planets.push(mars)
      planets.push(jupiter)
      planets.push(saturn)
      planets.push(uranus)
      planets.push(neptune)
      planets.push(moon)
      // TODO: Once support for creating meshes from arrays is implemented take these into use
      //saturnRing.makeRing()
      //uranusRing.makeRing()
      saturnRingOuterRadius = planetData[Planets.SATURN].radius + Planets.saturnOuterRadius
      saturnRingInnerRadius = planetData[Planets.SATURN].radius + 6.630
      uranusRingOuterRadius = planetData[Planets.URANUS].radius + Planets.uranusOuterRadius
      uranusRingInnerRadius = planetData[Planets.URANUS].radius + 2
      ready = true
      changeScale(1200)
      changeSpeed(0.2)
      setLookAtOffset(Planets.SUN)
  }

</pre>
<p>The scene is animated by calling the <code>animate()</code> function. That is also the place where the time is advanced, and the new positions for all of the planets are calculated. The planets are rotated in the <code>positionPlanet()</code> function based on their axial tilt and their sidereal rotation period. Finally, the new camera position is calculated in the <code>updateCamera()</code> function.</p>
<pre class="qml">

  function animate(focusedPlanet) {
      if (!ready)
          return

      advanceTime(focusedPlanet)
      for (var i = 0; i <= Planets.NUM_SELECTABLE_PLANETS; i++)
          positionPlanet(i)

      updateCamera(focusedPlanet)
  }

</pre>
<p>Files:</p>
<ul>
<li><a href="qt3d-planets-qml-appletvinput-qml.html">planets-qml/AppleTVInput.qml</a></li>
<li><a href="qt3d-planets-qml-fpsdisplay-qml.html">planets-qml/FpsDisplay.qml</a></li>
<li><a href="qt3d-planets-qml-infosheet-qml.html">planets-qml/InfoSheet.qml</a></li>
<li><a href="qt3d-planets-qml-planet-qml.html">planets-qml/Planet.qml</a></li>
<li><a href="qt3d-planets-qml-planetbutton-qml.html">planets-qml/PlanetButton.qml</a></li>
<li><a href="qt3d-planets-qml-planeteffect-qml.html">planets-qml/PlanetEffect.qml</a></li>
<li><a href="qt3d-planets-qml-planetframegraph-qml.html">planets-qml/PlanetFrameGraph.qml</a></li>
<li><a href="qt3d-planets-qml-planetmaterial-qml.html">planets-qml/PlanetMaterial.qml</a></li>
<li><a href="qt3d-planets-qml-planetslight-qml.html">planets-qml/PlanetsLight.qml</a></li>
<li><a href="qt3d-planets-qml-planetsmain-qml.html">planets-qml/PlanetsMain.qml</a></li>
<li><a href="qt3d-planets-qml-ring-qml.html">planets-qml/Ring.qml</a></li>
<li><a href="qt3d-planets-qml-shadoweffect-qml.html">planets-qml/ShadowEffect.qml</a></li>
<li><a href="qt3d-planets-qml-solarsystem-qml.html">planets-qml/SolarSystem.qml</a></li>
<li><a href="qt3d-planets-qml-styledslider-qml.html">planets-qml/StyledSlider.qml</a></li>
<li><a href="qt3d-planets-qml-suneffect-qml.html">planets-qml/SunEffect.qml</a></li>
<li><a href="qt3d-planets-qml-android-androidmanifest-xml.html">planets-qml/android/AndroidManifest.xml</a></li>
<li><a href="qt3d-planets-qml-main-cpp.html">planets-qml/main.cpp</a></li>
<li><a href="qt3d-planets-qml-networkcontroller-cpp.html">planets-qml/networkcontroller.cpp</a></li>
<li><a href="qt3d-planets-qml-networkcontroller-h.html">planets-qml/networkcontroller.h</a></li>
<li><a href="qt3d-planets-qml-planets-qml-images-qrc.html">planets-qml/planets-qml-images.qrc</a></li>
<li><a href="qt3d-planets-qml-planets-qml-pro.html">planets-qml/planets-qml.pro</a></li>
<li><a href="qt3d-planets-qml-planets-qml-qrc.html">planets-qml/planets-qml.qrc</a></li>
<li><a href="qt3d-planets-qml-planets-watchos-planetsclient-watchkit-extension-extensiondelegate-h.html">planets-qml/planets-watchos/PlanetsClient WatchKit Extension/ExtensionDelegate.h</a></li>
<li><a href="qt3d-planets-qml-planets-watchos-planetsclient-watchkit-extension-interfacecontroller-h.html">planets-qml/planets-watchos/PlanetsClient WatchKit Extension/InterfaceController.h</a></li>
<li><a href="qt3d-planets-qml-planets-watchos-planetsclient-appdelegate-h.html">planets-qml/planets-watchos/PlanetsClient/AppDelegate.h</a></li>
<li><a href="qt3d-planets-qml-planets-watchos-planetsclient-viewcontroller-h.html">planets-qml/planets-watchos/PlanetsClient/ViewController.h</a></li>
<li><a href="qt3d-planets-qml-planets-js.html">planets-qml/planets.js</a></li>
<li><a href="qt3d-planets-qml-shaders-es2-planetd-vert.html">planets-qml/shaders/es2/planetD.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-es2-planetdb-vert.html">planets-qml/shaders/es2/planetDB.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-es2-sun-vert.html">planets-qml/shaders/es2/sun.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-gl3-planetd-vert.html">planets-qml/shaders/gl3/planetD.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-gl3-planetdb-vert.html">planets-qml/shaders/gl3/planetDB.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-gl3-planetdshadow-vert.html">planets-qml/shaders/gl3/planetDShadow.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-gl3-shadowmap-vert.html">planets-qml/shaders/gl3/shadowmap.vert</a></li>
<li><a href="qt3d-planets-qml-shaders-gl3-sun-vert.html">planets-qml/shaders/gl3/sun.vert</a></li>
</ul>
<p>Images:</p>
<ul>
<li><a href="images/used-in-examples/planets-qml/android/res/drawable-hdpi/icon.png">planets-qml/android/res/drawable-hdpi/icon.png</a></li>
<li><a href="images/used-in-examples/planets-qml/android/res/drawable-ldpi/icon.png">planets-qml/android/res/drawable-ldpi/icon.png</a></li>
<li><a href="images/used-in-examples/planets-qml/android/res/drawable-mdpi/icon.png">planets-qml/android/res/drawable-mdpi/icon.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/earth.png">planets-qml/images/earth.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/jupiter.png">planets-qml/images/jupiter.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/mars.png">planets-qml/images/mars.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/mercury.png">planets-qml/images/mercury.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/nasa/uranusringcolortrans.png">planets-qml/images/nasa/uranusringcolortrans.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/neptune.png">planets-qml/images/neptune.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/saturn.png">planets-qml/images/saturn.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/earthcloudmapcolortrans.png">planets-qml/images/solarsystemscope/earthcloudmapcolortrans.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/earthcloudmapspec.jpg">planets-qml/images/solarsystemscope/earthcloudmapspec.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/earthmap2k.jpg">planets-qml/images/solarsystemscope/earthmap2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/earthnormal2k.jpg">planets-qml/images/solarsystemscope/earthnormal2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/earthspec2k.jpg">planets-qml/images/solarsystemscope/earthspec2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/galaxy_starfield.jpg">planets-qml/images/solarsystemscope/galaxy_starfield.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/jupitermap.jpg">planets-qml/images/solarsystemscope/jupitermap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/marsmap2k.jpg">planets-qml/images/solarsystemscope/marsmap2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/marsnormal2k.jpg">planets-qml/images/solarsystemscope/marsnormal2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/mercurymap.jpg">planets-qml/images/solarsystemscope/mercurymap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/mercurynormal.jpg">planets-qml/images/solarsystemscope/mercurynormal.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/moonmap2k.jpg">planets-qml/images/solarsystemscope/moonmap2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/moonnormal2k.jpg">planets-qml/images/solarsystemscope/moonnormal2k.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/neptunemap.jpg">planets-qml/images/solarsystemscope/neptunemap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/saturnmap.jpg">planets-qml/images/solarsystemscope/saturnmap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/saturnringcolortrans.png">planets-qml/images/solarsystemscope/saturnringcolortrans.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/sunmap.jpg">planets-qml/images/solarsystemscope/sunmap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/uranusmap.jpg">planets-qml/images/solarsystemscope/uranusmap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/venusmap.jpg">planets-qml/images/solarsystemscope/venusmap.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/solarsystemscope/venusnormal.jpg">planets-qml/images/solarsystemscope/venusnormal.jpg</a></li>
<li><a href="images/used-in-examples/planets-qml/images/sun.png">planets-qml/images/sun.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/uranus.png">planets-qml/images/uranus.png</a></li>
<li><a href="images/used-in-examples/planets-qml/images/venus.png">planets-qml/images/venus.png</a></li>
<li><a href="images/used-in-examples/planets-qml/planets-watchos/PlanetsClient WatchKit App/Assets.xcassets/AppIcon.appiconset/home_icon.png">planets-qml/planets-watchos/PlanetsClient WatchKit App/Assets.xcassets/AppIcon.appiconset/home_icon.png</a></li>
<li><a href="images/used-in-examples/planets-qml/planets-watchos/PlanetsClient/Assets.xcassets/AppIcon.appiconset/icon120.png">planets-qml/planets-watchos/PlanetsClient/Assets.xcassets/AppIcon.appiconset/icon120.png</a></li>
<li><a href="images/used-in-examples/planets-qml/planets-watchos/PlanetsClient/Assets.xcassets/AppIcon.appiconset/icon180.png">planets-qml/planets-watchos/PlanetsClient/Assets.xcassets/AppIcon.appiconset/icon180.png</a></li>
</ul>
</div>
<!-- @@@planets-qml -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 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>