0

I've been trying to rotate an object using the functions of the class QQuaternion.

I defined my quaternion then normalize it. Now I'm struggling to make it rotate using this specific function :

void QMatrix4x4::rotate(const QQuaternion &quaternion)

So this function multiplies a current matrix (this matrix) with the rotation matrix that corresponds to the quaternion I defined. In my code, the current matrix is the modelview matrix.

So logically, I should type m.rotate(quaternion) but how can I specify that m is actually the modelview matrix ?

here is what I tried to do:

   GLfloat matrix[16];
   glGetFloatv (GL_MODELVIEW_MATRIX, matrix);
   matrix.rotate(quaternion);

I think now the function knows that matrix is actually the modelview matrix. But, I got an error: member reference base type GLfloat [16] is not a structure or union. So I don't think it's the right way to do it.

wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • I'm not sure I understand. There is no direct relationship between `QMatrix4x4` and any `OpenGL` state such as the current modelview matrix. If you're using the old fixed function `OpenGL` pipeline then you'll need to read the current model view matrix using [`glGet*`](https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glGet.xml) with `GL_MODELVIEW_MATRIX`. Having said that you'd be better off learning [modern `OpenGL`](https://learnopengl.com/) and using a library such as `GLM` for the basic maths. – G.M. Mar 08 '22 at 14:58
  • There is no direct relationship between QMatrix4x4 and OpenGL but that function multiplies the rotation matrix that corresponds to the quaternion I defined with the modelview matrix. Anyways, I tried to use glGet but it didn't work because of this error: member reference base type 'GLfloat [16]' is not a structure or union. –  Mar 08 '22 at 15:36

0 Answers0