Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to rotate object in 3D space about its axis
QtWS25 Last Chance

How to rotate object in 3D space about its axis

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 2.4k 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
    SpyerGame
    wrote on 24 Dec 2020, 11:13 last edited by SpyerGame
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gde23
      wrote on 24 Dec 2020, 12:35 last edited by
      #2

      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.

      S 1 Reply Last reply 24 Dec 2020, 13:58
      0
      • G gde23
        24 Dec 2020, 12:35

        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.

        S Offline
        S Offline
        SpyerGame
        wrote on 24 Dec 2020, 13:58 last edited by
        #3

        @gde23 ur mean is after apply e.g. 'rotX = 25' then rotate the camera in x axis equal 25 degrees?
        Can u make example for this prb?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          gde23
          wrote on 24 Dec 2020, 15:02 last edited by gde23
          #4

          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)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SpyerGame
            wrote on 24 Dec 2020, 17:40 last edited by
            #5

            Yes, exactly at the first time two coordinates are matching but must a way for any time and robust !

            K 1 Reply Last reply 24 Dec 2020, 18:09
            0
            • S SpyerGame
              24 Dec 2020, 17:40

              Yes, exactly at the first time two coordinates are matching but must a way for any time and robust !

              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 24 Dec 2020, 18:09 last edited by
              #6

              The rotation property is a quaternion, which is rather hard to reason about directly. I'd suggest using a QTransform attached to your node instead.

              Read and abide by the Qt Code of Conduct

              S 1 Reply Last reply 24 Dec 2020, 18:28
              0
              • K kshegunov
                24 Dec 2020, 18:09

                The rotation property is a quaternion, which is rather hard to reason about directly. I'd suggest using a QTransform attached to your node instead.

                S Offline
                S Offline
                SpyerGame
                wrote on 24 Dec 2020, 18:28 last edited by SpyerGame
                #7

                @kshegunov Thanks, but I don't figure out completely!
                Cause Qtransform is in C++ and there is not in qml and how to use it

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gde23
                  wrote on 24 Dec 2020, 18:38 last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SpyerGame
                    wrote on 24 Dec 2020, 19:11 last edited by SpyerGame
                    #9

                    Are these methods useful for my prb?
                    @gde23 in Model scope for rotation.x: property, I put this?

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SpyerGame
                      wrote on 25 Dec 2020, 15:13 last edited by
                      #10

                      I Can't to solve this, yet!!

                      K 1 Reply Last reply 26 Dec 2020, 17:57
                      0
                      • S SpyerGame
                        25 Dec 2020, 15:13

                        I Can't to solve this, yet!!

                        K Offline
                        K Offline
                        kshegunov
                        Moderators
                        wrote on 26 Dec 2020, 17:57 last edited by kshegunov
                        #11

                        @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 the QTransform class ... like this one ...

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SpyerGame
                          wrote on 26 Dec 2020, 19:05 last edited by SpyerGame
                          #12

                          Thanks, yes it is, but I think use fromAxesAndAngles but I don't know how to work each vector3d of axes. In other words if each of a,b & c in Qt.vector3d(a,b,c) !
                          I know that Qt.vector3d(1,0,0) is X axis and so on but I don't know what is it Qt.vector3d(.54,.1,0) ?
                          My desired rotation around X,Y & Z of object like this:
                          alt text

                          1 Reply Last reply
                          0

                          3/12

                          24 Dec 2020, 13:58

                          topic:navigator.unread, 9
                          • Login

                          • Login or register to search.
                          3 out of 12
                          • First post
                            3/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved