Search code examples
copenglquaternions

Recommended way to approach rotations in OpenGL


I'm currently writing my transformation implementation in my OpenGL program. I am at the point where I need to code in rotations. Here's the question:

I'm on board with quaternions, but the vertex shader is not (e.g. there is no quaternion "multiplication" in the GLSL language, as far as I'm aware). While I can appreciate the usefulness of quaternions, it seems that I have to use a matrix in the end anyway. What should I do? Do I go with quaternions and convert them to a transformation matrix, or is there something else I'm missing and should be doing (maybe hardcoding the quaternion multiplication in the vertex shader)?


Solution

  • A great resource to understand rotations in modern OpenGL is reading Tutorial 17: rotations from opengl-tutorial.org. I won't copy the page word for word, but in short,

    You don't use quaternions inside GLSL. Convert your quaternion to a rotation matrix, and use it in the Model matrix. Your vertices will be rotated as usual with your Model - View - Projection Matrix.