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 using quaternion Class]
Forum Updated to NodeBB v4.3 + New Features

[Rotation using quaternion Class]

Scheduled Pinned Locked Moved Unsolved Qt 6
2 Posts 1 Posters 353 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.
  • E Offline
    E Offline
    Erija
    wrote on 7 Mar 2022, 09:46 last edited by
    #1

    Hello, I hope you're doing well.
    I'm a Qt and OpenGL beginner and I'm trying to learn how to use the quaternion class.
    So I wanted to rotate my object using quaternion: I created a quaternion defining w,x,y and Z then I normalized it and calculated the rotation matrix. Finally I used glMultMatrixf to rotate the object. GlMultMatrixf multiplies the current matrix of the object or what we call the modelview matrix with the rotation matrix.
    Since Qt already has these function, I wanted to work directly with them: so I defined my quaternion: QQauternion quaternion;
    quaternion.setScalar(w);
    quaternion.setX(x);
    quaternion.setY(y);
    quaternion.setZ(z);
    then :
    quaternion.normalize();// normalization of the quaternion
    QMatrix3x3 rot;
    rot= quaternion.QQuaternion::toRotationMatrix(); // calculating the rotation matrix.
    The problem is that I didn't know how to perform the rotation.
    I tried to use glMultMatrixf(rot) but rot (the rotation matrix) is a 33 matrix and the current matrix that will be multiplied by the rotation matrix "rot" is 44. So I cannot use it anymore.

    Can someone help me please?

    E 1 Reply Last reply 7 Mar 2022, 11:33
    0
    • E Erija
      7 Mar 2022, 09:46

      Hello, I hope you're doing well.
      I'm a Qt and OpenGL beginner and I'm trying to learn how to use the quaternion class.
      So I wanted to rotate my object using quaternion: I created a quaternion defining w,x,y and Z then I normalized it and calculated the rotation matrix. Finally I used glMultMatrixf to rotate the object. GlMultMatrixf multiplies the current matrix of the object or what we call the modelview matrix with the rotation matrix.
      Since Qt already has these function, I wanted to work directly with them: so I defined my quaternion: QQauternion quaternion;
      quaternion.setScalar(w);
      quaternion.setX(x);
      quaternion.setY(y);
      quaternion.setZ(z);
      then :
      quaternion.normalize();// normalization of the quaternion
      QMatrix3x3 rot;
      rot= quaternion.QQuaternion::toRotationMatrix(); // calculating the rotation matrix.
      The problem is that I didn't know how to perform the rotation.
      I tried to use glMultMatrixf(rot) but rot (the rotation matrix) is a 33 matrix and the current matrix that will be multiplied by the rotation matrix "rot" is 44. So I cannot use it anymore.

      Can someone help me please?

      E Offline
      E Offline
      Erija
      wrote on 7 Mar 2022, 11:33 last edited by
      #2

      Well, I changed some code lines:
      QQuaternion quaternion
      quaternion.setScalar(w);
      quaternion.setX(x);
      quaternion.setY(y);
      quaternion.setZ(z);
      QMatrix3x3 rot;
      quaternion=quaternion.normalized();
      rot=quaternion.toRotationMatrix();
      The problem is that I cannot use glMultMatrixf now since the rotation matrix is 33 and glMultMatrix is going to multiply the rotation matrix with the current one which the modelview matrix which is 44

      1 Reply Last reply
      0

      1/2

      7 Mar 2022, 09:46

      • Login

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