Probleme mit "selbstgemachter" PerspectiveFovLH Matrix
-
Hey!
Folgendes Problem:
In meinem Programm benutze ich eine selbstgemachte (also nicht durch D3DXMatrixPerspectiveFovLH(...) erzeugte) PerspectiveFovLH Matrix.
In der DXSDK Doku steht dazu folgendes:w 0 0 0 0 h 0 0 0 0 zf/(zf-zn) 1 0 0 -zn*zf/(zf-zn) 0 [i]where: h is the view space height. It is calculated from h = cot(fovY/2); w is the view space width. It is calculated from w = h / Aspect.[/i]
In meinem Code mache ich das so:
m_NearClippingPlane = 1000; m_FarClippingPlane = 1.0f; float h = cotf(PI/4/2); float w = h / (4.0f/3.0f); m_ProjectionMat.m[0][0] = w; m_ProjectionMat.m[0][1] = 0; m_ProjectionMat.m[0][2] = 0; m_ProjectionMat.m[0][3] = 0; m_ProjectionMat.m[1][0] = 0; m_ProjectionMat.m[1][1] = h; m_ProjectionMat.m[1][2] = 0; m_ProjectionMat.m[1][3] = 0; m_ProjectionMat.m[2][0] = 0; m_ProjectionMat.m[2][1] = 0; m_ProjectionMat.m[2][2] = m_FarClippingPlane/(m_FarClippingPlane-m_NearClippingPlane); m_ProjectionMat.m[2][3] = 1; m_ProjectionMat.m[3][0] = 0; m_ProjectionMat.m[3][1] = 0; m_ProjectionMat.m[3][2] = -m_NearClippingPlane*m_FarClippingPlane/(m_FarClippingPlane-m_NearClippingPlane); m_ProjectionMat.m[3][3] = 0;
Dabei gibts aber ein Problem: Alles, was vorne sein sollte ist hinten und alles was hinten sein sollte ist vorne (liegt nicht am z buffer, hab ich ausprobiert).
Wenn ich statt diesem Code aber folgendes schreibe:
D3DXMatrixPerspectiveFovLH( &Matrix, PI/4, 4/3, 1, 1000);
funzt alles, so wie es soll. Aber eigentlich sollte doch das gleiche Ergebnis zu sehen sein.
Hat irgendjemand von euch ne Idee, was ich falsch mache???
-
Matrix4x4 MatrixPerspectiveFovLH(float fov, float aspect, float zn, float zf ) { float h = cos(fov/2) / sin(fov/2); float w = h / aspect; return Matrix4x4( w, 0, 0 , 0, 0, h, 0 , 0, 0, 0, zf/(zf-zn) , 1, 0, 0, -zn*zf/(zf-zn) , 0 ); }
Diese Funktion funktioniert bei mir.
Moment was seh ich da ...
m_NearClippingPlane = 1000;
m_FarClippingPlane = 1.0f;vertausch die Werte mal?
-
Verdammisch, wie peinlich
... Hattest Recht. Das war der Fehler.
Ey, TGGC ich hätte da nen Vorschlag für deine Heldengalerie!
-
godlikebot schrieb:
Ey, TGGC ich hätte da nen Vorschlag für deine Heldengalerie!
Endlich mal jemand hier, der auch über sich selbst lachen kann, und sich nicht direkt wegen jedem Piep angegriffen fühlt! RESPEKT!