c++ - 使用 glm 创建 View 矩阵

标签 c++ opengl glm-math

我正在尝试使用 glm 创建一个 View 矩阵。我知道 glm::lookAt 并了解它的工作原理。我想知道是否有类似的函数可以通过不同的参数实现相同的结果。例如,是否有一个函数接受向上 vector 、垂直于 vector 的平面上的方向方位(?)和一个角度? (即天空是那样的,我向左转 N 度/弧度,然后将头向上倾斜 M 度/弧度)。

最佳答案

您可以通过组合一组操作来构建矩阵:

// define your up vector
glm::vec3 upVector = glm::vec3(0, 1, 0);
// rotate around to a given bearing: yaw
glm::mat4 camera = glm::rotate(glm::mat4(), bearing, upVector);
// Define the 'look up' axis, should be orthogonal to the up axis
glm::vec3 pitchVector = glm::vec3(1, 0, 0);
// rotate around to the required head tilt: pitch
camera = glm::rotate(camera, tilt, pitchVector);

// now get the view matrix by taking the camera inverse
glm::mat4 view = glm::inverse(camera);

关于c++ - 使用 glm 创建 View 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22194424/

相关文章:

c++ - 用于 mysql 的异步 C++ 连接器

c++ - GLUT 程序仅适用于几帧

c++ - 如何删除由 GLUT 创建的窗口的边框?

c++ - 四元数 -> 欧拉角 -> 旋转矩阵问题 (GLM)

c++ - 使用 new 创建时如何初始化结构

c++ - 非逻辑代码流/无效 vector 操作

c++ - OpenGL; gluBuild2DMipmaps 无效枚举

c++ - GLM 矩阵中的旋转方向,使用四元数

c++ - OpenGL 对象没有正确渲染?

C++签名,指针