#### Archived

This topic is now archived and is closed to further replies.

# Aspect Ratio

This topic is 5776 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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

##### Share on other sites
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

##### Share on other sites
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?

##### Share on other sites
Are you doing an integer division? Try iWidth/(float)iHeight.

##### Share on other sites
hmm...ill give it a go

float fAspect = iWidth / iHeight;

see if that helps any

Mark Ingram
http://www.mark-ingram.com

##### Share on other sites
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

Mark Ingram
http://www.mark-ingram.com

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011313
• ### Who's Online (See full list)

There are no registered users currently online

×