Ich entwickle eine einfache 3D-Engine (ohne API-Verwendung), verwandelte meine Szene erfolgreich in Welt und Ansichtsraum, habe aber Schwierigkeiten, meine Szene (vom Ansichtsbereich) mit der Perspektive zu projizieren Projektionsmatrix (OpenGL-Stil). Ich bin nicht sicher über die fov, nah und fern Werte und die Szene, die ich bekomme, ist verzerrt. Ich hoffe, wenn mir jemand mich leiten kann, wie man die perspektivische Projektionsmatrix mit Beispielcodes richtig baut und verwendet. Vielen Dank im Voraus für jede Hilfe.Wie erstellt man eine perspektivische Projektionsmatrix (keine API)
Die Matrix build:
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 }
};
Die Matrix Verwendung:
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...
}
http://www.scratchapixel.com/lessons/3d-basic-rendering/Perspektive-und-orthographische-Projektions-Matrix Ich empfehle auch die vorherigen Lektionen (Projektionspunkte und 3D-Ansicht). – user18490