且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenGL透视图使场景扭曲的程度远超出沿z轴的预期

更新时间:2023-02-02 16:49:01

矩阵使用裁剪平面从3D环境投影到屏幕.因此,x和y裁剪平面需要考虑窗口的宽高比以及FOV.所以你应该有这样的东西:

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);
...

请注意,我刚刚将某些c ++代码更改为Java,因此未经测试.它可以在我的代码中工作,所以应该没问题.

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.