Search code examples
openglgraphicsviewport

FocalLength to Fov formula in OpenGl


Im writing a FBX reader and the camera gives me the FocalLength (distance from the camera to the interest).

In opengl I initialize the viewport using Field of View (angle of view).

After some RESEARCH on the web, I seen this formula in an few places:

FOV=2.0f*atanf((pixelwidth/2.0f)/focalLength);

But, the result of this formula gives me a small value. PD: I thought it might be radians but converting it from radians to degrees turned out in a too big number.

  • for a FocalLength of 35mm, I should get a FOV of 54.432 degrees
  • for a FocalLength of 50mm, I should get a FOV of 39.598 degrees
  • for a FocalLength of 85mm, I should get a FOV of 23.913 degrees

but the formula doesn't work. What I'm doing wrong here?


Solution

  • FOV=ANGLE * ((float)Math.PI / 180f);

    There'is an angle value that is giving the degree, for example if you use an camera 35 mm then you need to give the degree 63 in FOV. So that is ANGLE equals with 63

    Here are main angles in angle of the view of the camera:

    Super Telephoto 600 mm - 400 mm - > ANGLE=4 or 5 or 6

    Telephoto 300 mm - 100 mm - > ANGLE=8 or 12 or 18 or 24

    Medium Telephoto 85 mm- 80 mm - > ANGLE=28 or 30

    Normal 70 mm - ~42 mm -> - > ANGLE=34 or 46 or 52

    Wide angle ~40 mm - 23.2 mm - > ANGLE=rangle[60..83]

    Extreme Wide angle 24 mm - 14 mm -> ANGLE=range[84..114]

    Extreme Wide angle if you are under 14 mm then -> ANGLE=range[115..178]

    Fisheye ~8 mm -> ANGLE=range[178..179]

    CreatePerspectiveFieldOfView(FOV, m_AspectRatio, 0.1f, 100.0f);

    Shortly That's all.