2023-06-19 13:29:46 +00:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
|
|
|
import QtQuick
|
|
|
|
import QtQuick3D
|
2025-02-28 09:30:42 +00:00
|
|
|
import QtQuick3D.Physics
|
2023-08-17 03:49:16 +00:00
|
|
|
import QtMultimedia
|
2023-06-19 13:29:46 +00:00
|
|
|
|
|
|
|
Node {
|
|
|
|
id: shapeSpawner
|
|
|
|
|
2025-02-28 09:30:42 +00:00
|
|
|
required property PhysicsMaterial physicsMaterial
|
|
|
|
property int count: 0
|
|
|
|
property double diceWidth: 3.5
|
|
|
|
property vector3d rollForce: Qt.vector3d(0, 0, 0)
|
2023-06-19 13:29:46 +00:00
|
|
|
|
2025-02-28 09:30:42 +00:00
|
|
|
onCountChanged: respawn()
|
|
|
|
|
|
|
|
Repeater3D {
|
|
|
|
id: repeater
|
|
|
|
|
|
|
|
model: new Array(shapeSpawner.count).fill({
|
|
|
|
"ts": new Date().valueOf()
|
|
|
|
})
|
|
|
|
|
|
|
|
delegate: PhysicalDie {
|
|
|
|
position.x: 0.11 * Math.cos(index / (Math.PI / 4))
|
|
|
|
position.y: index * 2.1
|
|
|
|
position.z: 0
|
|
|
|
eulerRotation.x: randomInRange(0, 360)
|
|
|
|
eulerRotation.y: randomInRange(0, 360)
|
|
|
|
eulerRotation.z: randomInRange(0, 360)
|
|
|
|
physicsMaterial: shapeSpawner.physicsMaterial
|
|
|
|
diceWidth: shapeSpawner.diceWidth
|
|
|
|
|
|
|
|
Component.onCompleted: applyCentralForce(shapeSpawner.rollForce)
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
}
|
2025-02-28 09:30:42 +00:00
|
|
|
|
2023-08-17 03:49:16 +00:00
|
|
|
SoundEffect {
|
|
|
|
id: rollSound
|
|
|
|
loops: 0
|
|
|
|
source: "sounds/rolling.wav"
|
|
|
|
}
|
2023-06-19 13:29:46 +00:00
|
|
|
|
2025-02-28 09:30:42 +00:00
|
|
|
function respawn() {
|
|
|
|
repeater.model = new Array(shapeSpawner.count).fill({
|
|
|
|
"ts": new Date().valueOf()
|
|
|
|
})
|
|
|
|
rollSound.stop()
|
|
|
|
rollSound.play()
|
2024-01-15 09:31:36 +00:00
|
|
|
}
|
|
|
|
|
2025-02-28 09:30:42 +00:00
|
|
|
function randomInRange(min, max) {
|
|
|
|
return Math.random() * (max - min) + min
|
2024-01-11 10:06:55 +00:00
|
|
|
}
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|