Advertisement

How to draw a polygon at the edge of the screen?

Started by February 07, 2004 07:15 PM
3 comments, last by silversaraph 21 years, 1 month ago
after using gluPerspective(60.0f,(GLfloat)800/(GLfloat)600,0.1f,100.0f) in a 800 x 600 window, how to draw a quad that with it's top-left point at the top-left point of the window screen? how to calculate it, thank you? [edited by - silversaraph on February 7, 2004 8:17:35 PM]
Highest visible point in frustrum at distance d:
[1] y = tan(fovy) * d

Leftmost visible point in frustrum at distance d:
[2] x = -tan(fovx) * d

You already have fovy. To calculate tan(fovx):
[3] fovy = atan(height / distance)[4] fovx = atan(width / distance)[5] tan(fovy) = height / distance (rearrangement of 3)[6] tan(fovx) = width / distance (rearrangement of 4)[7] distance = height / tan(fovy) (rearrangement of 5)[8] tan(fovx) = width / (height / tan(fovy)) (7 into 6)[9] tan(fovx) = (width * tan(fovy)) / height (rearrangement of 8)[10] tan(fovx) = tan(fovy) * (width / height) (rearrangement of 9)


Enigma
Advertisement
Thank you Enigma, I will try it out
Enigma, out of curiosity why didn''t you recommed glOrtho? Just curious.

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

It was late and I read his post and just assumed he really wanted to be able to position something at an absolute position under a perspective projection. Reading it again it''s quite possible that an orthographic projection would have been the simplest answer. Just goes to show that if you''re not careful how you specify your question you might not get the best answer!

Enigma

This topic is closed to new replies.

Advertisement