Aspect Ratio
Hi, i posted this in the NeXe forums but as thats quite dead i thought i''d repost it here
http://www.gamedev.net/community/forums/topic.asp?topic_id=134868
BTW: Only need to answer 2nd question
Thanks
Setting the aspect ratio in the projection matrix is the usual way to do it in newer versions of Direct3D.
If you use a function like D3DXMatrixPerspectiveFovLH to calculate your projection matrix, then there is an aspect ratio parameter.
Really the aspect ratio is just a scale which takes place in the projection matrix. If you use a function to calculate your projection matrix which DOESN''T have an aspect ratio, then simply multiply the _11 element of your matrix by the aspect ratio after you''ve generated it which will apply the correct scale for you.
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
If you use a function like D3DXMatrixPerspectiveFovLH to calculate your projection matrix, then there is an aspect ratio parameter.
Really the aspect ratio is just a scale which takes place in the projection matrix. If you use a function to calculate your projection matrix which DOESN''T have an aspect ratio, then simply multiply the _11 element of your matrix by the aspect ratio after you''ve generated it which will apply the correct scale for you.
--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
float Aspect_Ratio = Window_Width / Window_Height;
[NOTE] If you use a ''normal'' resolution (i.e. 640x480) this value will always
be 1.333333333333333333333333333333...............f
KaMiKaZe
[NOTE] If you use a ''normal'' resolution (i.e. 640x480) this value will always
be 1.333333333333333333333333333333...............f
KaMiKaZe
This is the line in my code...
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, iWidth/iHeight, 1.0, 100.0);
you see ive got iWidth/iHeight
iWidth = 1024
iHeight = 768
somewhere above that, so technically that should work?
// Matrix code
D3DXMATRIX mat;
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, iWidth/iHeight, 1.0, 100.0);
g_pDevice->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mat);
D3DXMatrixIdentity(&mat);
g_pDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);
D3DXMatrixTranslation(&mat, 0, 0, 10.0);
g_pDevice->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mat);
// Setup triangle vertices
vtxTriangle[0].Create(0, 1, 0, 1, 0, 0);
vtxTriangle[1].Create(-1, -1, 0, 0, 1, 0);
vtxTriangle[2].Create(1, -1, 0, 0, 0, 1);
// Make it so that it''ll draw triangles facing either towards or away from the camera
g_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off Direct3D''s lighting since we use our own vertex color.
g_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
When you look at the triangle in the window, 0,0,0 is the centre of the triangle, its correctly drawn with 1 unit up to the top of the triangle, and 1 unit down to the bottom of the triangle. But when you go left and right, its 1 1/3 units left + right.
What am i doing wrong?
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, iWidth/iHeight, 1.0, 100.0);
you see ive got iWidth/iHeight
iWidth = 1024
iHeight = 768
somewhere above that, so technically that should work?
// Matrix code
D3DXMATRIX mat;
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, iWidth/iHeight, 1.0, 100.0);
g_pDevice->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mat);
D3DXMatrixIdentity(&mat);
g_pDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mat);
D3DXMatrixTranslation(&mat, 0, 0, 10.0);
g_pDevice->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mat);
// Setup triangle vertices
vtxTriangle[0].Create(0, 1, 0, 1, 0, 0);
vtxTriangle[1].Create(-1, -1, 0, 0, 1, 0);
vtxTriangle[2].Create(1, -1, 0, 0, 0, 1);
// Make it so that it''ll draw triangles facing either towards or away from the camera
g_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off Direct3D''s lighting since we use our own vertex color.
g_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
When you look at the triangle in the window, 0,0,0 is the centre of the triangle, its correctly drawn with 1 unit up to the top of the triangle, and 1 unit down to the bottom of the triangle. But when you go left and right, its 1 1/3 units left + right.
What am i doing wrong?
hmm...ill give it a go
float fAspect = iWidth / iHeight;
see if that helps any
Mark Ingram
http://www.mark-ingram.com
float fAspect = iWidth / iHeight;
see if that helps any
Mark Ingram
http://www.mark-ingram.com
float fAspectRatio = float(iWidth) / float(iHeight);
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, fAspectRatio, 1.0, 100.0);
Yes :D
It worked. I checked values without converting to floats and the answer was coming out as 1, so i checked what the output should look like with the answer of 1.333333333333333333333333 and that looked right.
Then i remembered conversion
Thanks for your help guys
Mark Ingram
http://www.mark-ingram.com
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/6, fAspectRatio, 1.0, 100.0);
Yes :D
It worked. I checked values without converting to floats and the answer was coming out as 1, so i checked what the output should look like with the answer of 1.333333333333333333333333 and that looked right.
Then i remembered conversion
Thanks for your help guys
Mark Ingram
http://www.mark-ingram.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement