Jump to content
  • Advertisement
Sign in to follow this  
pontomedon

OpenGL Getting the focal length of the camera

This topic is 3311 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

I'm having a problem implementing the scissor optimization for stencil volume shadows. I implemented the calculation of the scissor box as described here: http://www.gamasutra.com/features/20021011/lengyel_06.htm but I'm getting invalid results if my viewport is not square. I've tracked the error down to the value e which is the distance from the camera to the image plane. This distance is given by 1/tan(fov/2). With this value the scissor box fits perfectly if my viewport is square. My viewport setup looks like this (is called in every frame):
int width, height;
glfwGetWindowSize( &width, &height );
glViewport( 0, 0, width, height );

float aspect = ((float)width)/((float)height);
float fov = 65.0f;
float zNear = 0.005f;

// Select and setup the projection matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
double top = tan(fov*0.0087266463f) * zNear; // PI/360 = 0.0087266463
double bottom = -top;
double left = aspect * bottom;
double right = aspect * top;
glFrustumInfinite(left,right,bottom,top,zNear,(double)INFINITE);
the calculation of the parameters is just because i originally used gluPerspective, but switched because i needed an infinite view frustum. The parameter conversion is done as stated here: http://www.opengl.org/resources/faq/technical/transformations.htm, section 9.085. glFrustumInfinite is exactly the function from http://http.developer.nvidia.com/GPUGems/gpugems_ch09.html, Example 9-2. Now correct me if I'm wrong - the field of view I set here (65°) changes if i resize my viewport, doesn' it? I mean it's perfectly ok for it to change, would look rather odd if it wouldn't. My question is now - how can i get the current field of view for the calculation of e? pontomedon edit: seems like i am confusing fovy and fovx here. fovy (as used in gluPerspective) does not change on resize, fovx does, am i right? I'm currently trying to figure out how to get the current fovx..

Share this post


Link to post
Share on other sites
Advertisement
fixed it ;-)

I really confused horizontal and vertical fields of view.

if anyone cares - e is calculated like this (at the end of the function posted above):
e = 1/tan(fovx/2)
fovx = 2*atan(right/zNear)
e = 1/tan((2*atan(right/zNear))/2)
e = 1/tan(atan(right/zNear))
e = 1/(right/zNear)
e = zNear/right


pontomedon

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!