我遇到过很多不同的公式,如何构建投影矩阵,它们都有不同的输出,但我觉得我误解了这个概念。目前,我有这样的:如何正确计算正射投影矩阵?
//x = 10 | y = 10 | width = 800 | height = 600
float left = x;
float top = y;
float right = x + width;
float bottom = y + height;
final Matrix4f pMatrix = new Matrix4f();
pMatrix.m[0][0] = 2f/(right - left);
pMatrix.m[1][1] = 2f/(top - bottom);
pMatrix.m[2][2] = -2f/(farZ - nearZ);
pMatrix.m[3][0] = -(right + left)/(right - left);
pMatrix.m[3][1] = -(top + bottom)/(top - bottom);
pMatrix.m[3][2] = -(farZ + nearZ)/(farZ - nearZ);
pMatrix.m[3][3] = 1;
在给定的输出:
0.0025, 0.0, 0.0, -1.025
0.0, -0.0033333334, 0.0, 1.0333333
0.0, 0.0, -0.0068965517, -2.724138
0.0, 0.0, 0.0, 1.0
但是我不知道该right
和bottom
常数是否X +宽& Y +高度或宽度只是高度&?在网络上的一些文章中,人们使用两种不同的公式。
看起来不错,但你可以仔细检查这个[很好的教程](http://www.songho.ca/opengl/gl_projectionmatrix.html)。你在使用OpenGL还是DirectX? (它对Z分量稍有不同)。 –