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 ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.