2

I have a 3d space with a list of 3d axis-aligned bounding boxes. Let's call one of these bounding boxes the target. In addition to all these bounding boxes, I have a position vector, call it start.

I want to determine if a ray exists that:

  • Starts at start
  • Intersects target
  • Does not intersect with any other bounding boxes before intersecting with target

Here are the approaches I've already tried:

  1. Testing rays from start to all the vertices of target. This doesn't work because it's possible that other bounding boxes block all the vertices, but there is a space in the middle.
  2. Testing rays from start through the vertices of nearby bounding boxes, and seeing if any of them intersect target. This also doesn't work for cases where the target is blocked by an AABB where all corners cause rays to diverge from the target.

Is there an algorithm which can find rays like the above? I don't actually need to find the actual ray, just determine whether it exists.

konsolas
  • 1,041
  • 11
  • 24
  • 2
    This is called an *occlusion query*, and the fully analytic solution is very hard to implement. One would need to do polygon clipping in 3D space to determine whether the "outline frustum" of the target AABB from the perspective of `start` still exists after being clipped by the AABBs it intersects. **EDIT:** on second thought this can in-fact be reduced to an effective 2D problem by projecting all the polygons onto a plane, in which case a polygon clipping library like [Clipper](http://www.angusj.com/delphi/clipper.php) would be very helpful. – meowgoesthedog Mar 10 '18 at 23:49
  • 1
    If you want to employ GPU capabilities, you can try the following rendering-based approach: Set up a camera at `start` such that the target is completely in view. Then, render everything using a depth buffer (and output some object ID of sorts to the render target). Then, all you need to do is check if you have a pixel with the desired ID in the image. Accuracy can be adjusted through the image's resolution. – Nico Schertler Mar 12 '18 at 17:12

0 Answers0