我正在尝试将 glm 中的 quat 转换为 mat4。
我的代码是:
#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;
}
当我运行该程序时,它显示错误“错误:‘四元数’尚未声明”。
谁能帮我解决这个问题?
最佳答案
添加包含:
#include <glm/gtx/quaternion.hpp>
并修复toMat4
的命名空间:
glm::mat4 RotationMatrix = glm::toMat4(myQuat);
glm::toMat4()
存在于 gtx/quaternion.hpp
文件中,you can see只有 glm
命名空间。
另请注意,从 C++14 开始,嵌套 namespace (例如 glm::quaternion::toMat4)are not allowed .
关于c++ - 使用 glm 四元数到矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38145042/