Spatial data structure for games

I need to implement a spatial data structure to store rectangles, and then find all the rectangles that intersect the given rectangle. This will be implemented in JavaScript.

So far I am developing a Quad Tree to reduce the search space, but as for the game, all moving objects must update their position in the tree. Return to the square.

Are there any data structures or methods? He will have to process about 10,000 objects, so brute force is not good enough.

+5
source share
2 answers

- , . - ODE.

. , . . javascript, python-ish.

for each ob in objects:
  for each x in [floor(ob.x_min / grid_size) .. floor(ob.x_max / grid_size)]:
    for each y in [floor(ob.y_min / grid_size) .. floor(ob.y_max / grid_size)]:
      hashtable[hash(x, y)].append(ob)

, -, .

near_collisions = []
for each x in [floor(ob.x_min / grid_size) .. floor(ob.x_max / grid_size)]:
  for each y in [floor(ob.y_min / grid_size) .. floor(ob.y_max / grid_size)]:
    near_collisions = near_collisions ++ hashtable[hash(x, y)]

remove duplicates from near_collisions

for each ob2 in near_collisions:
  if exact_collision_test(ob, ob2):
    do_something
+4

quadtree, - , , , .

, R-tree.

+2

All Articles