[Rotation using quaternion Class]
-
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?
-
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