OpenGL perspective distorting scene much more than expected along z axis

半世苍凉 提交于 2019-12-04 17:16:27

The clipping planes are used by the matrix to project from the 3D environment to your screen. So the x and y clipping planes need to account for the aspect ratio of your window, and the FOV. So you should have something like this:

...
double fovyInDegrees = 50; // Change this if you want.
double ymax, xmax, aspectRatio;
aspectRatio = OpenGL.WIDTH / OpenGL.HEIGHT;
ymax = znear * Math.tan(fovyInDegrees * Math.PI / 360);
xmax = ymax * aspectRatio;
GL11.glFrustum(-xmax, xmax, -ymax, ymax, znear, zfar);
...

Note that I've just changed some of my c++ code to Java, so this isn't tested. It works in my code though, so should be fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!