Jump to content
  • Advertisement
Sign in to follow this  
akgreene

OpenGL opengl horizontal field of view

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I was wondering if anyone knew how to guarantee the horizontal field of view of a window in OpenGL. I've been using gluPerspective to set up the viewing frustum, and using the vertical field of view I want along with setting the aspect ratio to get the result desired (e.g. for a 80 degree horizontal field of view with a 20 degree vertical field of view, I specify the vertical field of view as 30, with an aspect ratio of 4). However, this seems to breakdown when the horizontal field of view gets close to 180 (> 150 or so). I don't have any direct test for this, except that I render an image with this field of view, then read the depth buffer, convert the depths to points, and then render the points on top of the area viewed from an overhead view. When the desired horizontal field of view gets bigger, the footprint of the field of view doesn't seem to match up. Does anyone know at what point the horizontal field of view won't match up to the values indicated by the vertical field of view and aspect ratio? I hope this e-mail makes sense. Thanks for any help. akgreene

Share this post


Link to post
Share on other sites
Advertisement
If you'll look at this page (http://pyopengl.sourceforge.net/documentation/manual/gluPerspective.3G.html) and see the matrix generated by gluPerspective, you'll see that the x field of view is specified as a function of fovy and aspect: (cotangent(fovy / 2) / aspect). If you generated your own matrix using cotangent(fovx / 2) in place of that element, you might get what you want.

Share this post


Link to post
Share on other sites
What isn't matching up? How is it not matching up? Are you sure the thing you are matching it with is correct?

The only thing that I can think of is that you are losing precision or resolution as the horizontal FOV gets closer to 180 degrees.

BTW, the aspect ratio is not the ratio of the angles -- it is the ratio of the width to height. With an aspect ratio of 4:1, if the vertical FOV is 20 degrees, the horizontal FOV is 70.4 degrees, not 80. If the vertical FOV is 30 degrees, the horizontal aspect ratio is 94 degrees. Perhaps this is your results aren't "matching up". This equation shows the relationship between FOV and aspect ratio:
    aspect_ratio = tan( HFOV/2 ) / tan( VFOV/2 ) 

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!