Convert a quaternion glm to a rotation matrix and use it with opengl

so I have the orientation of my object stored in glm :: fquat, and I want to use it to rotate my model. how am i doing this

I tried this:

glPushMatrix();
   glTranslatef(position.x, position.y, position.z);
   glMultMatrixf(glm::mat4_cast(orientation));
   glCallList(modelID);
glPopMatrix();

but I got this error:

error: cannot convert 'glm::detail::tmat4x4<float>' to 'const GLfloat* {aka const float*}' for argument '1' to 'void glMultMatrixf(const GLfloat*)'|

im obviously doing something wrong, so what is the right way to do this?

+4
source share
1 answer

GLM will not / cannot (?) Automatically cast a mat4before GLfloat*, so you need to help it a bit .

Try the following:

#include <glm/gtc/type_ptr.hpp> 
glMultMatrixf( glm::value_ptr( glm::mat4_cast(orientation) ) );

This may also work:

glMultMatrixf( &glm::mat4_cast(orientation)[0][0] );
+3
source

All Articles