In my 2D game, I have static and dynamic objects. There can bemultiple cameras. My problem:Determineobjects that intersect with the current camera's viewrectangle.
Currently, I simply iterate over all existing objects (not caringwheter dynamic or static) and do an AABB check with the camerasview rect on them. This seems acceptable for very dynamic objects,but not for static objects, where there can be tens of thousands ofthem (static level geometry scattered over the whole scene).
I have looked into multiple data structures which could solve myproblem:
This was the first thing I considered, however the problem is thatit would force my scenes to be of fixed size. (Acceptable forstatic, but not for dynamic objects)
Seems good, but the overhead for rebalancing it seems just toogreat for many dynamic objects.
The main problem here for me was that if you zoom out with thecamera a lot, a huge number of mostly non-existing spatial hashbuckets had to be queried, causing low performance.
In general, my criterias for a good solution of this problemare:
Dynamic size: The solution must not cause the scene size to belimited, or require heavy recomputation for resizing
Good query performance (for the camera)
Good support of very dynamic objects: The computations needed tohandle objects with constantly changing position should begood:
The maximum sane number of dynamic objects in my game at one timeprobably is at 5000. Consider they all change their position everyframe. Is there even a data structure which can be faster,considering the frequent insertions and deletions, than comparingthe AABBs of the objects with the camera every frame?
Don't try to find the silver bullet. Just split your scene intodynamic and static parts and use different algorithms for them.
Quad trees are obviously suitable for static geometry with fixedbounds.
Spatial hashes are ideal for sets of objects with similarsizes
(particle systems, for example).
AFAIK dynamic AABB trees are rarely used for occlusion culling,their main purpose is the broad phase of collision detection.
And as you noticed, bruteforce culling is normal for dynamicobjects if the number of them is not really big.
static level geometry scattered over the whole scene
If your scene is highly-sparse, you can divide it into islands,i.e. create a list of scene parts with "good density".