glm::perspective() 和 glm::lookAt() 如何协同工作?
How glm::perspective() and glm::lookAt() work together?
我想弄清楚 lookAt 和 perspective 函数是如何工作的。
我想更改 glm::lookAt 的值(特别是相机位置的 z 值)并且我注意到如果该值与 [=25= 中近平面的值不同] 它破坏了我的对象(它看起来不正常)。然后,我不知道我的问题是否与 arcball 有关(但我不这么认为,因为问题也在移动对象之前出现)或者由于某种原因我应该为相机位置使用相同的值lookAt 函数中的(z 值)和透视函数中的近平面。
有什么建议吗?
我从 https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball
中获取了 arcball 的实现
Main.cpp:
// ... Something ...
// lookAt function
glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0.,
0., 0.), glm::vec3(0., 1., 0.));
// ... Something ...
while(!glfwWindowShouldClose(window)) {
// ... Something ...
// perspective
glm::mat4 projection = glm::perspective(glm::radians(45.0f),
(float)WIDTH / (float)HEIGHT, 0.1f, 10.f);
// arcball
glm::mat4 rotated_view = view * arcball.rotation_matrix_view();
glm::mat4 rotated_model = model *
arcball.rotation_matrix_model(rotated_view);
ourShader.setMat4("projection", projection);
ourShader.setMat4("view", rotated_view);
ourShader.setMat4("model", rotated_model);
// ... Something ...
}
// ... Something ...
问题更新。已解决!
我刚刚发现这是一个z-fighting的问题。
对于有同样问题的其他用户,我建议页面:https://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm
我想弄清楚 lookAt 和 perspective 函数是如何工作的。
我想更改 glm::lookAt 的值(特别是相机位置的 z 值)并且我注意到如果该值与 [=25= 中近平面的值不同] 它破坏了我的对象(它看起来不正常)。然后,我不知道我的问题是否与 arcball 有关(但我不这么认为,因为问题也在移动对象之前出现)或者由于某种原因我应该为相机位置使用相同的值lookAt 函数中的(z 值)和透视函数中的近平面。
有什么建议吗?
我从 https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball
中获取了 arcball 的实现Main.cpp:
// ... Something ...
// lookAt function
glm::mat4 view = glm::lookAt(glm::vec3(0.0f, 0.0f, 3.0f), glm::vec3(0.,
0., 0.), glm::vec3(0., 1., 0.));
// ... Something ...
while(!glfwWindowShouldClose(window)) {
// ... Something ...
// perspective
glm::mat4 projection = glm::perspective(glm::radians(45.0f),
(float)WIDTH / (float)HEIGHT, 0.1f, 10.f);
// arcball
glm::mat4 rotated_view = view * arcball.rotation_matrix_view();
glm::mat4 rotated_model = model *
arcball.rotation_matrix_model(rotated_view);
ourShader.setMat4("projection", projection);
ourShader.setMat4("view", rotated_view);
ourShader.setMat4("model", rotated_model);
// ... Something ...
}
// ... Something ...
问题更新。已解决!
我刚刚发现这是一个z-fighting的问题。
对于有同样问题的其他用户,我建议页面:https://www.opengl.org/archives/resources/faq/technical/depthbuffer.htm