# How do I construct the planes for my camera's frustum?

I'm trying to get a handle on frustum culling, but I'm not quite there yet.

I have a camera in three-dimensional space

Camera
position (cx, cy, cz)
rotation (tx, ty, tz)
fieldofview
near-plane
far-plane


and a quadtree containing my chunks of terrain

Quadtree
Chunk
bottomleft (x, y)
width
length
heightmap


Currently, I am rendering every chunk within the quadtree. However, I would like to cull all chunks outside the six planes of the camera's frustum.

I am unsure how to:

1. Generate these planes given the information in the camera class.
2. Efficiently test for intersection using my quadtree. If one region of the quadtree fails, do all of its children (that seems reasonable, I just want to make sure)? What is the process for running through a quadtree for culling?
3. Perform the intersection test using the planes and my terrain chunks. How do I quickly tell if a piece of terrain (square with varying y values) lies within the 6 camera planes?

Field of View and Aspect Ratio define how much the frustum planes diverge, so a little math should let you define the 4 planes of the viewport... but then you are stuck with plane/plane intersection tests

One approach would be to use the inverse of your camera and projection matrix to project the corners of the viewport some defined distance into the environment... the math is the same as used for handling mouse picking of 3D objects.. that will tell you the extents of the frustum planes. Use the same math with a very short (zero) distance to get the close in extents, then make the plane rectangular using the larger edges to expand the smaller.

Since you are only using a quadtree (for terrain I suppose ??) you might be better off just using your camera matrix to project the intersection points of the leaves to viewport space and then test if they are visible... if you get a hit, then the 4 leaves around a the given point are visible, and you can start drilling up/down to find the adjacent sections that are also have visible corners... start with the 4 points for the leaf you are on/above and work from there.

• This was helpful, thank you. When you say "stuck with plane/plane intersection tests" - how bad is that if I have to do 6 plane tests per logn chunks? – sdasdadas Aug 27 '14 at 22:48
• if you are testing against terrain you really only need to check the 2 sides against the terrain plane, or some simple abstraction of it (4 corners points with the altitude replaced with the average altitude of the 4 corners would work), to determine if a chunk of terrain is in the viewport... just make sure the side planes extend well below and above the terrain.... or you could even reduce it to a 2D test (line/plane intersection) in the terrain plane which would have even better performance – Ascendion Aug 28 '14 at 0:59