Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Struggling with simple rotation in Qt3D
Forum Updated to NodeBB v4.3 + New Features

Struggling with simple rotation in Qt3D

Scheduled Pinned Locked Moved Unsolved Game Development
6 Posts 2 Posters 3.1k Views 2 Watching
  • 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.
  • J Offline
    J Offline
    James321
    wrote on last edited by James321
    #1

    I have imported a simple object from a .obj file and am attempting to rotate it about one of its own axis'. I know the x,y,z coordinates of the point I wish to rotate around from blender so I use the following code:

        Transform { 
                    id: rotationTransform
                    matrix: {
                        var m = Qt.matrix4x4();
                        m.translate(Qt.vector3d(0.19707,0.75906,0.18050)); 
                        m.rotate(rotationTransform.userAngle, Qt.vector3d(1, 0, 0))
                        m.translate(Qt.vector3d(-0.19707, -0.75906,- 0.18050)); //applied first
                        return m;
                            }
                        }
    

    The result is completely different to what I expect however rotating about Qt.vector3d(0, 0, 1)) works fine. Furthermore m.translate only moves my object relative to where it is, I had the misunderstanding that the argument of the function was a vector centered at the origin.

    All I want to do is rotate an object about its own Z axis- any help is appreciated.

    kshegunovK 1 Reply Last reply
    1
    • J James321

      I have imported a simple object from a .obj file and am attempting to rotate it about one of its own axis'. I know the x,y,z coordinates of the point I wish to rotate around from blender so I use the following code:

          Transform { 
                      id: rotationTransform
                      matrix: {
                          var m = Qt.matrix4x4();
                          m.translate(Qt.vector3d(0.19707,0.75906,0.18050)); 
                          m.rotate(rotationTransform.userAngle, Qt.vector3d(1, 0, 0))
                          m.translate(Qt.vector3d(-0.19707, -0.75906,- 0.18050)); //applied first
                          return m;
                              }
                          }
      

      The result is completely different to what I expect however rotating about Qt.vector3d(0, 0, 1)) works fine. Furthermore m.translate only moves my object relative to where it is, I had the misunderstanding that the argument of the function was a vector centered at the origin.

      All I want to do is rotate an object about its own Z axis- any help is appreciated.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @James321 said in Struggling with simple rotation in Qt3D:

      All I want to do is rotate an object about its own Z axis- any help is appreciated.

      What's it's own z-axis? Is it the same as the global z-axis?
      Move whatever you want to rotate to the origin (i.e. after translate it has to have (0, 0, 0) as coordinates), then rotate, then move it back to the original position.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        James321
        wrote on last edited by
        #3

        @kshegunov said in Struggling with simple rotation in Qt3D:

        own z-axis? Is it the same as the global z-axis?
        Move whatever you want to rotate to the origin (i.e. after translate

        Thats the approach that my code above takes. The only problem is finding the coordinate of my point in qt3d after scaling it. I thought using the values from blender would work but this doesnt seem to be working. It would be great if anyone could suggest a method for finding out the x,y,z coordinate of a point in qt3d.

        kshegunovK 1 Reply Last reply
        0
        • J James321

          @kshegunov said in Struggling with simple rotation in Qt3D:

          own z-axis? Is it the same as the global z-axis?
          Move whatever you want to rotate to the origin (i.e. after translate

          Thats the approach that my code above takes. The only problem is finding the coordinate of my point in qt3d after scaling it. I thought using the values from blender would work but this doesnt seem to be working. It would be great if anyone could suggest a method for finding out the x,y,z coordinate of a point in qt3d.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          No clue, but if you use the scene loader, then I think the coordinates should be in the transform of your mesh and accessible through the translation property.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            James321
            wrote on last edited by
            #5

            Based on this ([https://doc.qt.io/qt-5/qml-qt3d-render-sceneloader-members.html]) and what I tried in qml, sceneloader has no translation property.
            I am currently loading .obj components into a mesh and then to find each of their x,y,z coordinates I translate them until I reach the origin (which I can visually see because creating a torusmesh for instance will have its centre on the origin ).
            Needless to say, this isn't fun! There has to be an easier way to do this in qt3d itself..

            kshegunovK 1 Reply Last reply
            0
            • J James321

              Based on this ([https://doc.qt.io/qt-5/qml-qt3d-render-sceneloader-members.html]) and what I tried in qml, sceneloader has no translation property.
              I am currently loading .obj components into a mesh and then to find each of their x,y,z coordinates I translate them until I reach the origin (which I can visually see because creating a torusmesh for instance will have its centre on the origin ).
              Needless to say, this isn't fun! There has to be an easier way to do this in qt3d itself..

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @James321 said in Struggling with simple rotation in Qt3D:

              sceneloader has no translation property

              The scene loader supposedly reads the whole scene and sets the components and entities correctly based on it, then your mesh should have its transform object properly set, if I understand it correctly. Again, I'm speculating here, I haven't done almost any coding with Qt3D.

              I am currently loading .obj components into a mesh and then to find each of their x,y,z coordinates I translate them until I reach the origin (which I can visually see because creating a torusmesh for instance will have its centre on the origin ).

              Your mesh should be centered about the origin if you do that. What I assume is that the vertex data is translated in the .obj file, so my advice is to export the mesh as centered around the origin, and after loading then move it to the proper position.

              Read and abide by the Qt Code of Conduct

              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