0

I have a quadtree set up for all static collision objects, which works great for both collision detection and raycasting

However, as I also have non-static collision objects, when I raycast I'd like to include them as possible collidable objects for the ray

What would be the best (in terms of performance) way to achieve this? My current ideas are:

1) clone the quadtree, add the non-static objects, then use that for the raycast

2) add the non-static objects to the current quadtree, with some flags that basically prevent the quadtree from splitting up its quads even if there are more children than allowed in a quad. The quadtree would then have to "clean up" after itself once the raycast is complete

3) after determining the closest static object collision (using the quadtree), just iterate through all non-static objects and see if the ray collides with them, and then check to see if the collision point is close than the closest static object collision point

All of these ideas seem a bit cumbersome though, so I'm looking for any alternative ideas that could be more performant

In case it matters, I'm using Java

Ben Ezard
  • 463
  • 6
  • 18

1 Answers1

0

At 1) Cloning the quadtree is probably very expensive if you have more than 10 objects, so I wouldn't do that.

At 2) Why not just keep a list of non-static objects? Just add all objects to the tree (I don;t see why splitting is a problem) and after the calculation rempove them from the tree.

At 3) This is quite expensive if you have many non-static object, but probably the cheapest solution if you have very few.

Some more ideas:

4) Build a second quadtree for non-static objects and do the collision detection (similar to 5) ). After the collision, simply discard the second tree.

5) If splitting nodes are really a problem, how about using a PH-Tree? It's like a quadtree, but it behaves a lot more static than a quadtree (no insert/delete will ever modify more than one node (except creating deleting one empty node in addition).

6) Depending on how fast your non-static objects are, you could use a 'moving object tree' (just google for it, there are some dedicated structures). If the objects are not too fast, the PH-Tree may again be a good choice, it has a dedicated move/update method.

TilmannZ
  • 1,784
  • 11
  • 18