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. Class QMatrix4x4
Qt 6.11 is out! See what's new in the release blog

Class QMatrix4x4

Scheduled Pinned Locked Moved Unsolved Qt 6
29 Posts 3 Posters 19.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.
  • E Erija

    @SGaist Yesterday you told me that I should load it back ? does it mean that I should use glLoadMatrix ?

    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #18

    @Erija said in Class QMatrix4x4:

    @SGaist Yesterday you told me that I should load it back ? does it mean that I should use glLoadMatrix ?

    Yes, the way the OpenGL pipeline works is closer to my QFont example. The data you fetch from it is a copy of what is used not a reference to it.

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Erija
      wrote on last edited by
      #19

      I see but I tried to load the modelview matrix and the object didn't rotate.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #20

        Can you show your code ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Erija
          wrote on last edited by
          #21

          @SGaist Okay, Here is my code:

          GLWidget::GLWidget(QWidget *parent):QOpenGLWidget(parent)

          {
          quaternion = QQuaternion( w, x, y, z); // construction of the quaternion
          w=1.0;
          x=0.0;
          y=0.0;
          z=0.0;

          connect(&timer, SIGNAL(timeout()), this, SLOT(update()));
          
          timer.start(16);
          

          }
          //================================================================================================

          void GLWidget::initializeGL()
          {

          glClearColor(0.0f,0.0f,0.0f,1.0f); //background
          

          }

          void GLWidget::paintGL()
          {

          glClear(GL_COLOR_BUFFER_BIT);
          glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          

          glMatrixMode(GL_MODELVIEW); // Modelview matrix used to apply transformations on the object
          glLoadIdentity();

          // camera transformation
          gluLookAt(6.0, 6.0, 6.0, 3.0,3.5,0.0, 0.0,1.0,0.0);
          glTranslatef(1.1, 2.1, -3.1); // trnaslate the elements of the scene to the center
                                        // of the screen
          

          quaternion.normalize();

          GLfloat m[16];

          glGetFloatv (GL_MODELVIEW_MATRIX, m);
          QMatrix4x4 modelview(m);
          modelview.rotate(quaternion); // applying the rotation: rotate function calculates
          //the rotation matrix that corresponds to the quaternion
          // then multiplies it by the modelview matrix

          glLoadMatrixf(modelview.constData());

          glEnable(GL_DEPTH_TEST);
          glEnable(GL_CULL_FACE);

             glBegin(GL_QUADS);
          

          [ Then I drew the object]

          void GLWidget::resizeGL(int wi, int h)
          {
          glViewport(0,0,wi,h);
          glMatrixMode(GL_PROJECTION);
          glLoadIdentity();
          gluPerspective( 45.0, (float)wi/h, 0.01, 100.0);

          update();
          

          }

          Logically the glLoadMatrix will replace the current matrix which is the old modelview matrix with the new modelview matrix after applying the rotation but that doesn't happen and when I run my code, the object disappears.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #22

            Did you check that the output of your multiplied matrices is what you expect ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • E Offline
              E Offline
              Erija
              wrote on last edited by Erija
              #23

              Yes,
              when I run my application, this is what I get:
              quaternion.PNG

              I changed my quaternion values using the spin boxes. The quaternion was normalized and the modelview matrix values changed as shown in the image below:
              modelview2.PNG
              Yet, the object doesn't rotate.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #24

                Let's take a step back.

                Can you properly rotate it if you grab the matrix, manually apply the coefficients and then load it back ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • E Offline
                  E Offline
                  Erija
                  wrote on last edited by Erija
                  #25

                  By manually applying the coefficients, you mean changing the values in my code and not using the spin boxes in the mainwindow ?
                  If that's what you mean, then it doesn't work but the values of the modelview matrix change after applying the rotation.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #26

                    So if you grab the matrix, change its values and set it again in does not do anything ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      Erija
                      wrote on last edited by
                      #27

                      I tried to change the modelview matrix values manually but that didn't work. When I add glLoadMatrix to load it back, the object completely disappears from the scene.

                      Well, at first I could rotate the object without using the class QQuaternion.

                      I declared 4 variables which are w,x,y and z (quaternion components) and developped a function to normalize the quaternion and another one to calculate the rotation matrix. Then I used glMultMatrixf to apply the rotation and I could rotate the object.

                      But, the moment I started using QQuaternion and QMatrix, nothing seemed to work as it should.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #28

                        I am currently wondering whether your QQuaternion is properly initialised with regard to your OpenGL scene.

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          Erija
                          wrote on last edited by Erija
                          #29

                          @SGaist Hello again, I hope you're doing well.
                          Well, I used another method to render the object and rotate using quaternions.

                          Instead of specifying the matrix mode with
                          glMatrixMode(GL_MODELVIEW)

                          I used QMatrix4x4 class to create the model, view and projection matrices. So there is no need to load the modelview anymore.

                          Thank you so much for your help and patience.

                          1 Reply Last reply
                          1

                          • Login

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