Solved FirstPersonCameraController not working
-
Good day. I am trying to learn how to control a camera. Made my first app, here is all the code
import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick3D 1.15 import Qt3D.Core 2.15 import Qt3D.Extras 2.15 Window { id: root width: 800 height: 600 visible: true title: qsTr("Hello World") View3D { id: view anchors.fill: parent environment: SceneEnvironment { clearColor: "skyblue" backgroundMode: SceneEnvironment.Color } PerspectiveCamera { id: mainCamera position: Qt.vector3d(0, 500, 500) eulerRotation.x: -50 } FirstPersonCameraController { camera: mainCamera acceleration : 0.5 deceleration : 0.3 linearSpeed : 0.5 lookSpeed : 0.5 } DirectionalLight { eulerRotation.x: -30 eulerRotation.y: -70 } Model { position: Qt.vector3d(-100, 0, 0) source: "#Cube" scale: Qt.vector3d(1, 0.2, 1) materials: [ DefaultMaterial { diffuseColor: "red" } ] } Model { position: Qt.vector3d(0, 0, 0) source: "#Cylinder" scale: Qt.vector3d(1, 1, 1) materials: [ DefaultMaterial { diffuseColor: "blue" } ] } Model { position: Qt.vector3d(100,0, 0) source: "#Sphere" scale: Qt.vector3d(1, 1, 1) materials: [ DefaultMaterial { diffuseColor: "green" } ] } } }
Everything starts, but there is no reaction to the keys / mouse. Why? It seems like it follows from the manual that it is enough to place the FirstPersonCameraController on the 3d scene.
-
Hi
AFAIK you cant use FirstPersonCameraController , that is from Qt3D, you cant mix it with Quick3D, they are different libraries. Use WasdController and set is property controlledObject, to control your PerspectiveCamera. You may need to encapsulate PerspectiveCamera inside a Node, not sure, I would have to check it.Cheers
João -
Thank you so much, WasdController is really what you need.
The best part is that you can attach not only a camera to it, but also any object, for example a model.
Then you can move my cubes with the key.
Perhaps it will help someone, everything turned out to be simple therePerspectiveCamera { id: mainCamera position: Qt.vector3d(0, 500, 500) eulerRotation.x: -50 } WasdController { controlledObject: mainCamera }
or
Model { id: mod01 position: Qt.vector3d(-100, 0, 0) source: "#Cube" scale: Qt.vector3d(1, 0.2, 1) materials: [ DefaultMaterial { diffuseColor: "red" } ] } WasdController { controlledObject: mod01 }