c++ - 使用 glm 四元数到矩阵

标签 c++ opengl glm-math

我正在尝试将 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/

相关文章:

c++ - 从主机向在 VirtualBox Linux 机器上运行的服务器发送 http 请求

c++ - 正确使用 cin 对象?

c++ - 这个类定义中定义了什么

c++ - Lambdas 不适用于接受 std::function 的函数

c++ - 根据 3D 对象的位置旋转相机

opengl - 为什么顶点位置是从颜色缓冲区而不是位置缓冲区中获取的?

c++ - 无需访问类的自动转换

opengl - 忽略 OpenGL typedef 有什么影响?

c++ - GLM 无法使用 g++/C++11 进行编译

c++ - 片段着色器在彼此之上绘制面孔,即使它不应该