**2**

# Frustrum culling window size at range

Started by Dun, May 13 2011 01:20 PM

9 replies to this topic

###
#1
Members - Reputation: **100**

Posted 13 May 2011 - 01:20 PM

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.

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.

###
#4
Members - Reputation: **275**

Posted 14 May 2011 - 05:15 AM

when u set up your projection matrix u have to give OpenGL a fov value.

u probably use this function:

fovy is half the angle of the fov I think(when u enter 45 u get a 90°

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:

A = Z / (far-near) * 2 - 1

just multiplicate 4D vector with A as z-value and everything else set to 1 with the inverse of the projection matrix.

result = inverse(projection) * vector (1, 1, a, 1);

then the x&y coordinats of the result vector are at the top right corner of the frustum in view space.

left down corner is then (-x,y) and so on.

PPS:

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

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°

**F**ield**O**f**V**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:

A = Z / (far-near) * 2 - 1

just multiplicate 4D vector with A as z-value and everything else set to 1 with the inverse of the projection matrix.

result = inverse(projection) * vector (1, 1, a, 1);

then the x&y coordinats of the result vector are at the top right corner of the frustum in view space.

left down corner is then (-x,y) and so on.

PPS:

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

###
#7
Members - Reputation: **275**

Posted 14 May 2011 - 10:18 AM

sry I mixed x&y up in my fov calculations

u supply the half of the fov in x direction to

so fovy = fovx/aspect

@

yes they are, take a look at http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml

u supply the half of the fov in x direction to

**gluPerspective**and the fov for the y is calculated like aboveso fovy = fovx/aspect

@

**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

xas it is iny.

###
#8
Members - Reputation: **2075**

Posted 14 May 2011 - 01:06 PM

Read this, especially the third post. Then, see here, under the section 'Conversion from horizontal to vertical and vice versa'.yes they are, take a look at http://www.opengl.or...Perspective.xml

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?

###
#9
Crossbones+ - Reputation: **2551**

Posted 14 May 2011 - 08:22 PM

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

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