Jump to content

  • Log In with Google      Sign In   
  • Create Account

Frustrum culling window size at range


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Dun   Members   -  Reputation: 100

Like
0Likes
Like

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.

Sponsor:

#2 Danny02   Members   -  Reputation: 275

Like
1Likes
Like

Posted 13 May 2011 - 05:05 PM

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

#3 Dun   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 May 2011 - 12:04 AM

Thx, and how can i compute FOV angle?

#4 Danny02   Members   -  Reputation: 275

Like
0Likes
Like

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:

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







#5 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 14 May 2011 - 07:33 AM

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

#6 Dun   Members   -  Reputation: 100

Like
0Likes
Like

Posted 14 May 2011 - 09:18 AM

sorry, i forgot to mention. I use directX9.

#7 Danny02   Members   -  Reputation: 275

Like
0Likes
Like

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 gluPerspective and the fov for the y is calculated like above
so 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 x as it is in y.




#8 scgames   Members   -  Reputation: 1977

Like
0Likes
Like

Posted 14 May 2011 - 01:06 PM

yes they are, take a look at http://www.opengl.or...Perspective.xml

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?

#9 Trienco   Crossbones+   -  Reputation: 2224

Like
0Likes
Like

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).
f@dzhttp://festini.device-zero.de

#10 Danny02   Members   -  Reputation: 275

Like
0Likes
Like

Posted 14 May 2011 - 08:37 PM

yeah sry, I didn't thought everything through. Thanks for the explanation, seems as if the "official" docs aren't right all the time.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS