I remember an early problem with D3D9 rendering windows was that the viewport projection matrix would resize everything in the viewport if and only if the window was resized vertically and not horizontally. This is the fault of the limited functions Direct3D supplies for manipulating projection matrices. I recently decided to delve into the mathematics for 5 minutes and found this quick fix for my display system ... the fault occurs when the screen resizes ... here is some code ...
[code]
/*
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
(float)w / float(h), 0.1f, 100.0f );
produces this matrix:-
xScale 0 0 0
0 yScale 0 0
0 0 zf/(zf-zn) 1
0 0 -zn*zf/(zf-zn) 0
where:
yScale = cot(fovY/2)
xScale = yScale / aspect ratio
*/
/*
D3DXMatrixPerspectiveLH(&matProj,
(float)w, float(h), 1.0f, 100.0f );
produces this matrix:-
2*zn/w 0 0 0
0 2*zn/h 0 0
0 0 zf/(zf-zn) 1
0 0 zn*zf/(zn-zf) 0
*/
// the solution - to have a Field of View parameter using the top matrix this will fix the problem.
D3DXMATRIX matProj;
if( w > h )
{
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
(float)w / float(h), 0.1f, 100.0f );
}
else
{
D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
(float)h / float(w), 0.1f, 100.0f );
float temp = matProj._22;// =
matProj._22 = matProj._11;
matProj._11 = temp;
}
[/code]
as shown the xscale and yscale parameters do not depend upon the values of x and y, and so they can be swapped. Additionally the aspect ratio must be h/w if the height is greater than the width.
(I don't know if anyone actually reads this).
No comments:
Post a Comment