# 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.

## 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 );
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 on other sites
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

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001808
×