PDA

View Full Version : Vertical perspective corrections



10-06-2006, 06:49 AM
I'm trying to work out the code you need to resize the window properly for vertical aspect ratios, but can't get it working.

The normal code is:

gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

Which works fine, as long as your window is either square or has some sort of horizontal-biased aspect ratio (e.g. 640x480).

But as soon as you adjust the window to have a vertical aspect ratio (480x640), it clips the sides of whatever object I'm viewing instead of keeping it all centred nicely on the screen.

Can anyone help me with this? I know it's stupid, but I can't work it out. The aspect ratio should still be worked out the same either way, but it only keeps my object centred when viewing with a horizontal window!

Any help much appreciated!!

Kenny

Nychold
10-09-2006, 04:23 AM
I just tested this code, and it seems to work okay, although far from mathematically accurate or fast. :)


if (aspect<1.0)
gluPerspective(45.0f/aspect,1.0,0.1f,100.0f);
else
gluPerspective(45.0f,aspect,0.1f,100.0f);

10-09-2006, 12:34 PM
OK, thanks for the reply, I'll give that a try! :)

Ken