Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. FirstPersonCameraController not working
Forum Updated to NodeBB v4.3 + New Features

FirstPersonCameraController not working

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 311 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Anton1978A Offline
    Anton1978A Offline
    Anton1978
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • johngodJ Offline
      johngodJ Offline
      johngod
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      1
      • Anton1978A Offline
        Anton1978A Offline
        Anton1978
        wrote on last edited by
        #3

        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 there

                PerspectiveCamera {
                    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
                }
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved