[英]Quaternion to Matrix using glm
I am trying to convert quat in glm to mat4. 我试图将glm中的quat转换为mat4。
My code is : 我的代码是:
#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;
}
When i run the program it shows the error "error: 'quaternion' has not been declared". 当我运行程序时,它显示错误“错误:'四元数'尚未声明”。
Can anyone help me with this? 谁能帮我这个?
Add the include: 添加包含:
#include <glm/gtx/quaternion.hpp>
And fix the namespace of toMat4
: 并修复
toMat4
的命名空间:
glm::mat4 RotationMatrix = glm::toMat4(myQuat);
glm::toMat4()
exists in the gtx/quaternion.hpp
file, which you can see only has the glm
namespace. glm::toMat4()
存在于glm::toMat4()
gtx/quaternion.hpp
文件中, 您只能看到 glm
命名空间。
Also as a side note, as of C++14, nested namespaces (eg glm::quaternion::toMat4) are not allowed . 另外作为旁注,从C ++ 14开始, 不允许嵌套命名空间(例如glm :: quaternion :: toMat4)。
In addition to meepzh's answer, it can also be done like this: 除了meepzh的答案,它也可以这样做:
glm::mat4 RotationMatrix = glm::mat4_cast(myQuat);
which does not require #include <glm/gtx/quaternion.hpp>
其不需要
#include <glm/gtx/quaternion.hpp>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.