2013-09-26 52 views
4

所以我有存儲在glm :: fquat中的對象的方向,我想用它來旋轉我的模型。我怎麼做?將glm四元數轉換爲旋轉矩陣,並將其與opengl一起使用

我想這:

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*)'| 

IM明明做錯事有啥正確的方式做到這一點?

回答

3

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

非常感謝!這兩種方法都有效。不能說我明白這一點。但它的工作原理。這就是重要的:) – user2820068