O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – creating disks

Our next task is to create eight disks that will slide onto rods. We'll do it in a similar way to how we handled rods. First, create a new file called Disk.qml for our new component. Put the following content into the file:

import Qt3D.Core 2.10import Qt3D.Render 2.10import Qt3D.Extras 2.10Entity {    property int index    property alias pos: transform.translation    components: [        DiffuseSpecularMaterial {            ambient: Qt.hsla(index / 8, 1, 0.5)        },        TorusMesh {            minorRadius: 1.1            radius: 2.5 + 1 * index            rings: 80        },        Transform {            id: transform            rotationX: 90            scale: 0.45        }    ]}

Like rods, disks are identified by their index. In this case, index influences the color and size of the disk. We calculate the disk's color using the  ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required