2 hours ago, Pronova159 said:
I think you're looking for loose-leaf octrees/quadtrees. They're commonly used for dynamic objects and in collision systems. The idea is that as objects move, reinserting the object is costly, so you try to reduce the amount of reinsertions. Standard octree implementations subdivide a grid into equal but fixed-sized cubes. A loose-leaf tree would expand the AABB by a certain amount when doing the intersection tests, relaxing it to reduce the amount of reinsertions that take place during updates. Objects that travel shorter distances shouldn't need to reinsert.
Bear in mind that this is not the same thing as just increasing the scale of the octree's overall bounds. This loosened tree is at the same scale but insertions are determined mostly by the position of the object and it's depth is determined by the size of the object. This does cause the object's bounds to overlap multiple cells resulting in more queries but realistically this is offset by the higher quality tree that it produces. Loose-leaf trees have a tendency to pack objects in more efficiently separating clusters not only by position but by shape. Larger objects appearing closer to root and smaller objects towards the leaves. In contrast, normal octrees can have smaller objects near the root if their bounds intersect multiple cells.
The amount you need to relax the AABB has a significant affect to the quality of the tree an ultimately the performance of updates and queries. A larger amount would result in less reinsertions but have a less optimal tree fill which would slow down queries.
Hope this helps. I am by no means an expert but this is something I did before and it really improved the performance of my scene which had 5,000+ dynamic objects.
If you are right then my understanding of the term 'loose octree' is wrong (and i've never been sure of that).
I'll point this out, because i think i have a better solution for this (also i don't think i'm not the first one using it, but no tutorial covers this, so...)
There are multiple ways to handle objects intersecting the grid:
1. Put them in the lowest (internal or leaf) node that does not intersect (e.g. https://www.gamedev.net/articles/programming/general-and-gameplay-programming/introduction-to-octrees-r3529/ ) Problem: Intersecting objects cause much more tests than necessary - an object at world center collides with every object in the scene - unsteady performance between frames - very bad.
2. Put intersecting objects in multiple nodes. Requires to store a list of pointers to objects per node instead a single pointer, can't sort objects to tree without duplication, memory requirements unpredictable - still bad.
3. Put objects into internal and leaf nodes depending on their size. Objects are allowed to extend the grid by half cell size in every direction. This solves all above problems at the cost of a small increase of tests. (This is what i called 'loose octree', but i came up with it myself so let me know the proper name for it). It allows more movement as well but defines the rules exactly and more importantly: It allows to get the bounds from the grid, so no need to store a bounding box per node.
How does this relate to BVH?
BVH avoids those problems and offers the flexibility from ground up. It's only worth to mention that it makes sense to store large objects in interior nodes as well. If we store all objects just in the leafs, a large objects prevent small bounds, so small objects nearby collide with every other small object near the large one. If all your objects have similar size, it's better to put them all in the leafs.
(Decisions like that make it hard to give a good genaral example, so you find lots of research about details, but hardly a good introduction that fits your specific need. But a BVH node has just a bounding volume and some children - it's simple. You should not need a tutorial or a library to make it)
Personally i've implemented octree with update and neighbour pointers for collision detection. It worked well at that time but it's the hardest route to go and not very cache friendly. I've implemented BVH for rendering purposes only but i'd pick it for collision detection as well nowadays.