3

我正在开发一个简单的 3D 应用程序,在该应用程序中,我根据从 MPU6050 传感器读取的四元数值旋转 3D 对象。

我使用了 simple-qml 示例中的以下代码作为参考:

Entity {
id: sceneRoot

property real x: 0.5
property real y: -0.5
property real z: 0.5
property real w: 0.5

onWChanged: console.log("3W: "+w)
onXChanged: console.log("3X: "+x)
onYChanged: console.log("3Y: "+y)
onZChanged: console.log("3Z: "+z)


Camera {
    id: camera
    projectionType: CameraLens.PerspectiveProjection
    fieldOfView: 90
    nearPlane : 0.1
    farPlane : 100
    position: Qt.vector3d( 0.0, 0.0, 40.0 )
    upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
    viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
}

FirstPersonCameraController { camera: camera }

components: [
    RenderSettings {
        activeFrameGraph: ForwardRenderer {
            camera: camera
            clearColor: "transparent"
        }
    },
    InputSettings { }
]

PhongMaterial {
    id: material
}

Mesh
{
    id: arrowMesh
    source: "/3dObj/resources/3dObj/arrow.obj"

}

Transform
{
    id: arrowTransform

    //Default/Reset position
    //Arrow head facing towards the screen
    //x:90,y:90,z:0
    property int eXAngle: 90
    property int eYAngle: 90
    property int eZAngle: 0

    rotation:
    {
        //MPU6050 gives values in quaternion
        Qt.quaternion(sceneRoot.w,sceneRoot.x,sceneRoot.y,sceneRoot.z)


    }
    scale: 0.05

}
Entity {
    id: sphereEntity
    components: [ arrowMesh, material, arrowTransform ]

}
}

我面临的问题是旋转发生在箭头的头部(3D 对象)而不是箭头的中心,并且某些四元数值的对象也会缩放。

我需要更改哪些内容才能单独围绕其中心旋转对象而没有任何缩放效果?

另外,我也尝试了三个projectionType

我需要 3D 的行为类似于以下 youtube 链接中的行为: Arduino MPU6050 示例

4

0 回答 0