Jump to content
  • Advertisement
Sign in to follow this  
ProjectinMatrix

Derive FOV from projection matrix? How?

This topic is 2941 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 have a projection matrix being set up using a frustum function
void Frustum(float left, float right, float bottom, float top, float near_, float far_);

Within that i set up a projection matrix.

Based on the parameters provided, or the projection matrix i need to figure out the Field of View. I've been searching for a while now and can't seem to find the solution?
Does anyone know the magic formula?

Share this post


Link to post
Share on other sites
Advertisement

Hi have a projection matrix being set up using a frustum function
void Frustum(float left, float right, float bottom, float top, float near_, float far_);

Within that i set up a projection matrix.

Based on the parameters provided, or the projection matrix i need to figure out the Field of View. I've been searching for a while now and can't seem to find the solution?
Does anyone know the magic formula?


Basically you're just calculate the angle between the top of the window, the camera `eye`, and bottom of the window. Don't have any formulas on me though, I'm sure you can find one easy though.

This video explains FOV http://www.youtube.c...h?v=blZUao2jTGA

Share this post


Link to post
Share on other sites
If you are not generating an off-center projection matrix, I think these two are equivalent:
http://msdn.microsof...7(v=vs.85).aspx

http://msdn.microsof...1(v=vs.85).aspx


Equalling the top-left element of the two matrix representations, you get 2*near/(right-left) == 1/tan(fovX/2). This gives
tan(fovX/2) == (right-left)/(2*near), or

fovX = 2*atan[ (right-left)/(2*near) ].

(as usual, double-check I didn't make a mistake)

Share this post


Link to post
Share on other sites
Thanks for all the reply's guys. I ended up solving the issue before i checked this thread.

I have a void setPerspective(float fov, float aspect, float near_, float far_); function as well, this setPerspective function actually calls the frustum function. in setPerspective i calculate the value for top like so:
float top = near_ * float(tanf(fov * 3.14159265f / 360.0f));
With a little bit of thinking i reversed that formula to
float FOV = float(atanf(top / near_)) * SSR_RAD_TO_DEG * 2.0f;
Inside of the Frustum function.

Thanks again everyone!

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!