Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

CarChallenge 3D Demo

 import Qt3D.Core 2.0
 import Qt3D.Render 2.0
 import QtQuick.Scene3D 2.0

 import QtQuick 2.0 as QQ2

 // NOTE: this component is not working yet and is currently not used! it is just a playground to display multiple viewports

 // is just a container for the frameGraph, and specific to CC3D thus not generally usable
 // will get modified later to support e.g. an additional top-down minimap, a back mirror or a second player
 // parts copied from the qt3d example "multiviewport" (although the multiviewport example does not work as whole screen is black, probably because the scene loading doesnt work there in qt 5.5 beta at least)
 Entity {
   id: sceneRootEntity

   property alias cameraPosition: camera.position
   property alias cameraUpVector: camera.upVector
   property alias cameraViewCenter: camera.viewCenter

   property alias frameGraph: frameGraph

   //property var cameras : [cameraViewport1, cameraViewport2, cameraViewport3, cameraViewport4]

     FrameGraph {
         id : frameGraph

         Viewport {
             id : mainViewport
             rect: Qt.rect(0, 0, 1, 1)
             clearColor: "cyan"
             ClearBuffer {
                 buffers : ClearBuffer.ColorDepthBuffer
             }

             // even this is not working (the same code as in Scene3D!)
 //            CameraSelector {
 //              camera : cameraViewport1
 //              ClearBuffer {
 //                  buffers : ClearBuffer.ColorDepthBuffer
 //              }
 //            }

             Viewport {
                 id : fullscreenViewport
                 // with 1 viewport, the size of the rect doesnt matter! it is always the same and covers the full screen, as it does not get cleared by others right?
                 //rect : Qt.rect(0, 0, 0.1, 0.1)
                 rect : Qt.rect(0, 0, 1, 1) // fill the whole screen, this is the fullscreen viewport
 //                rect : Qt.rect(0.5, 0.5, 0.5, 0.5)
 //                clearColor: "green"
                 CameraSelector {camera : cameraViewport1}
             }

             Viewport {
                 id : topdownViewport
                 // with 1 viewport, the size of the rect doesnt matter! it is always the same and covers the full screen, as it does not get cleared by others right?
                 rect : Qt.rect(0.8, 0.8, 1, 1)
 //                clearColor: "blue"
                 CameraSelector {camera : cameraTopDown}
             }

 /*
             Viewport {
                 id : topRightViewport
                 rect : Qt.rect(0.5, 0, 0.5, 0.5)
                 CameraSelector {id : cameraSelectorTopRightViewport; camera : sceneRootEntity.cameras[1]}
             }

             Viewport {
                 id : bottomLeftViewport
                 rect : Qt.rect(0, 0.5, 0.5, 0.5)
                 CameraSelector {id : cameraSelectorBottomLeftViewport; camera : sceneRootEntity.cameras[2]}
             }

             Viewport {
                 id : bottomRightViewport
                 rect : Qt.rect(0.5, 0.5, 0.5, 0.5)
                 CameraSelector {id : cameraSelectorBottomRightViewport; camera : sceneRootEntity.cameras[3]}
             }
             */

         } // mainViewport
     } // frameGraph

     CameraLens {
         id : cameraLens
         projectionType: CameraLens.PerspectiveProjection
         fieldOfView: 45
         aspectRatio: 16/9
         nearPlane : 0.01
         farPlane : 2000.0
     } // cameraLens

     Entity {
         id : cameraViewport1
         property Transform transform : Transform {
             LookAt {
               id: camera
               // gets overwritten from the outside
                 position: Qt.vector3d( 0,0,-1000 )
                 upVector: Qt.vector3d( 1,0,0 )
                 viewCenter: Qt.vector3d( 0,0,0 )
             }
         }
         components : [cameraLens, transform]
     }

     Entity {
         id : cameraViewport2
         property Transform transform : Transform {
             LookAt {
                 position: Qt.vector3d( 1000,0,0 )
                 upVector: Qt.vector3d( 0,1,0 )
                 viewCenter: Qt.vector3d( 0,0,0 )
             }
         }
         components : [cameraLens, transform]
     }

     Entity {
         id : cameraViewport3
 //        property Transform transform : Transform {
 //            LookAt {
 //                position: Qt.vector3d( 0.0, 30.0, 30.0 )
 //                upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
 //                viewCenter: Qt.vector3d( -5.0, -20.0, -10.0 )
 //            }
 //        }
         property Transform transform : Transform {
             LookAt {
                 position: Qt.vector3d( 0,1000,0 )
                 upVector: Qt.vector3d( -1,0,0 )
                 viewCenter: Qt.vector3d( 0,0,0 )
             }
         }
         components : [cameraLens, transform]
     }

     Entity {
         id : cameraTopDown
         property Transform transform : Transform {
           // top-down view

             // shifting works, but the map is not on top of the main screen!
 //            Translate {
 //              dx: -500
 //              dy: -200
 //              dz: -100
 //            }
 //            // gets much smaller than the bottom scale
 //            Scale {
 //              scale: 0.4
 //            }

             LookAt {
                 position: Qt.vector3d( -level.width/2, -level.height/2, -500 )
                 upVector: Qt.vector3d( 0, 1, -1 ) // if 0,0,-1 would be used, the camera is rotated by 45°
                 viewCenter: Qt.vector3d( -level.width/2, -level.height/2, 0 )
             }
 //            Scale {
 //              scale: 0.1 // if set to 0.01, or less, it does not get smaller!?
 //            }
         }
         components : [cameraLens, transform]
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded