Author Topic: Axis-aligned bounding boxes  (Read 3288 times)

sfx1999

  • *
  • Posts: 1142
    • View Profile
Axis-aligned bounding boxes
« on: 2005-04-12 17:44:03 »
OK I am having a problem with this. I want to test if an AABB lies within the view frustum for my program. The problem is, it will always say that a box is not in the frustum if all points are outside the frustum. This means that if I have an AABB with all points outside of the frustum that STILL intersects with it, then it will say it is not in the frustum. Does anyone have an idea on how fix this?

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Axis-aligned bounding boxes
« Reply #1 on: 2005-04-13 09:07:10 »
Hmmm im not sure if I understand correctly .. but some simple math should do it. Try to draw your problem and post a pic.

sfx1999

  • *
  • Posts: 1142
    • View Profile
Axis-aligned bounding boxes
« Reply #2 on: 2005-04-14 21:10:07 »


As you see, the first one has a point in the frustrum, so it works. The problem is, the second one intersects, but has no points in the frustrum, so it fails.

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Axis-aligned bounding boxes
« Reply #3 on: 2005-04-15 06:44:41 »
Hmm .. what kind of math do you use to calculate it ? Is it something OpenGl ? 2d or 3d ?

In this case (2d) you could do it by calculating intersection of the half-line(vector) of view (A) with line segment of one of sides of the bounding box (B). In case they intersect the box is absolutely in the view. You have to decide how many box sides do you have to intersect.


I would post a simple c++ code for it, but I dont have my sourcecodes here :( So I tried googling, and here is some math to the intersecting: http://astronomy.swin.edu.au/~pbourke/geometry/lineline2d/

Ehm and sorry for my math english.

sfx1999

  • *
  • Posts: 1142
    • View Profile
Axis-aligned bounding boxes
« Reply #4 on: 2005-04-15 21:12:13 »
Well, what I was planning on doing in the first place was to take the dot product of the frustum planes' normals and the points and compare it to the plane's distance. Then, I thought about that scenario.

Anyway, you gave me an idea. I could first check to see if the box has points on opposite sides of that new plane you suggested, or after the orignal test. The only thing I will need to add another two planes for the other dimensions. I might only need one, because I don't see a chance in hell that something would span from all the way behind the frustum to all the way in front of it.

Micky

  • *
  • Posts: 300
    • View Profile
Axis-aligned bounding boxes
« Reply #5 on: 2005-04-16 10:31:03 »
You can do an initial fast test if all points of the AABB are outside a single plane of the frustum. If you can find one plane that separates the AABB from the frustum you can be sure it isn't in view. As you're most interested in rejecting as many AABBs as possible as fast as possible this should be enough.
If the AABB intersects one or more planes it may be visible. To be sure you could repeat the test with the planes from the AABB against the points of the frustum, but depending on the size of the AABB and the model you want to cull it may be easier to just draw it. YMMV.