Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting glm quaternion to rotation matrix and using it with opengl

so i have the orientation of my object stored in a glm::fquat and i want to use it to rotate my model. how do i do that?

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 whats the correct way to do it?

like image 924
user2820068 Avatar asked Oct 02 '22 20:10

user2820068


1 Answers

GLM won't/can't(?) automagically cast a mat4 to GLfloat* so you have to help it along a bit.

Try this:

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

This might also work:

glMultMatrixf( &glm::mat4_cast(orientation)[0][0] );
like image 175
genpfault Avatar answered Oct 13 '22 11:10

genpfault