问题
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