view frustum to AABB


I need to:
-calculate the four vertices of the view frustum far-plane
-calculate the four vertices of the view frustum near-plane

(Basicly I need to construct an Axis Aligned Bounding Box that fits around the view frustum.)

Resulting positions should be world space coordinates.

All I have is:
-camera x,y,z position (world coordinates)
-camera x,y,z rotation (world coordinates)
-camera fov angle
-camera far-plane distance
-camera near-plane distance

How do I do this? I know how to extract the six view frustum planes from the stack using the OpenGL API functions but I’m not sure they can be of use in an efficient way.

Note that my knowledge of math doesn’t go far beyond rotations and planes.

All help is appreciated…

[This message has been edited by remdul (edited 03-18-2004).]

Triangle 1
in x-z plane
                Triangle 2
      /|        in y-z plane
  C /  |        /|
   /   | A   F /e|
  /    |      /  | D
 /a   c|     /d f|
-------     -----
    B         E

The angle a is 1/2 of the field of view, and c is pi/2 radians (or 90 degrees). This means simple trigonometry can be used to find A (which will be the x coordinate for the either side of both the near and far planes):

tan a = A/B => B*tan a = A

so the distance to either plane times the tangent of 1/2 the field of view is equal to the distance from the center of the plane. Obviously, you need to adjust that for left and right.

Now, the y coordinate involves analyzation of triangle 2. Since the aspect ratio is rarely 1.0, the field of view is likely to represent the angle in the x-z plane, and not the y-z plane. So we need to adjust our triangle calculations to take this into account. The aspect ratio is always width/height. Since we’re dealing with height, not width we need to cancel them:

       1                  height
 ------------  * width =  ------ * width = height
 aspect ratio             width

So trigonometry using the second triangle is unnecessary. Just divide the width by the aspect ratio and you have the y coordinate.

This is just the viewing frustum for the identity transformation. However, once you find these values, simply transform them using the official transformation from object space to world space and it will give you the current viewing frustum coordinates in world space.

This is a general practice, and may not be 100% for every 3D graphics environment. Some may use the field of view to represent the vertical angle, and that would involve a little bit of tweaking. I hope this was helpful. ^^


Didn’t get it to work yet, but at least I got an understanding how to attack the problem.