Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. [Rotation of an object using a QList of QQuaternion doesn't work]
Forum Updated to NodeBB v4.3 + New Features

[Rotation of an object using a QList of QQuaternion doesn't work]

Scheduled Pinned Locked Moved Solved Qt 6
34 Posts 5 Posters 5.0k Views 1 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.
  • A Offline
    A Offline
    appdev
    wrote on last edited by
    #5

    Okay;

    Here is the code with qDebug() statement:

    for (int i=0; i<quaternion_w.size();++i)
         {
    
        quaternioncsv.append(QQuaternion(quaternion_w[i],quaternion_x[i], 
        quaternion_y[i], quaternion_z[i]));
        qDebug()<<"quaternioncsv"<<quaternioncsv;
        matrix.rotate(quaternioncsv[i]);
    
         }
    

    and here is the output of quaternioncsv which is the QList that I want to use to rotate the object.

    quaternioncsv QList(QQuaternion(scalar:-0.169757, vector:(-0.00949828, -0.550083, 0.817619)), QQuaternion(scalar:0.542742, vector:(-0.0784193, 0.663872, -0.508483)), QQuaternion(scalar:0.605322, vector:(-0.242393, 0.722369, -0.230249)), QQuaternion(scalar:0.615956, vector:(-0.269809, 0.694952, -0.254643)), QQuaternion(scalar:0.647567, vector:(-0.199047, 0.701155, -0.222303)), QQuaternion(scalar:0.680871, vector:(-0.102179, 0.707951, -0.157415)), QQuaternion(scalar:0.691001, vector:(-0.0221707, 0.71639, -0.0938709)), QQuaternion(scalar:0.705128, vector:(0.000843344, 0.706753, -0.05739)), QQuaternion(scalar:0.709317, vector:(0.0126352, 0.70401, -0.0328456)), QQuaternion(scalar:0.707146, vector:(0.0292804, 0.706193, -0.0194616)), QQuaternion(scalar:0.706209, vector:(0.0210576, 0.707072, -0.0295872)), QQuaternion(scalar:0.709335, vector:(0.00930126, 0.702975, -0.0508208)), QQuaternion(scalar:0.711758, vector:(0.000600887, 0.699882, -0.0597074)), QQuaternion(scalar:0.716376, vector:(-0.00306779, 0.69464, -0.065364)), QQuaternion(scalar:0.723806, vector:(-0.0100708, 0.686258, -0.0710871)), QQuaternion(scalar:0.718329, vector:(-0.0157465, 0.69134, -0.0761881)), QQuaternion(scalar:0.704027, vector:(-0.0112261, 0.705654, -0.0791981)), QQuaternion(scalar:0.702827, vector:(0.0169507, 0.708798, -0.057904)), QQuaternion(scalar:0.712661, vector:(0.02157, 0.699067, -0.054351)), QQuaternion(scalar:0.720286, vector:(0.0286278, 0.691334, -0.0492495)), QQuaternion(scalar:0.727202, vector:(0.0236371, 0.684334, -0.0480126)), QQuaternion(scalar:0.727093, vector:(0.0409809, 0.683973, -0.0428709)), QQuaternion(scalar:0.728412, vector:(0.0425436, 0.681845, -0.0518988)), QQuaternion(scalar:0.723284, vector:(0.042028, 0.689264, 0.00299574))
    

    Its a QList of QQuaternion.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • A appdev

      Okay;

      Here is the code with qDebug() statement:

      for (int i=0; i<quaternion_w.size();++i)
           {
      
          quaternioncsv.append(QQuaternion(quaternion_w[i],quaternion_x[i], 
          quaternion_y[i], quaternion_z[i]));
          qDebug()<<"quaternioncsv"<<quaternioncsv;
          matrix.rotate(quaternioncsv[i]);
      
           }
      

      and here is the output of quaternioncsv which is the QList that I want to use to rotate the object.

      quaternioncsv QList(QQuaternion(scalar:-0.169757, vector:(-0.00949828, -0.550083, 0.817619)), QQuaternion(scalar:0.542742, vector:(-0.0784193, 0.663872, -0.508483)), QQuaternion(scalar:0.605322, vector:(-0.242393, 0.722369, -0.230249)), QQuaternion(scalar:0.615956, vector:(-0.269809, 0.694952, -0.254643)), QQuaternion(scalar:0.647567, vector:(-0.199047, 0.701155, -0.222303)), QQuaternion(scalar:0.680871, vector:(-0.102179, 0.707951, -0.157415)), QQuaternion(scalar:0.691001, vector:(-0.0221707, 0.71639, -0.0938709)), QQuaternion(scalar:0.705128, vector:(0.000843344, 0.706753, -0.05739)), QQuaternion(scalar:0.709317, vector:(0.0126352, 0.70401, -0.0328456)), QQuaternion(scalar:0.707146, vector:(0.0292804, 0.706193, -0.0194616)), QQuaternion(scalar:0.706209, vector:(0.0210576, 0.707072, -0.0295872)), QQuaternion(scalar:0.709335, vector:(0.00930126, 0.702975, -0.0508208)), QQuaternion(scalar:0.711758, vector:(0.000600887, 0.699882, -0.0597074)), QQuaternion(scalar:0.716376, vector:(-0.00306779, 0.69464, -0.065364)), QQuaternion(scalar:0.723806, vector:(-0.0100708, 0.686258, -0.0710871)), QQuaternion(scalar:0.718329, vector:(-0.0157465, 0.69134, -0.0761881)), QQuaternion(scalar:0.704027, vector:(-0.0112261, 0.705654, -0.0791981)), QQuaternion(scalar:0.702827, vector:(0.0169507, 0.708798, -0.057904)), QQuaternion(scalar:0.712661, vector:(0.02157, 0.699067, -0.054351)), QQuaternion(scalar:0.720286, vector:(0.0286278, 0.691334, -0.0492495)), QQuaternion(scalar:0.727202, vector:(0.0236371, 0.684334, -0.0480126)), QQuaternion(scalar:0.727093, vector:(0.0409809, 0.683973, -0.0428709)), QQuaternion(scalar:0.728412, vector:(0.0425436, 0.681845, -0.0518988)), QQuaternion(scalar:0.723284, vector:(0.042028, 0.689264, 0.00299574))
      

      Its a QList of QQuaternion.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #6

      @appdev So, your debug output tells us that quaternioncsv contains 24 QQuaternion. Looks good, doesn't it?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        appdev
        wrote on last edited by
        #7

        Yes exactly, the QList isn't empty.

        When I run the application, I 'm supposed to see an object that changes its orientation 24 times [24 orientations that correspond to every quaternion in the QList] however it only changes its orientation one time and then remains at that position.

        jsulmJ 1 Reply Last reply
        0
        • A appdev

          Yes exactly, the QList isn't empty.

          When I run the application, I 'm supposed to see an object that changes its orientation 24 times [24 orientations that correspond to every quaternion in the QList] however it only changes its orientation one time and then remains at that position.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #8

          @appdev How do you do the actual rotation?
          It sounds like you want to do an "animation", so you will need to apply each quaternion one after the other (but NOT in a loop!).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A appdev

            Okay;

            Here is the code with qDebug() statement:

            for (int i=0; i<quaternion_w.size();++i)
                 {
            
                quaternioncsv.append(QQuaternion(quaternion_w[i],quaternion_x[i], 
                quaternion_y[i], quaternion_z[i]));
                qDebug()<<"quaternioncsv"<<quaternioncsv;
                matrix.rotate(quaternioncsv[i]);
            
                 }
            

            and here is the output of quaternioncsv which is the QList that I want to use to rotate the object.

            quaternioncsv QList(QQuaternion(scalar:-0.169757, vector:(-0.00949828, -0.550083, 0.817619)), QQuaternion(scalar:0.542742, vector:(-0.0784193, 0.663872, -0.508483)), QQuaternion(scalar:0.605322, vector:(-0.242393, 0.722369, -0.230249)), QQuaternion(scalar:0.615956, vector:(-0.269809, 0.694952, -0.254643)), QQuaternion(scalar:0.647567, vector:(-0.199047, 0.701155, -0.222303)), QQuaternion(scalar:0.680871, vector:(-0.102179, 0.707951, -0.157415)), QQuaternion(scalar:0.691001, vector:(-0.0221707, 0.71639, -0.0938709)), QQuaternion(scalar:0.705128, vector:(0.000843344, 0.706753, -0.05739)), QQuaternion(scalar:0.709317, vector:(0.0126352, 0.70401, -0.0328456)), QQuaternion(scalar:0.707146, vector:(0.0292804, 0.706193, -0.0194616)), QQuaternion(scalar:0.706209, vector:(0.0210576, 0.707072, -0.0295872)), QQuaternion(scalar:0.709335, vector:(0.00930126, 0.702975, -0.0508208)), QQuaternion(scalar:0.711758, vector:(0.000600887, 0.699882, -0.0597074)), QQuaternion(scalar:0.716376, vector:(-0.00306779, 0.69464, -0.065364)), QQuaternion(scalar:0.723806, vector:(-0.0100708, 0.686258, -0.0710871)), QQuaternion(scalar:0.718329, vector:(-0.0157465, 0.69134, -0.0761881)), QQuaternion(scalar:0.704027, vector:(-0.0112261, 0.705654, -0.0791981)), QQuaternion(scalar:0.702827, vector:(0.0169507, 0.708798, -0.057904)), QQuaternion(scalar:0.712661, vector:(0.02157, 0.699067, -0.054351)), QQuaternion(scalar:0.720286, vector:(0.0286278, 0.691334, -0.0492495)), QQuaternion(scalar:0.727202, vector:(0.0236371, 0.684334, -0.0480126)), QQuaternion(scalar:0.727093, vector:(0.0409809, 0.683973, -0.0428709)), QQuaternion(scalar:0.728412, vector:(0.0425436, 0.681845, -0.0518988)), QQuaternion(scalar:0.723284, vector:(0.042028, 0.689264, 0.00299574))
            

            Its a QList of QQuaternion.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #9

            @appdev
            The question was: how many times do you go through the loop?
            Did you get your qDebug() line once or 24 times --- you didn't say.
            You could at least have printed qDebug() << i<quaternion_w.size() above the for line....
            If that is 1 you only execute matrix.rotate(quaternioncsv[i]); once, with i == 0.
            How will that do 24 operations?

            Assuming this is the problem, I really don't see why you couldn't figure it with qDebug() statements or expect a one-time loop to do 24 operations....

            1 Reply Last reply
            0
            • A Offline
              A Offline
              appdev
              wrote on last edited by
              #10

              @jsulm I can do one rotation like this :

              quaternion = QQuaternion(w, x, y, z);
              matrix.rotate(quaternion)
              

              where w, x, y and z are the quaternion values that I specify there.

              and yes exactly I want to do an animation.

              @JonB Okay, I did that :

              qDebug() << i<quaternion_w.size()
              

              I get 24 which is the size of quaternion_w. and also 24 lines and not just one line.

              Well I thought that a loop will fill the QList of QQuaternion and at the same time executes the rotation of the object.
              For example it will fill in the first field of the QList and then executes the first rotation, then fill in the second field and executes the second rotation ..etc.. so that I can have an animation by the end.

              JonBJ Christian EhrlicherC 2 Replies Last reply
              1
              • A appdev

                @jsulm I can do one rotation like this :

                quaternion = QQuaternion(w, x, y, z);
                matrix.rotate(quaternion)
                

                where w, x, y and z are the quaternion values that I specify there.

                and yes exactly I want to do an animation.

                @JonB Okay, I did that :

                qDebug() << i<quaternion_w.size()
                

                I get 24 which is the size of quaternion_w. and also 24 lines and not just one line.

                Well I thought that a loop will fill the QList of QQuaternion and at the same time executes the rotation of the object.
                For example it will fill in the first field of the QList and then executes the first rotation, then fill in the second field and executes the second rotation ..etc.. so that I can have an animation by the end.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #11

                @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                I get 24 which is the size of quaternion_w. and also 24 lines and not just one line.

                OK, fair enough, that is really what I wanted to know. Sorry if I suspected that was not the case in your situation.

                For example it will fill in the first field of the QList and then executes the first rotation, then fill in the second field and executes the second rotation ..etc.. so that I can have an animation by the end.

                That I have no idea about --- wouldn't know what a "quaternion` was if it slapped me in the face!

                But you have to admit that your original

                It seems that the for loop isn't being executed and I don't have any reason why.

                was not the case, given the qDebug() statements.

                1 Reply Last reply
                0
                • A appdev

                  @jsulm I can do one rotation like this :

                  quaternion = QQuaternion(w, x, y, z);
                  matrix.rotate(quaternion)
                  

                  where w, x, y and z are the quaternion values that I specify there.

                  and yes exactly I want to do an animation.

                  @JonB Okay, I did that :

                  qDebug() << i<quaternion_w.size()
                  

                  I get 24 which is the size of quaternion_w. and also 24 lines and not just one line.

                  Well I thought that a loop will fill the QList of QQuaternion and at the same time executes the rotation of the object.
                  For example it will fill in the first field of the QList and then executes the first rotation, then fill in the second field and executes the second rotation ..etc.. so that I can have an animation by the end.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #12

                  @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                  and yes exactly I want to do an animation.

                  But how does this correlate to 'matrix' at all? Where do you use it? Currently you simply add all quaternions and then do nothing...

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    appdev
                    wrote on last edited by
                    #13

                    @Christian-Ehrlicher matrix is the modelview matrix.
                    When I use rotate function, it multiplies the modelview matrix with the matrix that corresponds to the quaternion.

                    What's confusing is that when I run the application, the object does change its orientation but only one time.

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • A appdev

                      @Christian-Ehrlicher matrix is the modelview matrix.
                      When I use rotate function, it multiplies the modelview matrix with the matrix that corresponds to the quaternion.

                      What's confusing is that when I run the application, the object does change its orientation but only one time.

                      Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                      its orientation but only one time.

                      When you don't change quaternion_w - what should change?

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        appdev
                        wrote on last edited by
                        #15

                        I'm sorry, I didn't understand.

                        Why should I change quaternion_w ?

                        quaternioncsv is the QList that contains values of QQuaternion and that I will be using to rotate my object.

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • A appdev

                          I'm sorry, I didn't understand.

                          Why should I change quaternion_w ?

                          quaternioncsv is the QList that contains values of QQuaternion and that I will be using to rotate my object.

                          Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #16

                          @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                          quaternioncsv is the QList that contains values of QQuaternion and that I will be using to rotate my object.

                          But where? I only see you iterate over a list and modify a variable, nothing more...

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            appdev
                            wrote on last edited by appdev
                            #17

                            Okay, here is the code:

                            for (int i=0; i<quaternion_w.size();++i)
                                 {
                            
                                quaternioncsv.append(QQuaternion(quaternion_w[i],quaternion_x[i], 
                                quaternion_y[i], quaternion_z[i]));
                             
                                matrix.rotate(quaternioncsv[i]); // the object should rotate
                            
                                 }
                            

                            So first thing first I fill the QList "quaternioncsv" with values from other QLists then I use the rotate function that multiplies the modelview matrix by the rotation matrix that corresponds to every quaternion of the QList " quaternioncsv".

                            The rotate function executes the rotation.

                            Christian EhrlicherC 1 Reply Last reply
                            0
                            • A appdev

                              Okay, here is the code:

                              for (int i=0; i<quaternion_w.size();++i)
                                   {
                              
                                  quaternioncsv.append(QQuaternion(quaternion_w[i],quaternion_x[i], 
                                  quaternion_y[i], quaternion_z[i]));
                               
                                  matrix.rotate(quaternioncsv[i]); // the object should rotate
                              
                                   }
                              

                              So first thing first I fill the QList "quaternioncsv" with values from other QLists then I use the rotate function that multiplies the modelview matrix by the rotation matrix that corresponds to every quaternion of the QList " quaternioncsv".

                              The rotate function executes the rotation.

                              Christian EhrlicherC Online
                              Christian EhrlicherC Online
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #18

                              @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                              matrix.rotate(quaternioncsv[i]); // the object should rotate

                              there is no object, just a matrix and you don't paint anything after you set the matrix to a new value...

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                appdev
                                wrote on last edited by
                                #19

                                The object is represented by that matrix which is the modelview matrix.

                                this works perfectly:

                                quaternion = QQuaternion(0.8536, 0.3536, -0.1464, 0.3536);
                                matrix.rotate(quaternion)
                                

                                I tried this with different quaternion values and the object does change its orientation.

                                If I'm not painting anything after setting the matrix to a new value, how come the code lines I wrote above, make the object rotate. I'm confused.

                                Christian EhrlicherC 1 Reply Last reply
                                0
                                • A appdev

                                  The object is represented by that matrix which is the modelview matrix.

                                  this works perfectly:

                                  quaternion = QQuaternion(0.8536, 0.3536, -0.1464, 0.3536);
                                  matrix.rotate(quaternion)
                                  

                                  I tried this with different quaternion values and the object does change its orientation.

                                  If I'm not painting anything after setting the matrix to a new value, how come the code lines I wrote above, make the object rotate. I'm confused.

                                  Christian EhrlicherC Online
                                  Christian EhrlicherC Online
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #20

                                  @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                                  make the object rotate. I'm confused.

                                  Because then you enter the event loop again, a paintEvent is triggered and your stuff is painted...

                                  Use a QTimer, set the desired timeout and advance your rotation to the next state in the connected slot.

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  1 Reply Last reply
                                  4
                                  • A Offline
                                    A Offline
                                    appdev
                                    wrote on last edited by
                                    #21

                                    Using QTimer and setting the desired timeout is fine but advancing the rotation to the next state isn't really clear ? shouldn't I use something like a loop to make it advance ?

                                    Christian EhrlicherC jsulmJ 2 Replies Last reply
                                    0
                                    • A appdev

                                      Using QTimer and setting the desired timeout is fine but advancing the rotation to the next state isn't really clear ? shouldn't I use something like a loop to make it advance ?

                                      Christian EhrlicherC Online
                                      Christian EhrlicherC Online
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #22

                                      @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                                      shouldn't I use something like a loop to make it advance ?

                                      Remember the current value, add one to get to the next and use this during the next execution of your slot. How else should it work?

                                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                      Visit the Qt Academy at https://academy.qt.io/catalog

                                      1 Reply Last reply
                                      0
                                      • A appdev

                                        Using QTimer and setting the desired timeout is fine but advancing the rotation to the next state isn't really clear ? shouldn't I use something like a loop to make it advance ?

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #23

                                        @appdev said in [Rotation of an object using a QList of QQuaternion doesn't work]:

                                        but advancing the rotation to the next state isn't really clear ?

                                        In each timeout slot call you take next quaternion from your list and do the rotation.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        0
                                        • A Offline
                                          A Offline
                                          appdev
                                          wrote on last edited by
                                          #24

                                          Okay but don't I need to iterate throught the QList ?

                                          jsulmJ 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