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