觉得教程有点问题。
camera.Yaw += 180.0f; // Turn the camera's yaw 180 degrees around
camera.Pitch += 180.0f; // Turn the camera's pitch 180 degrees around
camera.ProcessMouseMovement(0, 0, 0, false); // Call this to make sure it updates its camera vectors (should probably create an update function ;)), Note that we removed the pitch constrains for this specific case in the camera class via a boolean (otherwise we can't reverse camera's pitch values)
glm::mat4 view = camera.GetViewMatrix();
camera.Yaw -= 180.0f; // Reset it back to what it was
camera.Pitch -= 180.0f;
偏航角和俯仰角都改变了180度,其中还没有调用
camera.updateCameraVectors();
更改openGL的lookat矩阵,操作也是无效的。
另外都加上了180度等于没有变化啊。
我的处理方式是把摄像机放到物体前方,然后偏航角旋转180度正对物体的后方。
glm::mat4 model;
camera.Yaw += 180;
camera.Position = glm::vec3(0, 0, -3.0f);
camera.updateCameraVectors();
glm::mat4 view = camera.GetViewMatrix();
camera.Position = glm::vec3(0, 0, 3.0f);
camera.Yaw -= 180;
camera.updateCameraVectors();
同时渲染不透明物体的时候再根据距离先后次序渲染:
for (std::map<float, glm::vec3>::iterator it = sorted.begin(); it != sorted.end(); ++it)
{
model = glm::mat4();
model = glm::translate(model, it->second);
glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));
glDrawArrays(GL_TRIANGLES, 0, 6);
}
效果图:
可以看到后视镜里面的是反向的。
教程效果图:
并没有翻转。
参考链接:https://learnopengl-cn.readthedocs.io/zh/latest/04%20Advanced%20OpenGL/05%20Framebuffers/