DXs*_*ley 1 c++ opengl glm-math
我正在尝试使用 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);
Run Code Online (Sandbox Code Playgroud)