Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: view frustum to AABB

  1. #1
    Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    335

    view frustum to AABB

    Hi,

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

  2. #2
    Intern Contributor
    Join Date
    Nov 2001
    Posts
    77

    Re: view frustum to AABB

    Code :
    Triangle 1
    in x-z plane
                    Triangle 2
          /|        in y-z plane
         /b|
      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:

    Code :
           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. ^^

  3. #3
    Member Regular Contributor remdul's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands
    Posts
    335

    Re: view frustum to AABB

    Thanks!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •