Original Post
With all the recent discussion of BSP versus octree, and the introduction of newer methods for speeding up rendering on modern video hardware, it seems that collision detection is just an afterthought that should be worried about after your bazillion-vertex level renders as fast as possible. I'm yet another person trying to make a 3D engine because I can't afford to license the big-name engines around and would rather sell my own game rather than make a mod and encourage sales of a game that I don't have any interest in promoting. As such, I'd like to have support for levels with relatively high polygon counts, which can be either indoors or outdoors.
It seems that rendering the level is fairly easy in comparison to doing collision detection with it - for rendering you have a dual-CPU system, but for collisions you only have 1 CPU to make use of. So how can you do accurate collision detection in hi-poly scenes that manage to make use of modern video hardware's incredible speed? There's a variety of spatial subdivision methods available, with many of them offering variations on the KD-tree (quake-style BSP, ABT, quadtree, octree) and others making use of constrained visibility to slice up the level into arbitrary chunks (portalized sectors). These are all great for rendering, and I've seen it said several times that "you should keep a separate structure for rendering and collision detection," but I haven't seen much elaboration past that statement as to which methods are good for doing that. There also is the trouble of keeping the structures synchronized when dealing with dynamic environments, and whether or not they even deal with the same geometry - some methods don't even worry about the actual geometry and just create AABB's and OBB's around the geometry to collide with. So, what is good and what is bad when dealing with collisions in hi-poly environments? Let's say that we want to deal directly with the level geometry to avoid any issues with inconsistencies between collision and visual geometry; here are some tidbits that I've gathered:
BSP: (Binary Space Partition) very expensive to compile for hi-poly scenes due to the complexity of the splitting plane selector and the polygon splitting incurred when resolving the multiple-reference issue. Once compiled, points can be tested for being inside/outside the mesh, rays can be cast through the splitting planes to find intersections with a simple check, and the splitting plane orientation provides the best solution for doing CSG.
Quadtree/Octree: Less expensive than BSP to compile due to the simplistic splitting plane selection. Still no better in terms of data bloat due to splitting - the simplistic subdivision plane selection incurs a lot of splitting or multiple references (depending on how you implement it). Casting rays through an octree can be fairly fast, although all leaves that are intersected have all their contained polygons checked for intersection. Cannot indicate inside/outside unless you start from a point that is known to be inside or outside and do a ray-cast to determine the number of intersections (assuming the mesh is closed and has a definite "inside"). The splitting penalty can be reduced and spatial locality and expense increased by using an adaptive splitting plane method. You can also make an octree/BSP hybrid and compile a BSP for each leaf, which may give you faster ray-casts through a leaf.
ABT: (Adaptive Binary Tree) Expense for compilation is somewhere in the middle, because the splitting plane selection is adaptive (it picks the best place it can for the splitting plane based on various criteria) but not as complex as a quake-style BSP because the splitting planes are all axis-aligned. Has the interesting feature that the volumes of the 2 children of a node don't necessarily sum to the same volume as the parent node, because each node uses a bounding box to get a more accurate representation of the volume taken up by the geometry it contains - the volume can be less when objects are separated by empty space, or more when objects butt up against each other and interpenetrate, in which case the volumes can also interpenetrate. As such, ray-casts can be done more quickly because more geometry can be rejected than with an octree, and the planes are axis-aligned which can result in quicker comparisons and less data bloat. Also has a better multiple-reference resolution system than BSP or octree because the splitting plane's selection function takes the amount of split geometry into account and tries to minimize it. I'm still not completely sure how the whole system works, because I've only seen discussion of it in relation to rendering hi-poly scenes and because I've seen figures of 2000 or more polygons in a leaf, which may be optimal for rendering when compared to the 1-poly leaves of BSP and 50-poly leaves of the average octree. Doing a brute-force collision test on 2000 polygons isn't the best idea though, so I'm interested in seeing a way to adapt this system to efficient collision detection - perhaps compile a BSP for each leaf and use that? The issue with inter-penetrating volumes might also be a problem because it's non-deterministic in choosing which child node to recurse into for checking for the first intersection of a ray.
Portals: more of a scenegraph thing than a spatial subdivision thing, since it relies on spatial subdivision or a human being to place portals appropriately. Don't really help with collision detection except to form a cutoff point for the amount of geometry in the local sector.
Hmm, I've rambled on for quite a while on all that now, and I hope I've got most of the important things noted. I don't really see an obvious choice when choosing a collision detection method, but it seems that the ABT is a good choice for getting high rendering speeds on shader-class hardware. I would like to use the same structure for both rendering speedup and collision detection, but that's not always possible. I just feel a little lost and not sure where to start when deciding how to go about computing collisions, and since I'd like to have both indoor and outdoor scenes, the issue is clouded even more. So please, I'd like any comments or discussion you have on this topic.
--
Andy Campbell
www.andyc.org
[edited by - Assassin on April 9, 2003 9:45:19 PM]