Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

A 3D Block Building Game in QML

//The ISO perspective transform:
    transform: Matrix4x4 {
        id: isometric_perspective
        property real rotationZ: 45/360 * Math.PI * 2
        property matrix4x4 flipMatrix:
            Qt.matrix4x4(1,  0, 0, 0,
                         0, -1, 0, 0,
                         0,  0, 1, 0,
                         0,  0, 0, 1)
        property matrix4x4 rotationZMatrix:
            Qt.matrix4x4(Math.cos(rotationZ), -Math.sin(rotationZ), 0, 0,
                         Math.sin(rotationZ),  Math.cos(rotationZ), 0, 0,
                         0, 0, 1, 0,
                         0, 0, 0, 1)
        property real flatness: 0.5
        property matrix4x4 scaleYMatrix:
            Qt.matrix4x4(1,   0, 0, 0,
                         0, flatness, 0, 0,
                         0,   0, 1, 0,
                         0,   0, 0, 1)
        matrix: flipMatrix.times(scaleYMatrix).times(rotationZMatrix)
    }
//FaceArea.qml
    MouseArea {
        property var creationOffset: Qt.vector3d(0, 0, 1)
        anchors.fill: parent
        acceptedButtons: Qt.AllButtons
        onWheel: {isoCube.color = Qt.hsla(Math.random(),0.8, 0.5, 1)}
        onClicked: {
            if (mouse.button & Qt.LeftButton) {
                isoWorld.createCubeAt(isoCube.xpos + creationOffset.x,
                                                  isoCube.ypos + creationOffset.y,
                                                  isoCube.level + creationOffset.z);
            } else {
                isoCube.destroy()
            }
        }
    }

About KDAB


3 Comments

24 - Feb - 2021

Dave

24 - Feb - 2021

Christoph Sterz

25 - Feb - 2021

Abdramane Sakone