使用glm的四元数到矩阵
Quaternion to Matrix using glm
我正在尝试将quat在glm中转换为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;
}
当我运行程序时,它显示错误"error: ' quaternion ' has not被声明"。
有谁能帮我一下吗?添加include:
#include <glm/gtx/quaternion.hpp>
修复toMat4
的命名空间:
glm::mat4 RotationMatrix = glm::toMat4(myQuat);
glm::toMat4()
存在于"gtx/quaternion.hpp
"文件中,可以看到该文件中只有"glm
"命名空间。
还有一个旁注,从c++ 14开始,不允许嵌套命名空间(例如glm::quaternion::toMat4)。
除了meepzh的回答,还可以这样做:
glm::mat4 RotationMatrix = glm::mat4_cast(myQuat);
不需要#include <glm/gtx/quaternion.hpp>
相关文章:
- 单元测试欧拉到四元数实现失败
- 零四元数和任何向量都不为零的特征积,这是一个错误吗?
- 将四元数旋转的游戏对象旋转另一个四元数时出现问题
- 在OpenGL(GLM/C++)中使用四元数旋转时出现问题
- 想要将 CGAL 与四元数相结合是否合乎逻辑
- Eigen::Quaternion FromTwoVectors() 不返回有效的四元数
- C++四元数方程程序
- 四元数旋转不起作用
- 四元数和翻译
- 使用四元数防止绕某个轴旋转
- 四元数 -> 欧拉角 -> 旋转矩阵问题 (GLM)
- 将 glm 四元数转换为旋转矩阵并将其与 opengl 一起使用
- 笛卡尔到四元数 glm
- 如何否定GLM四元数在任何单轴上的旋转
- GLM矩阵的旋转方向,使用四元数
- OpenGL, GLM四元数旋转
- 用GLM确定四元数前面的位置
- 如何正确旋转GLM四元数
- 使用glm的四元数到矩阵
- 当提供轴和四元数时,我如何使用GLM获得角度