将glm四元数转换为旋转矩阵并在OpenGL中使用

5
所以,我已经将对象的定位存储在一个glm :: fquat中,我想使用它来旋转我的模型。我该怎么做?
我尝试过这个:
glPushMatrix();
   glTranslatef(position.x, position.y, position.z);
   glMultMatrixf(glm::mat4_cast(orientation));
   glCallList(modelID);
glPopMatrix();

但是我收到了这个错误:
error: cannot convert 'glm::detail::tmat4x4<float>' to 'const GLfloat* {aka const float*}' for argument '1' to 'void glMultMatrixf(const GLfloat*)'|

我显然做错了什么,那么正确的做法是什么?
1个回答

4
GLM无法自动将mat4转换为GLfloat*,因此您需要对其进行一些帮助

尝试这个:

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

这个方法也可能有效:
glMultMatrixf( &glm::mat4_cast(orientation)[0][0] );

非常感谢!这两种方法都可以。虽然我不太理解它,但它确实有效。这就是最重要的 :) - user2820068

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接