-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraAnimator.qml
More file actions
37 lines (31 loc) · 873 Bytes
/
CameraAnimator.qml
File metadata and controls
37 lines (31 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import QtQuick 2.2
import Qt3D.Core 2.0
import Qt3D.Render 2.0
Timer {
id: root
property Camera camera
property real sceneRadius: 150.0
property real rotationPeriodMs: 30000.0
property var _lastDate: Date.now()
property var _elapsed: 0
function reset() {
_lastDate = Date.now()
_elapsed = 0
}
running: true
interval: 1
repeat: true
onTriggered: {
let newDate = Date.now()
_elapsed += newDate - _lastDate
let pa = _elapsed * 2.0 * Math.PI / rotationPeriodMs
let px = sceneRadius * Math.cos(pa)
let py = sceneRadius + 5 * Math.cos(pa * 8.0)
let pz = sceneRadius * Math.sin(pa)
camera.position = Qt.vector3d(px, py, pz)
_lastDate = newDate
if (_elapsed > rotationPeriodMs) {
_elapsed -= rotationPeriodMs
}
}
}