Rotate 3D object in QML using Roll pitch and Yaw data
-
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 outSaicharan
code_textIronMan.Qml
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Extras 2.0Entity {
id: rootproperty 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 }
-
Hi, maybe this can help
-
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 outSaicharan
code_textIronMan.Qml
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Extras 2.0Entity {
id: rootproperty 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 }
Hey @Saicharan
Were you able to solve this?
I think you want to achieve something like this.
The following is a YouTube video with step-by-step instructions.