【问题标题】:Converting glm quaternion to rotation matrix and using it with opengl将glm四元数转换为旋转矩阵并将其与opengl一起使用
【发布时间】:2013-09-26 15:50:30
【问题描述】:

所以我将对象的方向存储在 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*)'|

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

【问题讨论】:

    标签: c++ opengl matrix quaternions glm-math


    【解决方案1】:

    GLM 不会/不能(?)自动将mat4 转换为GLfloat* 所以you have to help it along a bit

    试试这个:

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

    这也可能有效:

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

    【讨论】:

    • 非常感谢!这两种方法都有效。不能说我明白。但它有效。这就是最重要的:)
    猜你喜欢
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 2013-03-13
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多