# OpenGL Approximate frustum culling

This topic is 4496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi! I am developing a game with a pretty big heightmap terrain and I'm an a tight schedule. I really need to get frustum culling implemented fast. I have piece of heigthmap terrain terrain, that I've divided into square shaped pieces which are in separate display lists. Now I'd need a quick way to check if to draw one of those pieces or not. Basic frustum culling. However, my system is very simple, the camera moves only along the x-axis, so it's always looking in the same direction. Also, there's nothing behind the camera. I figured that the easiest way to do "close enough" frustum culling is to check if one of the square-piece's corners is inside an infinite cone drawn around frustum. I don't have to worry about near and far planes. Now I'd need to know how to get the FOV of the cone. I am using gluPerspective, so I have fovy (constant) and aspect ratio (changing because of different aspect splitscreens). So, how to (easily) calculate the FOV from the center of the screen (the "front" vector) to the corner of the frustum? Any math, code or other form of help is welcome! Thanks in advance, -Riku P.S. Is someone heard of or using a similar culling method? The guys at #opengl@freenode said they hadn't even thought about it.

##### Share on other sites
gluPerspective() takes the vertical field of view as an argument, but you'll most likely need the horizontal fov for culling. Here's a function to convert from the former to the latter:
template < typename T >T yfov_to_xfov(T yfov, T aspect) {    return T(2.0 * std::atan(std::tan(yfov * T(.5)) * double(aspect)));}
The angle from the camera forward vector to a side plane of the frustum will then be half this value. (Remember to convert between radians and degrees as appropriate.)

That may not address all your questions, but perhaps it will help.

##### Share on other sites
deavik,
Thanks for the URL, a nice tutorial. I really do not need real frustum culling. There are plenty of tutorials on how to do that. I'll reconsider the need if it ends up harder to do a cone-frustum culling I want to do.

jyk,
I had already figured that out. I need the FOV from the center to the corner. I know a hard way to calculate it. Perhaps I'll plug that into Mathematica and simplify it or maybe I'll just use the traditional pen and paper way =).

What I've got is this:

diagonal_fov = 2.0 * atan( sqrt( tan(0.5 * fovx)^2 + tan(0.5 * fovy)^2 ) );

Does anyone know a simplified form of that? My trig is not that good.

Thanks guys!
-Riku

EDIT: diagonal_fov formula had a mistake, fixed

[Edited by - RichardoX on July 30, 2006 3:24:01 AM]

1. 1
Rutin
43
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633398
• Total Posts
3011661
• ### Who's Online (See full list)

There are no registered users currently online

×