Spatial Partitioning
#1 Members - Reputation: 99
Posted 21 March 2011 - 06:59 PM
#2 Members - Reputation: 122
Posted 21 March 2011 - 08:01 PM
I just want to make a pretty big room with a bunch of objects and be able to simulate a ball bouncing and rolling around.
Sounds like a 2D room with 3D rendering, perhaps an Oct-Tree with ignoring the Y-Axis (Making it a quad-tree).
I only worked with Grid, and BSP-tree. BSP seems the most useless for games. I only learned about Oct-tree's never actually used them. The levels I made were all tile maps so partitioning all objects to a grid felt natural to the design.
#3 Members - Reputation: 100
Posted 21 March 2011 - 08:44 PM
#4 Members - Reputation: 176
Posted 21 March 2011 - 09:31 PM
To answer the original question, though, sweep-and-prune and bounding-volume hierarchies seem to be the most common techniques.
Here's some I've seen in actual use along with a few off-the-cuff descriptions:
- none (ODE dSimpleSpace)
- fine for a small number of objects
- slows down drastically as the number of objects goes up (O(N2))
- uniform grid (used by some tile-based games like N+)
- good match for worlds naturally divided into tiles
- allows efficient raycasts with with digital differential analyzer (DDA) algorithms
- requires a pre-defined world size
- can use a lot of memory (especially for a 3D grid--not advisable!)
- doesn't handle objects larger than the grid very well (must add them to multiple cells)
- multi-resolution grid
- different uniform grids for different-sized objects
- spatial hashing (what Chipmunk uses; ODE dHashSpace)
- variant of uniform grid that stores grid cells in a hash table instead of a fixed 2D or 3D array
- no longer requires a fixed world size
- memory usage proportional to number of objects, not world size
- sweep and prune / sort and sweep (what Box2D used to use; Bullet btAxisSweep3; ODE dSAPSpace)
- takes advantage of spatial and temporal coherence for efficiency
- great for detecting colliding pairs of objects
- not as good at handling raycasts
- straightforward implementations break down for very-fast-moving objects
- bounding volume hierarchy / AABB tree (what Box2D currently uses; Bullet btDbvtBroadphase; Newton Game Dynamics)
- no pre-defined limit on world size
- efficient spatial queries (i.e. finding all objects in a specified area/volume)
- may require periodic re-balancing unless the scene is static
- quadtree / octree (ODE dQuadTreeSpace)
StackOverflow has a good thread on this too.
#5 Members - Reputation: 308
Posted 22 March 2011 - 09:03 AM
I would use an Oct-Tree (More general term is an R-Tree) when there is no tile map. And some sort of grid when I have a tilemap. I dont have a webgl browser & the iink you provided doesn't work. From your description if the room is always a manageable size I might go with having a grid. If the level is pretty big, than an oct-tree.
I just want to make a pretty big room with a bunch of objects and be able to simulate a ball bouncing and rolling around.
Sounds like a 2D room with 3D rendering, perhaps an Oct-Tree with ignoring the Y-Axis (Making it a quad-tree).
I only worked with Grid, and BSP-tree. BSP seems the most useless for games. I only learned about Oct-tree's never actually used them. The levels I made were all tile maps so partitioning all objects to a grid felt natural to the design.
BSP seems most useless for games?? You're probably thinking of a limited spectrum of game types, BSP has fueled decades of in-doors FPS game engines right up until portals became popular, and many still use BSP trees
LinkedIn profile: http://ar.linkedin.com/pub/andres-ricardo-chamarra/2a/28a/272
#6 Members - Reputation: 99
Posted 22 March 2011 - 09:35 AM
#7 Members - Reputation: 176
Posted 22 March 2011 - 09:56 AM
It's fine to have a relatively loose collision broad-phase that returns false positives if it saves more processing cost than the extra narrow-phase collision tests it causes.
#8 Senior Moderators - Reputation: 1740
Posted 22 March 2011 - 10:51 AM
As a side note, octrees and R-trees are completely different data structures. R-trees are designed for range-searching very large databases of spatial information, and are the multidimensional analogue of B-trees. They're not widely useful for games.I would use an Oct-Tree (More general term is an R-Tree) when there is no tile map.
#9 Members - Reputation: 2369
Posted 22 March 2011 - 11:02 AM
I started to code that up, but since my testing is in WebGL/Javascript its kinda slow
You will notice that none of the demos have collision detection. There is a reason for that. Despite being called "fast", JavaScript is abysmally slow for this type of tasks.
Unless you implement it fully as a shader, the geometry collision detection isn't viable. So instead implement pseudo collision, such as testing against 2D plane that describes the floor.
JavaScript/WebGL is a pipedream that doesn't come close to what could be done on a 386. It's a nice concept, but it's wrong on so many levels that no amount of tweaking can fix that. Approximations and faking is the only viable way.






