Mike2012
Mike2012

Reputation: 7725

Computing FOVX (openGL)

When working with openGL perspectives I am not quite sure how to compute the fovx from the fovy. I read different things in different places and in I don't get the right behavior by using either method that I found. So can someone please tell me, given the fovy of the camera and the aspect ratio, how to I calculate the fovx of the camera? If any other data is needed that is fine just let me know what I need. Thank you so much in advance!

Upvotes: 6

Views: 9394

Answers (4)

Macke
Macke

Reputation: 25680

Correct:

fieldOfViewX = 2 * atan(tan(fieldOfViewY * 0.5) * aspect)

Wrong, especially for large aspects, see @gman's comments below:

Aspect ratio === width/height
fovy ~= "height" 
==> fovx = fovy * aspect

Test:

Fovy = 60 degs
Aspect = 4:3 ~= 1.33
Fovx = 60*1.33 = 80
80/60 = 4:3 (fovs match, yay)

For "reasonable" fovs/aspects, simple method is "reasonably" near the truth, but if you have extreme aspects you will get fovx > 180 degrees, which you don't want.

Upvotes: 14

EdgarSandyShoes
EdgarSandyShoes

Reputation: 41

Here is a good link:

http://wiki.panotools.org/Field_of_View

Note that the aspect ratio is not the same thing as the field of view ratio, and the proper relationship given on this page should be used for relating field of view angles.

Upvotes: 4

user718478
user718478

Reputation: 11

Java:

double d = (viewportHeight * 0.5) / Math.tan(Math.toRadians(fovY * 0.5));

fovX = (float) (2 * Math.toDegrees(Math.atan((viewportWidth * 0.5) / d)));

Upvotes: 1

Justin Pearce
Justin Pearce

Reputation: 5097

Have you looked at the formulas here?:

http://en.wikipedia.org/wiki/Angle_of_view

Upvotes: -1

Related Questions