2016-07-01 58 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>