Converting glm quaternion to rotation matrix and using it with opengl

拜拜、爱过 提交于 2019-12-10 16:46:12

问题


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?


回答1:


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] );


来源:https://stackoverflow.com/questions/19032922/converting-glm-quaternion-to-rotation-matrix-and-using-it-with-opengl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!