How to rotate object in 3D space about its axis
-
I want to rotate an object (export from balsam tool) in 3D space with roll, pitch and yaw of its object in Node but the axes of rotation is different from its object.
With 'rotX, rotY, rotZ' after some rotate , these are not pitch and roll and yaw of object!!!
In other words, I wanna rotate about body frame not initial frame!
Here is my code://object.qml import QtQuick3D 1.12 import QtQuick 2.12 Node { id: rootNode rotationOrder: Node.XYZr orientation: Node.RightHanded property real rotX: 0 property real rotY: 0 property real rotZ: 0 PointLight { id: light x: 100 y: 100 z: 100 rotationOrder: Node.XYZr orientation: Node.RightHanded color: "#ffffffff" quadraticFade: -1 } OrthographicCamera { id: cameraOrthographicFront z: -600 rotation: Qt.vector3d(0, 0, 0) } Model { id: object rotation.x: rotX rotation.y: rotY rotation.z: rotZ scale.x: 100/3 scale.y: 100/3 scale.z: 100/3 rotationOrder: Node.XYZr orientation: Node.RightHanded source: "meshes/object.mesh" DefaultMaterial { id: material_003_material diffuseMap: Texture { source: 'maps/pan.jpg' tilingModeHorizontal: Texture.Repeat tilingModeVertical: Texture.Repeat } } materials: [ material_003_material ] }} }
//main.qml mport QtQuick 2.14 import QtQuick.Window 2.1 import QtQuick3D 1.12 Window { id: windowMain visible: true minimumWidth: 600 minimumHeight: 500 width: 600 height: 500 color: "transparent"// object{ id: obj} Item { id: root anchors.fill: parent Rectangle { id: object3d anchors.centerIn: parent width: 400;height: width View3D { id: mode anchors.fill: parent anchors.centerIn: parent importScene: obj focus: true Keys.onPressed: { switch (event.key) { case Qt.Key_Up: obj.rotX -= 1 break; case Qt.Key_Down: obj.rotX += 1; break; case Qt.Key_Left: obj.rotY += 1;console.log('roll: ',obj.rotY) break; case Qt.Key_Right: obj.rotZ += 1;console.log('yaw: ',obj.rotZ) break; default: break; } } } } }
there is similar quest bot did not solve
link text
and this annot access:
https://forum.qt.io/topic/81457/problem-with-qt3d-rotation-about-axis-of-object -
Lets say you have your object in its object coordinate system which is somehow arranged in space (rotated translated).
Then to achieve a rotation of the object about its own local object coordinate system you need to first rotate the object (as long as it still in the origin xyz coordinate system) and then apply the rotation that positions it in space afterwards. So the order of the rotations / translations is what makes the difference. -
Lets say you have your object in its object coordinate system which is somehow arranged in space (rotated translated).
Then to achieve a rotation of the object about its own local object coordinate system you need to first rotate the object (as long as it still in the origin xyz coordinate system) and then apply the rotation that positions it in space afterwards. So the order of the rotations / translations is what makes the difference. -
I assume your object is made up of triangles or points or whatever and each of these points is defined in the local coordinate system of the object.
Now as long as you do not translate/rotate your object, the local coordinate system will be the same as the global coordinate system. In this position now when you just rotate about x the object will pitch if you rotate about y it will roll and z yaw. Therefore if you first apply the picht/roll/yaw rotation matrix and afterwards the transformation to the global coordinate system it will be the same as if you first positioned the object in global coordinate system and afterwards rotate about those new rotated axes. (Which however would be more complicated math)
-
Yes, exactly at the first time two coordinates are matching but must a way for any time and robust !
The
rotation
property is a quaternion, which is rather hard to reason about directly. I'd suggest using aQTransform
attached to your node instead. -
The
rotation
property is a quaternion, which is rather hard to reason about directly. I'd suggest using aQTransform
attached to your node instead. -
It does not matter if you use quaternions or rotation/homgenious matrices for the rotations/translations as long as you keep the order.
The advantage of rotation matrices however is, that you can multiply them to get a single matrix that does all the rotations at once. -
@gde23 said in How to rotate object in 3D space about its axis:
It does not matter if you use quaternions or rotation/homgenious matrices for the rotations/translations as long as you keep the order.
Not in principle, as it is just a matter of representation. Utility and convenience however can vary.
The advantage of rotation matrices however is, that you can multiply them to get a single matrix that does all the rotations at once.
Which is also true for quaternions. They have the same properties, being associative and obeying the distributive property, but do not form a commutative ring. But again, this is just the math, and not that helpful in this case.
@SpyerGame said in How to rotate object in 3D space about its axis:
Cause Qtransform is in C++ and there is not in qml and how to use it
I'm pretty sure there's a
Transform
QML element that's "related" to theQTransform
class ... like this one ... -
Thanks, yes it is, but I think use
fromAxesAndAngles
but I don't know how to work eachvector3d
of axes. In other words if each ofa
,b
&c
inQt.vector3d(a,b,c)
!
I know thatQt.vector3d(1,0,0)
isX
axis and so on but I don't know what is itQt.vector3d(.54,.1,0)
?
My desired rotation aroundX
,Y
&Z
of object like this: