3

Is there a very fast way to check if a ray hit a cube? I know that i could just simply check every triangle of the cube, but there are a lot of rays and a lot of cubes, and it has to happen very fast. So is there a simple and fast way to check if a ray hit a cube? (Checking the spheres first is not an option right now.)

1 Answers1

0

Wait, wait, wait, Checking the spheres first is not an option right now? You've got the center of the cube, you have its dimensions, you can do sphere checking.

Even if you use the width directly rather than calculating the proper radius of the enclosing sphere, you're going to save a lot of checking.

Checking rays against polygons is simple. You can expand this to quads rather than triangles rather easily, since you know the pairs of polygons are always plane aligned, so you can cut down the number of checks by two.

Now, checking a ray-cube intersection directly is possible, and for a raytracer, it's pretty much necessary (although checking the sphere first is probably still a good idea). A relatively fast algorithm is presented in this paper - http://www.cs.utah.edu/~awilliam/box/box.pdf

Obviously, if your cubes are axis aligned, this can be done even faster, and if they are forming a grid, it becomes rather trivial.

Luaan
  • 62,244
  • 7
  • 97
  • 116