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 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 Offline
          Christian EhrlicherC Offline
          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 Offline
              Christian EhrlicherC Offline
              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 Offline
                  Christian EhrlicherC Offline
                  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 Offline
                      Christian EhrlicherC Offline
                      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 Offline
                          Christian EhrlicherC Offline
                          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 Offline
                              Christian EhrlicherC Offline
                              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
                                  • A appdev

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

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

                                    @appdev As already explained: on each timeout slot call you take next element from the list. Isn't this "iteration"?

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

                                    1 Reply Last reply
                                    3
                                    • A Offline
                                      A Offline
                                      appdev
                                      wrote on last edited by
                                      #26

                                      But an iteration needs a loop to iterate through the whole QList so I need to use a for loop right ?

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

                                        I tried something but it didn't work:
                                        I added a new function to my code: it's actually a SLOT

                                        void MainWidget::rotate_csv(QMatrix4x4 m)
                                        {
                                            for (int i=0; i<quaternioncsv.size();++i)
                                            {
                                                m.rotate(quaternioncsv[i]);
                                            }
                                        }
                                        
                                        

                                        It iterates through the QList of quaternions and multiplies the matrix "m" with the rotation matrix of quaternioncsv[i].

                                        Then in my paintGL() function I did this:

                                            this->m_timer=new QTimer(this);
                                            m_timer->setInterval(10000);
                                            QTimer::connect(m_timer,SIGNAL(timeout()),this,SLOT(rotate_csv(matrix)));
                                            m_timer->start();
                                        

                                        So according to Qt documentation, the rotate_csv will be called every 10 seconds.
                                        When I run my application, the object remains at its initial orientation. It doesn't start rotating.

                                        1 Reply Last reply
                                        0
                                        • A appdev

                                          But an iteration needs a loop to iterate through the whole QList so I need to use a for loop right ?

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

                                          @appdev
                                          First, SLOT(rotate_csv(matrix)) isn't even legal. Why you cannot do yourself a favor and change over to New Signal Slot Syntax (unless you are on Qt4, which you do not say), which would catch this, is beyond me.... If you really won't change over, why don't you test the result returned from connect()?

                                          When I run my application, the object remains at its initial orientation. It doesn't start rotating.

                                          Did you put a qDebug() statement inside MainWidget::rotate_csv() to see how many times it was called? I have advised you to do this....

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

                                          But an iteration needs a loop to iterate through the whole QList so I need to use a for loop right ?

                                          No, this is not what the others are asking you to do. They are asking you to perform one quaternion in the list per each timeout. No for loop!

                                          They are asking you to write something like:

                                          connect(m_timer, &QTimer::timeout, this, &MainWidget::rotate_csv);
                                          
                                          m_iterations = 0;
                                          m_timer->start();
                                          
                                          void MainWidget::rotate_csv()
                                          {
                                              if (m_iterations >= quaternioncsv.count())
                                                  return;
                                              matrix.rotate(quaternioncsv[m_iterations]);
                                              m_iterations++;
                                          }
                                          
                                          1 Reply Last reply
                                          3

                                          • Login

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