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 QtQuick3D.Physics
|
2023-08-17 03:49:16 +00:00
|
|
|
import QtMultimedia
|
|
|
|
import QtQml
|
2023-06-19 13:29:46 +00:00
|
|
|
|
|
|
|
DynamicRigidBody {
|
2024-07-05 07:59:31 +00:00
|
|
|
id: root
|
2023-06-19 13:29:46 +00:00
|
|
|
property real diceWidth: 1.9 // cm
|
2025-02-28 09:36:51 +00:00
|
|
|
property alias atRest: motionTimeout.running
|
2024-08-06 11:27:53 +00:00
|
|
|
property bool isClose: position.length() < 100
|
2023-08-17 03:49:16 +00:00
|
|
|
receiveContactReports: true
|
|
|
|
sendContactReports: true
|
2024-01-17 08:22:22 +00:00
|
|
|
onBodyContact: (body, positions, impulses, normals) => {
|
2025-02-28 09:36:51 +00:00
|
|
|
motionTimeout.restart()
|
2025-02-28 09:43:21 +00:00
|
|
|
const volume = impulses.reduce((acc, vector) => acc + vector.length(), 0)
|
2025-02-28 14:36:31 +00:00
|
|
|
diceSound.audioOutput.volume = volume / 2000
|
2023-08-17 03:49:16 +00:00
|
|
|
if (!diceSound.playing)
|
|
|
|
diceSound.play()
|
|
|
|
}
|
|
|
|
Timer {
|
|
|
|
id: motionTimeout
|
|
|
|
interval: 500
|
|
|
|
running: false
|
|
|
|
repeat: false
|
|
|
|
}
|
|
|
|
|
|
|
|
massMode: DynamicRigidBody.CustomDensity
|
|
|
|
density: 1.13
|
2023-06-19 13:29:46 +00:00
|
|
|
collisionShapes: BoxShape {
|
|
|
|
id: box
|
2024-07-05 07:59:31 +00:00
|
|
|
extents: Qt.vector3d(1, 1, 1).times(root.diceWidth)
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
|
|
|
Dice_low {
|
2024-08-06 11:27:53 +00:00
|
|
|
receivesShadows: root.isClose
|
2024-07-05 07:59:31 +00:00
|
|
|
scale: Qt.vector3d(2.65, 2.65, 2.65).times(root.diceWidth)
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|
2025-02-28 14:36:31 +00:00
|
|
|
|
|
|
|
MediaPlayer {
|
|
|
|
id: diceSound
|
|
|
|
source: "sounds/onedice.wav"
|
|
|
|
loops: 0
|
|
|
|
audioOutput: AudioOutput {}
|
2023-08-17 03:49:16 +00:00
|
|
|
}
|
2023-06-19 13:29:46 +00:00
|
|
|
}
|