# y-fov in perspective matrix creation functions

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

## Recommended Posts

Some friends and I were talking about how both glu and d3dx matrix creation functions take the fov in the y direction, instead of the possibly more intuitive x direction. We then started wondering why this is. I hit up Google a bit and couldn't really find an explanation of why y-fov is used. Is it just something that is because of some convention set long ago?

##### Share on other sites
Quote:
 Original post by DranithSome friends and I were talking about how both glu and d3dx matrix creation functions take the fov in the y direction, instead of the possibly more intuitive x direction. We then started wondering why this is. I hit up Google a bit and couldn't really find an explanation of why y-fov is used. Is it just something that is because of some convention set long ago?
I don't know why these functions work with the vertical rather than horizontal field of view (although I imagine there's a good reason). You can easily convert between horizontal and vertical fields of view if needed though. Here's a pair of functions that performs these conversions:
/** Convert horizontal field of view to vertical field of view. */template < typename T >T xfov_to_yfov(T xfov, T aspect) {    return T(2.0 * std::atan(std::tan(xfov * T(.5)) / double(aspect)));}/** Convert vertical field of view to horizontal field of view. */template < typename T >T yfov_to_xfov(T yfov, T aspect) {    return T(2.0 * std::atan(std::tan(yfov * T(.5)) * double(aspect)));}

##### Share on other sites
Quote:
 template < typename T >T xfov_to_yfov(T xfov, T aspect) { return T(2.0 * std::atan(std::tan(xfov * T(.5)) / double(aspect)));}template < typename T >T yfov_to_xfov(T yfov, T aspect) { return T(2.0 * std::atan(std::tan(yfov * T(.5)) * double(aspect)));}

ummm... doesn't this boil down to:

template < typename T >T xfov_to_yfov(T xfov, T aspect) {    return (xfov / aspect);}template < typename T >T yfov_to_xfov(T yfov, T aspect) {    return (yfov * aspect);}

am i missing something?

##### Share on other sites
Yeah, I'm more interested in where or how the convention started.

On a side note though, how is that different from a simple yfov = xfov/aspect? For values < pi, 2*atan(tan(rad/2)) == rad

##### Share on other sites
Quote:
 Original post by godechoummm... doesn't this boil down to:template < typename T >T xfov_to_yfov(T xfov, T aspect) { return (xfov / aspect);}template < typename T >T yfov_to_xfov(T yfov, T aspect) { return (yfov * aspect);}
No, the relationship between the horizontal and vertical fields of view is not linear with respect to the aspect ratio.

##### Share on other sites
Try it out.

Starting with a desired 90 degree xfov:

yfov = 2*atan(tan(pi/4))/(4/3) = 1.178 = (pi/2)/(4/3) = xfov/aspect

4/3 being for a standard resolution. The above holds true for any degree fov <180.

##### Share on other sites
Quote:
 Original post by DranithTry it out.Starting with a desired 90 degree xfov:yfov = 2*atan(tan(pi/4))/(4/3) = 1.178 = (pi/2)/(4/3) = xfov/aspect4/3 being for a standard resolution. The above holds true for any degree fov <180.
I think you're misreading the parentheses in my posted example (understandable - it's not very clear).

If you're still unconvinced, I'll try to post a derivation later this evening.

##### Share on other sites
Here's a quick, informal derivation of the yfov-from-xfov equation (the derivation of the opposite conversion is similar):
w = ( width of view volume at near plane) / 2h = (height of view volume at near plane) / 2n = distance to near planeaspect = w/htan(xfov/2) = w/ntan(yfov/2) = h/nyfov = 2*atan(h/n)yfov = 2*atan((w/n)/(w/h))yfov = 2*atan(tan(xfov/2)/aspect)

##### Share on other sites
Haha, yes I did read the parenthesis wrong. I worked it out by hand and indeed got what you posted above. Sorry about that.

Edit : Ah, I see you posted a derivation as well. Now if you could just tell me why the convention is to use y-fov! =)

##### Share on other sites
Quote:
 Original post by DranithNow if you could just tell me why the convention is to use y-fov! =)
Hehe, I wish I knew :) I'm sure someone here on GDNet knows the answer to this question though...

1. 1
2. 2
3. 3
frob
20
4. 4
Rutin
19
5. 5

• 32
• 13
• 11
• 9
• 18
• ### Forum Statistics

• Total Topics
632555
• Total Posts
3007066

×