summaryrefslogtreecommitdiffstats
path: root/examples/qt3d/controls
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2017-01-25 08:07:42 +0000
committerMike Krus <mike.krus@kdab.com>2017-05-23 17:31:00 +0000
commit939b9b4b7591e8a421cf048a0a84ed3e75d81d21 (patch)
tree828ee7a6862ec5c0bd24f97cb540625a2c647376 /examples/qt3d/controls
parente27ce2bf3b76ab4ed09508f780a8601875ea2fe8 (diff)
Add support to move the camera so that the entire model is visible
Adds QCamera::viewAll(), QCamera::viewEntity() and QCamera::viewSphere() to move and rotate the camera so that the view center is the center of the sphere and the sphere fits inside the viewport Only works in perspective projection. Introduces a job to compute the bounding sphere of the scene excluding the camera. Change-Id: Id9d67787ea91c354009d5358d5db63a1c9480c70 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'examples/qt3d/controls')
-rw-r--r--examples/qt3d/controls/Logo.qml14
-rw-r--r--examples/qt3d/controls/main.qml9
2 files changed, 21 insertions, 2 deletions
diff --git a/examples/qt3d/controls/Logo.qml b/examples/qt3d/controls/Logo.qml
index a686e29bd..2eb9abd1a 100644
--- a/examples/qt3d/controls/Logo.qml
+++ b/examples/qt3d/controls/Logo.qml
@@ -56,6 +56,18 @@ import Qt3D.Extras 2.0
Entity {
id: sceneRoot
+ readonly property double cameraZ: camera.position.z
+
+ function viewAll() {
+ camera.viewAll()
+ }
+ function viewLogo() {
+ camera.viewEntity(logoEntity)
+ }
+ function setPositionZ(z) {
+ camera.position = Qt.vector3d( 0.0, 0.0, z )
+ }
+
Camera {
id: camera
projectionType: CameraLens.PerspectiveProjection
@@ -63,7 +75,7 @@ Entity {
aspectRatio: 4/3
nearPlane : 0.1
farPlane : 1000.0
- position: Qt.vector3d( 0.0, 0.0, viewCenter_z.value )
+ position: Qt.vector3d( 0.0, 0.0, 7.5 )
upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}
diff --git a/examples/qt3d/controls/main.qml b/examples/qt3d/controls/main.qml
index 2b438ac20..5d1f9c02c 100644
--- a/examples/qt3d/controls/main.qml
+++ b/examples/qt3d/controls/main.qml
@@ -178,13 +178,20 @@ Item {
spacing: 5
Text { text: "Camera"; font.bold: true }
- Text { text: "View Center Z" }
+ Text { text: "View Ctr Z: " + watch.cameraZ.toFixed(2) }
Slider {
id: viewCenter_z
Layout.fillWidth: true
minimumValue: 4
maximumValue: 12
value: 7.5
+ onValueChanged: watch.setPositionZ(value)
+ }
+ Button {
+ id: viewAll
+ Layout.fillWidth: true
+ text: "View All"
+ onClicked: watch.viewLogo()
}
}