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. Rotate 3D object in QML using Roll pitch and Yaw data

Rotate 3D object in QML using Roll pitch and Yaw data

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 517 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.
  • S Offline
    S Offline
    Saicharan
    wrote on last edited by
    #1

    Hello,
    I am new to qt, I want to rotate the 3D object using IMU sensor data, I have loaded the 3D obj file in QML using Mesh and I want to rotate that Object using Roll Pitch and Yaw Data. ```Below is my code which i got from internet
    Please Help me out

    Saicharan
    code_text

    IronMan.Qml

    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0

    Entity {
    id: root

    property real x: 0
    property real y: 0
    property real z: 0
    property real scale: 1.0
    

    property real rotationAngle: 0.0

    code_text
    ```    property vector3d rotationAxis: Qt.vector3d(40, 0, 0)
    
       Texture2D{
            id: texture
            TextureImage {
                 source: "qrc:/pjan.png"
    
            }
        }
    
    
        //COPY RenderableEntity.qml in your project!!!!!!
        RenderableEntity{
            id: chest
            source: "qrc:/pjanic.obj" //Path to iron man model. You can open it with 3D Builder on Windows 10
            position: Qt.vector3d(root.x, root.y-0.10, root.z)
    
    
            //onPositionChanged: Qt.vector3d(10,10,30)
    
            scale:  root.scale
            rotationAngle: 100.0
            rotationAxis: Qt.vector3d(-60, -180, -10)
    
            Transform {
                id: transform
                scale: root.scale
                rotation: fromAxisAndAngle(root.rotationAxis, root.rotationAngle)
                translation: root.position
            }
    
            material: DiffuseMapMaterial {
                id: material
                diffuse:  texture
                specular: Qt.rgba( 0.2, 0.2, 0.2, 1.0 )
                shininess: 3.0
            }
    
    
    
        }
    }
    
    RenderableEntity.qml
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    
    Entity {
        id: root
    
        property vector3d position: Qt.vector3d(0, 0, 0)
        property real scale: 1.0
        property real rotationAngle: 40.0
        property vector3d rotationAxis: Qt.vector3d(0, 0, 0)
        property alias source: mesh.source
        property Material material
    
        components: [ transform, mesh, root.material ]
    
        Transform {
            id: transform
            scale: root.scale
            rotation: fromAxisAndAngle(root.rotationAxis, root.rotationAngle)
            translation: root.position
        }
    
        Mesh {
            id: mesh
        }
    }
    
    main.qml
    import QtQuick 2.0
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 2.0
    import QtQuick.Scene3D 2.0
    
    ColumnLayout {
    
        height: 600
        width: 500
    
        Rectangle{
        Layout.fillWidth: true
        height: 75
       // color: "#41CD52"
        color: "Black"
    
        Label {
            opacity: 0.749
            visible: true
            text: "VIGILANCE MODULE"
            color: "#fef7f7"
            anchors.fill: parent
            font.pixelSize: 35
            elide: Label.ElideRight
            horizontalAlignment: Qt.AlignHCenter
            verticalAlignment: Qt.AlignVCenter
            font.styleName: "Bold"
            font.family: "Verdana"
            textFormat: Text.RichText
            clip: false
            Layout.fillWidth: true
        }
        }
    
        Rectangle {
            id: scene
            Layout.fillHeight: true
            Layout.fillWidth: true
            color: "white"
    
            Scene3D {
                id: scene3d
                opacity: 1
                anchors.fill: parent
                anchors.margins: 10
                focus: true
                aspects: ["input", "logic"]
                cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
    
                //Loading ThreeDimensionalScene.qml for better code style
                ThreeDimensionalScene{}
            }
        }
    
        Item{
            Layout.fillWidth: true
            height: 50
    
        }
    X 1 Reply Last reply
    0
    • oria66O Offline
      oria66O Offline
      oria66
      wrote on last edited by
      #2

      Hi, maybe this can help

      https://github.com/oria66/test-qml-3d-model-rotation

      The truth is out there

      1 Reply Last reply
      0
      • S Saicharan

        Hello,
        I am new to qt, I want to rotate the 3D object using IMU sensor data, I have loaded the 3D obj file in QML using Mesh and I want to rotate that Object using Roll Pitch and Yaw Data. ```Below is my code which i got from internet
        Please Help me out

        Saicharan
        code_text

        IronMan.Qml

        import Qt3D.Core 2.0
        import Qt3D.Render 2.0
        import Qt3D.Extras 2.0

        Entity {
        id: root

        property real x: 0
        property real y: 0
        property real z: 0
        property real scale: 1.0
        

        property real rotationAngle: 0.0

        code_text
        ```    property vector3d rotationAxis: Qt.vector3d(40, 0, 0)
        
           Texture2D{
                id: texture
                TextureImage {
                     source: "qrc:/pjan.png"
        
                }
            }
        
        
            //COPY RenderableEntity.qml in your project!!!!!!
            RenderableEntity{
                id: chest
                source: "qrc:/pjanic.obj" //Path to iron man model. You can open it with 3D Builder on Windows 10
                position: Qt.vector3d(root.x, root.y-0.10, root.z)
        
        
                //onPositionChanged: Qt.vector3d(10,10,30)
        
                scale:  root.scale
                rotationAngle: 100.0
                rotationAxis: Qt.vector3d(-60, -180, -10)
        
                Transform {
                    id: transform
                    scale: root.scale
                    rotation: fromAxisAndAngle(root.rotationAxis, root.rotationAngle)
                    translation: root.position
                }
        
                material: DiffuseMapMaterial {
                    id: material
                    diffuse:  texture
                    specular: Qt.rgba( 0.2, 0.2, 0.2, 1.0 )
                    shininess: 3.0
                }
        
        
        
            }
        }
        
        RenderableEntity.qml
        import Qt3D.Core 2.0
        import Qt3D.Render 2.0
        
        Entity {
            id: root
        
            property vector3d position: Qt.vector3d(0, 0, 0)
            property real scale: 1.0
            property real rotationAngle: 40.0
            property vector3d rotationAxis: Qt.vector3d(0, 0, 0)
            property alias source: mesh.source
            property Material material
        
            components: [ transform, mesh, root.material ]
        
            Transform {
                id: transform
                scale: root.scale
                rotation: fromAxisAndAngle(root.rotationAxis, root.rotationAngle)
                translation: root.position
            }
        
            Mesh {
                id: mesh
            }
        }
        
        main.qml
        import QtQuick 2.0
        import QtQuick.Layouts 1.1
        import QtQuick.Controls 2.0
        import QtQuick.Scene3D 2.0
        
        ColumnLayout {
        
            height: 600
            width: 500
        
            Rectangle{
            Layout.fillWidth: true
            height: 75
           // color: "#41CD52"
            color: "Black"
        
            Label {
                opacity: 0.749
                visible: true
                text: "VIGILANCE MODULE"
                color: "#fef7f7"
                anchors.fill: parent
                font.pixelSize: 35
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
                font.styleName: "Bold"
                font.family: "Verdana"
                textFormat: Text.RichText
                clip: false
                Layout.fillWidth: true
            }
            }
        
            Rectangle {
                id: scene
                Layout.fillHeight: true
                Layout.fillWidth: true
                color: "white"
        
                Scene3D {
                    id: scene3d
                    opacity: 1
                    anchors.fill: parent
                    anchors.margins: 10
                    focus: true
                    aspects: ["input", "logic"]
                    cameraAspectRatioMode: Scene3D.AutomaticAspectRatio
        
                    //Loading ThreeDimensionalScene.qml for better code style
                    ThreeDimensionalScene{}
                }
            }
        
            Item{
                Layout.fillWidth: true
                height: 50
        
            }
        X Offline
        X Offline
        xpress_embedo
        wrote on last edited by
        #3

        Hey @Saicharan
        Were you able to solve this?
        I think you want to achieve something like this.
        alt text

        The following is a YouTube video with step-by-step instructions.
        alt text

        Qt Source Code can be checked from here.

        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