用glm创建视图矩阵

DXsmiley

我正在尝试使用glm创建视图矩阵。我知道glm::lookAt并了解它的工作原理。我想知道是否有相似的函数可以实现采用不同参数的相同结果。例如,是否有一个函数接受一个上矢量,一个在垂直于该矢量的平面上定向的方向以及一个角度?(即天空就是这样,我向左旋转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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章