Jump to content
  • Advertisement
Sign in to follow this  
angry

OpenGL Horizontal FOV?

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

Advertisement
Extract the left and right frustum planes from the projection matrix, and compute the angle between both using the dotproduct of their normals.

Share this post


Link to post
Share on other sites
Of course, the easiest way is to have it in the first place. If the projection matrix is from calling gluPerspective, you passed in the horizontal FOV. it's from calling glFrustum, you can easily calculate the horizontal FOV from the left, right, and near parameters.

Share this post


Link to post
Share on other sites
To add to the above, here's some additional info. If you created the frustum using gluPerspective(), you must already have the vertical fov since that's one of the arguments. Here are a couple of utility functions that convert back and forth between horizontal and vertical fov's:


float xfov_to_yfov(float xfov, float aspect) {
xfov = Math::DegToRad(xfov);
float yfov = 2.0f * Math::ATan(Math::Tan(xfov * 0.5f) / aspect);
return Math::RadToDeg(yfov);
}

float yfov_to_xfov(float yfov, float aspect) {
yfov = Math::DegToRad(yfov);
float xfov = 2.0f * Math::ATan(Math::Tan(yfov * 0.5f) * aspect);
return Math::RadToDeg(xfov);
}


If you created the frustum through glFrustum() or some other means, than as has been suggested you'll have to figure out the fov yourself from the function arguments or frustum planes.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!