# Frustrum culling window size at range

## Recommended Posts

Dun    100
Hallo, how can i compute the exact screen width and height when i consider frustrum culling.

The data is

wndHeight = 800;
wndWidth = 600;

m_fNearPlane = 1.0f;
m_fFarPlane = 11.0f;

I would like to compute exact view screen size at z = 9.0f. Can you please explain me how?
Thx for answer. I think, that the wnd infos are not important, but they are here for sure.

##### Share on other sites
Danny02    279
what u need is the field of view angle(call it alpha),
So the screen size at Z x will be: x / (tan (alpha/2)) * 2

##### Share on other sites
Dun    100
Thx, and how can i compute FOV angle?

##### Share on other sites
Danny02    279
when u set up your projection matrix u have to give OpenGL a fov value.

u probably use this function:

[b]gluPerspective[/b](GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar);

fovy is half the angle of the fov I think(when u enter 45 u get a 90° [b]F[/b]ield [b]O[/b]f [b]V[/b]iew)

Remember this is only for the y direction.
in x direction u have: fovx = fovy/aspect; aspect = screen width / screen height

PS: an much easier way to get the screen size for an specific Z Value:
[font="'Times New Roman"][size="3"]A = Z / (far-near) * 2 - 1[/size][/font]
[font="'Times New Roman"][size="3"]just multiplicate 4D vector with A as z-value and everything else set to 1 with the inverse of the projection matrix.[/size][/font]
[font="'Times New Roman"][size="3"]
[/size][/font]
[font="'Times New Roman"][size="3"]result = [/size][/font][size=2] inverse(projection) * vector (1, 1, a, 1);[/size]
[size=2]
[/size]
[size=2]then the x&y coordinats of the result vector are at the top right corner of the frustum in view space.[/size]
[font="'Times New Roman"][size=2]left down corner is then (-x,y) and so on.[/size][/font]
[font="'Times New Roman"][size=2]
[/size][/font]
[font="'Times New Roman"][size=2]
[/size][/font]
[font="'Times New Roman"][size=2]PPS:[/size][/font]
[font="'Times New Roman"][size=2]just read again your question, when it comes to frustum culling it is more common to test your bounding volums against the 6 sides of the frustum[/size][/font]

##### Share on other sites
jyk    2094
[quote name='Danny02' timestamp='1305371702' post='4810627']
in x direction u have: fovx = fovy/aspect;[/quote]
The horizontal and vertical fields of view actually aren't related linearly in that way. (Also, even if they were, I think it'd be * aspect, not / aspect.)

##### Share on other sites
Dun    100
sorry, i forgot to mention. I use directX9.

##### Share on other sites
Danny02    279
sry I mixed x&y up in my fov calculations

u supply the half of the fov in x direction to [color=#1C2837][size=2][b]gluPerspective [/b]and the fov for the y is calculated like [/size][/color][size="2"][color="#1c2837"]above[/color][/size]
[size="2"][color="#1c2837"]so fovy = fovx/aspect[/color][/size]
[size="2"][color="#1c2837"]
[/color][/size]
[size="2"][color="#1c2837"]@[/color][/size][color=#1D3652][size=4][b][color=#B57438][b][url="http://www.gamedev.net/user/51412-jyk/"]jyk[/url][/b][/color][/b][/size][/color]
yes they are, take a look at [url="http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml"]http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml[/url]
[quote]For example, aspect = 2.0 means the viewer's angle of view is twice as wide in [i]x[/i] as it is in [i]y[/i].[/quote]
[size="2"][color="#1c2837"]
[/color][/size]

##### Share on other sites
jyk    2094
[quote]yes they are, take a look at [url="http://www.opengl.or...Perspective.xml"]http://www.opengl.or...Perspective.xml[/url][/quote]
Read [url="http://www.gamedev.net/topic/333567-opengl-horizontal-field-of-view/"]this[/url], especially the third post. Then, see [url="http://wiki.panotools.org/Field_of_View"]here[/url], under the section 'Conversion from horizontal to vertical and vice versa'.

Just in case that's not sufficient, let's work through an example. Say the aspect ratio is 4:3, and the vertical field of view is 90. At a near-plane distance of, say, 3, the visible area of the viewing plane has a height of 6. With an aspect ratio of 4:3, that gives us a width of 8. The horizontal field of view is then:

2 * atan(4/3) = ~106 degrees

If the relationship were linear with respect to aspect ratio, the horizontal field of view would be 120, and clearly, 120 != 106.

Here's another way you can convince yourself. Say the aspect ratio is 1000:1. Given a vertical field of view of 90, that would mean a horizontal field of view of 90,000 degrees, correct? Yet it should be clear that as the width of the viewable area approaches infinity, the horizontal field of view approaches (and does not exceed) 180.

Let's look at the actual formula for computing horizontal field of view from vertical field of view:

h = 2*atan(tan(v/2)*aspect)

tan(90/2) is 1, so in our example we can reduce this to:

h = 2*atan(aspect)

The maximum value atan() can return (mathematically speaking) is a value very close to 90 degrees, so the maximum horizontal field of view that can be computed is a number very close to 180. If the aspect ratio were 1,000,000:1, the fields of view would be v = 90, h = ~180. Clearly, the relationship is nonlinear.

Does that clear things up at all?

##### Share on other sites
Trienco    2555
Before anybodies head explodes from the math, half the height of the frustum for any given z is
h = z * tan(fovy/2);

And before you even think about calculating fovx for a serious mathematical detour (unless you really need it):

w = aspect * h;

You probably want to calculate those once when you setup your frustum (for z = 1, so you get convenient factors to use).

##### Share on other sites
Danny02    279
yeah sry, I didn't thought everything through. Thanks for the explanation, seems as if the "official" docs aren't right all the time.