Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How should I set up FirstPersonCameraController?



  • Good day. Now it's definitely a matter of
    my inability to FirstPersonCameraController.
    As I understand it, it must be attached to some object.
    Everything seems to have been done correctly, but there is no reaction to the mouse and keyboard.

    import QtQuick 2.15
    import QtQuick.Window 2.14
    import QtQuick3D 1.15
    import QtQuick.Scene3D 2.0
    
    Window {
        width: 800
        height: 600
        visible: true
        title: qsTr("Hello World 3D")
    
        Scene3D {
            anchors.fill: parent
            anchors.bottomMargin: 50.0
            anchors.rightMargin: 50.0
            Mega3DScene {}
        }
    }
    

    Or maybe the whole scene just moves with him?
    I'm confused.
    Mega3DScene.qml file:

    import QtQuick 2.15
    import Qt3D.Core 2.0
    import Qt3D.Extras 2.15
    import Qt3D.Input 2.0
    import Qt3D.Render 2.0
    import Qt3D.Logic 2.0
    import QtQuick.Window 2.14
    
    
    Entity {
        id: rootEtity
    
        SkyboxEntity {
            baseName: "qrc:/Items/Item/skybox"
            extension: ".tga"
        }
    
        Entity{
            TorusMesh {
                id: torusMesh
                radius: 15.0
                minorRadius: 6.0
                slices: 16
                rings: 32
            }
            PhongMaterial{
                id: torusMaterial
                diffuse: Qt.rgba(0,0,1,0)
                ambient: Qt.rgba(0.15,0,0,1)
            }
            Transform {
                id: torusTransform
                translation: Qt.vector3d(0.0,0.0,0.0)
                SequentialAnimation on rotationY {
                    loops: Animation.Infinite
                    NumberAnimation {
                        duration: 3000
                        to: -360
                        from: 0
                        easing.type:Easing.InQuad
                    }
                }
            }
            id: torusEntity
            components: [torusMesh,torusMaterial,torusTransform]
        }
    
        Entity{
            PointLight{
                id: pointLight01
                color: Qt.rgba(1,0.5,0.5,0)
            }
            Transform{
                id: lightTransform01
                translation: Qt.vector3d(0.0,0.0,30.0)
            }
            id: pintLightEntity01
            components: [pointLight01,lightTransform01]
        }
    
        Entity{
            id: pintLightEntity
            PointLight{
                id: pointLight02
                color: Qt.rgba(1,0.5,0.5,0)
            }
            Transform{
                id: lightTransform02
                translation: Qt.vector3d(0.0,0.0,-30.0)
            }
            components: [pointLight02,lightTransform02]
        }
    
        Entity{
            SceneLoader{
                id: sceneLoader01
                source: "qrc:/Items/Item/teaPort.obj"
            }
            Transform{
                id: lightTransform03
                translation: Qt.vector3d(0.0,-5.0,-30.0)
                scale: 0.3
            }
            components: [sceneLoader01,lightTransform03]
        }
    
        Entity{
            SceneLoader{
                id: sceneLoader02
                source: "qrc:/Items/Item/text.obj"
            }
            Transform{
                id: lightTransform04
                translation: Qt.vector3d(0.0,-5.0,30.0)
                scale: 0.3
            }
            
            
            components: [sceneLoader02,lightTransform04]
        }
    
        Camera {
            id: mainCamera
            projectionType: CameraLens.PerspectiveProjection
            fieldOfView: 60.0
            aspectRatio: 16.0 / 9.0
            nearPlane: 0.1
            farPlane: 1000.0
            position: Qt.vector3d(0.0,0.0,50.0)
            upVector: Qt.vector3d(0.0,1.0,0.0)
            viewCenter: Qt.vector3d(0.0,0.0,0.0)
        }
    
        FirstPersonCameraController{
            id: controllerFirst
            camera: mainCamera
        }
    
        components: [
            RenderSettings {
                activeFrameGraph: ForwardRenderer{
                    clearColor: Qt.rgba(1,1,1,1)
                    camera: mainCamera
                }
            },
            InputSettings{}
        ]
    }
    


  • Everything is working. In short, I was sure that if I clicked on Scene3D with the mouse, it was immediately in focus.
    It turns out that something is wrong, you need to give its focus programmatically.

            Scene3D {
                id: scene3d
                anchors.fill: parent
                anchors.leftMargin: 200
                anchors.topMargin: 10
                anchors.rightMargin: 10
                anchors.bottomMargin: 10
                focus: true
                aspects: ["input", "logic"]
                cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
    
                Mega3DScene{}
            }
    

Log in to reply