PDA

View Full Version : How to set focal length in OpenGL^_^

hawaii
04-04-2007, 11:06 PM
I was working on an algorithm. Focal length is an crucial parameter in my algorithm.

At first, I think the near_plane parameter which is used in gluPerspective(fovy, aspect, near_plane, far_plane) is related to focal length. But I tried and failed :(

Could anyone who have ever used this help me please? Thank you :)

Best regards,
Hawaii

Mazy
04-05-2007, 01:08 AM
You need to know more than focal length to set the corret FOV(which is what you can use with gluperspective(...) )

To calculate the FOV from a focal length you also need the projected area size ie. "frame size" you are using.

FOV (rectilinear) = 2 * arctan (frame size/(focal length * 2))

Here "frame size" refers to the dimension of the frame in the direction of the FOV, so for 35mm (which is 24mm x 36mm), frame size is 36mm for the horizontal FOV, 24mm for the vertical FOV and 43.25mm for the diagonal FOV

hawaii
04-05-2007, 02:05 AM
Thank you, Mazy :) But I still have two questions to ask.

1, Is focal length equal to the distance from the viewpoint to the projection plane?

2, I can set the value of focal length by setting the value of fov, and fov is calculated through the formula that you posted, is that correct？

Thanks again :)

HuoYi

Mazy
04-05-2007, 02:50 AM
Focal length is the number of millimeters from the lens to the focal point, it's a property of a lens so i don't think you find it directly equal to any number in OpenGL.

If you know what focal length your imaginary lens should have and what imaginary camera you want to simulate then you just calculate the FOV and use gluperspective. the Far and Near plane has nothing to do with that property, they are only there to clip anything outside those values, and thats not happening in real life.

hawaii
04-05-2007, 05:19 AM
To Mazy:

Thank you very much for your kindly instructions. But I am sorry because I think I confused focal length with the distance from viewpoint to projection plane. So I want to explain my question again.

I use OpenGL to realize my algorithm. I need to change the distance from the viewpoint to the projection plane. I believed it is same to the concept of focal length at first. But From your explanation, I think they are different.

So do you know how to change the distance from the viewpoint to the projection plane by using OpenGL? Thank you :) I hope you could help me :)

I appreciate your kindness very much :)

Hawaii