Я разрабатываю простой 3D-движок (без использования API), успешно преобразовывая свою сцену в мир и пространство просмотра, но имею проблемы с проектированием моей сцены (из пространства просмотра) с использованием матрицы перспективных проекций (стиль OpenGL). Я не уверен в значениях fov, near и far, и сцена, которую я получаю, искажена. Я надеюсь, что кто-то может направить меня, как правильно построить и использовать матрицу перспективной проекции с примерами кодов. Заранее благодарю за любую помощь.
Строка матрицы:
double f = 1 / Math.Tan(fovy / 2);
return new double[,] {
{ f / Aspect, 0, 0, 0 },
{ 0, f, 0, 0 },
{ 0, 0, (Far + Near) / (Near - Far), (2 * Far * Near) / (Near - Far) },
{ 0, 0, -1, 0 }
};
Использование матрицы:
foreach (Point P in T.Points)
{
.
. // Transforming the point to homogen point matrix, to world space, and to view space (works fine)
.
// projecting the point with getProjectionMatrix() specified in the previous code :
double[,] matrix = MatrixMultiply( GetProjectionMatrix(Fovy, Width/Height, Near, Far) , viewSpacePointMatrix );
// translating to Cartesian coordinates (from homogen):
matrix [0, 0] /= matrix [3, 0];
matrix [1, 0] /= matrix [3, 0];
matrix [2, 0] /= matrix [3, 0];
matrix [3, 0] = 1;
P = MatrixToPoint(matrix);
// adjusting to the screen Y axis:
P.y = this.Height - P.y;
// Printing...
}