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

CarChallenge 3D Demo

 import QtQuick 2.0
 import Felgo 3.0

 EntityBase {
     id: entity
     entityType: "wall"

     BoxCollider {
         id: boxCollider
         bodyType: Body.Static
         // the size of the collider is the same as the one from entity by default
     }

     Rectangle {
         anchors.fill: parent
         color: "brown"
         // this could be set to true for debugging
         visible: false
     }

     property string wallType: wallTypeEnum.top
     property variant wallTypeEnum: {
       'top': 0,
       'right': 1,
       'left': 2,
       'bottom': 3,
     }

     function calculateRotationOffset() {
       // a check with === would not work here, as only the int value is the same not the reference
       // the bottom wall points upwards into the negative y direction (QML coordinate system)
       if(wallType == wallTypeEnum.bottom)
         return 0
       else if(wallType == wallTypeEnum.left)
         return 90
       else if(wallType == wallTypeEnum.top)
         return 180
       else if(wallType == wallTypeEnum.right)
         return 270
     }

     Render3D {
       // the wall rendering is a bit more tricky: it is not a box anymore, because then the edges would be visible that it it is not one area
       // instead, the edge is skewed
       // the center of the wall shall be the center based on the wall x/y & w/h
       // afterwards rotate it based on which side of the wall we are
       // in physics it is still a box though and these boxes overlap in the edges

       x: -(parent.x + entity.width/2)
       y: -(parent.y + entity.height/2)
       zOffset: -20*scaleOffset // move it up, so it matches with the ground
       // with this value it matches exactly that 2 walls are rotated and appear as 1 congruent wall
       scaleOffset: 0.4276

       source: "../../assets/3d/outerwall.obj"
       texture: "../../assets/3d/walloutT.jpg"
       textureScale: 7 // the texture has a x- and y-scale (it is repeated to appear crisper)

       // the parent.rotation is always 0 - the walls do not get rotated
       rotation: entity.calculateRotationOffset()
       rotationAxis: Qt.vector3d(0,0,1)

       // set this to correctly rotate the car
       rotationOffset: 270
       rotationAxisOffset: Qt.vector3d(1,0,0)
     }

     // this was the old solution, with just a box and the texture wrapped around it
     // the issue was that the texture was wrapped incorrectly
     // thus the above solution is better with custom uv mapping
 //    Render3D {
 //      // the cube is positioned with 0/0 in the item center
 //      xOffset: -entity.width/2
 //      yOffset: -entity.height/2
 //      zOffset: -cubeMesh.zExtent/2 // move it up, so it matches with the ground
 //      texture: "../../assets/3d/walloutT.jpg"
 //      components: [renderTransform, material, cubeMesh]
 //    }
 //    CuboidMesh {
 //      id: cubeMesh
 //      // the level is 640x640
 //      xExtent: entity.width
 //      yExtent: entity.height
 //      zExtent: 20 // make it higher so it is an obstacle for car
 //      yzMeshResolution: Qt.size(2, 2)
 //      xzMeshResolution: Qt.size(2, 2)
 //      xyMeshResolution: Qt.size(2, 2)
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded