Quad Trees Implementation

Started by
2 comments, last by frob 5 years, 10 months ago

I have 2 questions about quad trees.

I'm planning to use quad trees for sphere-sphere, sphere-point, sphere-line and sphere-point collision detection.

1: How often do you typically update the tree ? Every frames ? Every time something changes in the scene (I have no trigger for that, but it shouldn't be hard to implement, however in my games stuff moves about every update tick)

2: How do you detect the number of object in each nodes ? Simple square test for each objects ? Isn't that inefficient if the purpose is to reduce calculations ?

Advertisement

Not sure what the common approaches are but here's what I use.

Create a slightly larger bounding box for every shape. Then for every shape, if it's not inside its bounding box anymore, then re-insert it into the tree. This means that only objects that are actually moving at noticeable speeds will need to be updated, and not every frame.

2 hours ago, FFA702 said:

1: How often do you typically update the tree ? Every frames ?

They are best left alone unless something has moved.  When something moves it may remain in the same box or it may move. 

If you must move items around, there is a variation called the loose quadtree where objects are allowed to drift beyond the bounds before the data actually requires adjustment.

3 hours ago, FFA702 said:

2: How do you detect the number of object in each nodes ?

Depends on your implementation details.  It is fairly common to return a collection of objects that intersect a shape or footprint. If you do that, you can use the size of that collection.

This topic is closed to new replies.

Advertisement