-1

I have a visualization program using OpenGL and I'm using glRotated for rotation. I have Quaternion data for rotation but I'm not sure how can I apply this to the glRotated function. Do I need to make a conversion first? If so, what should I do?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Gus Sabina
  • 189
  • 1
  • 13

2 Answers2

1

You need to convert the quaternion to a rotation matrix. See Convert Quaternion rotation to rotation matrix?

Equation for quaternion to rotation matrix

from http://www.math.ucsd.edu/~sbuss/MathCG/

Community
  • 1
  • 1
user3103692
  • 101
  • 4
1

The best way, would be to stop using the deprecated fixed-function pipeline functions.

  • glMatrixMode()
  • glLoadIdentity()
  • glTranslate*()
  • glRotate*()
  • glBegin()
  • etc.

Instead use the new Shader based pipeline, where you simply can call glUniformMatrix4fv() to provide your own Matrix.

Then you can basically just convert the Quaternions to Matrices.

If you don't want to do all the heavy lifting and calculating all the matrices yourself, then you can use GLM (OpenGL Mathematics).

Also, if you have no idea of how to use the new /modern OpenGL stuff, then you can read these great tutorials.

Alternative

An alternative, that I strongly advice you not to use, since it rely on the deprecated fixed-function pipeline.

Would be to still calculate the Quaternion to a Matrix, and then pass it to OpenGL using glMultMatrix*()

vallentin
  • 23,478
  • 6
  • 59
  • 81