2016-07-01 60 views
6

我想将gmm中的四元数转换为mat4。使用glm的四元数到矩阵

我的代码是:

#include <iostream> 
#include<glm/glm.hpp> 
#include<glm/gtc/quaternion.hpp> 
#include<glm/common.hpp> 
using namespace std; 


int main() 
{ 
    glm::mat4 MyMatrix=glm::mat4(); 
    glm::quat myQuat; 

    myQuat=glm::quat(0.707107,0.707107,0.00,0.000); 
    glm::mat4 RotationMatrix = quaternion::toMat4(myQuat); 

    for(int i=0;i<4;++i) 
    { 
     for(int j=0;j<4;++j) 
     { 
      cout<<RotationMatrix[i][j]<<" "; 
     } 
     cout<<"\n"; 
    } 
    return 0; 
} 

当我运行程序它显示的错误“错误:‘四元数’尚未声明”。

任何人都可以帮助我吗?

+1

是否'四元数:: toMat4'必须'GLM ::四元:: toMat4'? – NathanOliver

回答

8

添加包括:

#include <glm/gtx/quaternion.hpp> 

和修复的toMat4命名空间:

存在于 gtx/quaternion.hpp文件, you can see不仅具有 glm命名空间
glm::mat4 RotationMatrix = glm::toMat4(myQuat); 

glm::toMat4()


另外,作为边注,作为C++ 14,嵌套的命名空间(例如GLM ::四元:: toMat4)are not allowed

0

除了meepzh的答案,它也可以做这样的:

glm::mat4 RotationMatrix = glm::mat4_cast(myQuat); 

要求#include <glm/gtx/quaternion.hpp>