Frustrum culling window size at range

Started by
8 comments, last by Danny02 12 years, 11 months ago
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.
Advertisement
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
Thx, and how can i compute FOV angle?
when u set up your projection matrix u have to give OpenGL a fov value.

u probably use this function:

gluPerspective(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° Field Of View)


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"]A = Z / (far-near) * 2 - 1[/font]
[font="'Times New Roman"]just multiplicate 4D vector with A as z-value and everything else set to 1 with the inverse of the projection matrix.[/font]
[font="'Times New Roman"]
[/font]
[font="'Times New Roman"]result = [/font][size=2] inverse(projection) * vector (1, 1, a, 1);
[size=2]

[size=2]then the x&y coordinats of the result vector are at the top right corner of the frustum in view space.
[font="'Times New Roman"][size=2]left down corner is then (-x,y) and so on.[/font]
[font="'Times New Roman"][size=2]
[/font]
[font="'Times New Roman"][size=2]
[/font]
[font="'Times New Roman"][size=2]PPS:[/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[/font]






in x direction u have: fovx = fovy/aspect;

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.)
sorry, i forgot to mention. I use directX9.
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]gluPerspective and the fov for the y is calculated like [color="#1c2837"]above
[color="#1c2837"]so fovy = fovx/aspect
[color="#1c2837"]

[color="#1c2837"]@[color=#1D3652]

[color=#B57438]jyk
yes they are, take a look at http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml
For example, aspect = 2.0 means the viewer's angle of view is twice as wide in x as it is in y.[/quote]
[color="#1c2837"]

yes they are, take a look at http://www.opengl.or...Perspective.xml[/quote]
Read this, especially the third post. Then, see here, 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?
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).
f@dzhttp://festini.device-zero.de
yeah sry, I didn't thought everything through. Thanks for the explanation, seems as if the "official" docs aren't right all the time.

This topic is closed to new replies.

Advertisement