07 – Tutorial: Broadphase Collision Detection
Collision detection weaknesses Naive collision detection suffers from 3 known weaknesses Fixed-timestep weakness All-pairs weakness Pair-processing weakness Two-phase collision detection addresses most of these weaknesses using an initial broadphase that optimises the process by culling unneeded work
All pairs weakness n ( n 1 ) Normally Pairwise 2 comparisons are required O ( n ) 2 20 – objects = 190 pairs 2 objects: 10000 polygons However much of these is wasted work that could be eliminated by taking spatial coherence into account (i.e. Check object only against others in the neighbourhood)
Pair-processing Weakness Checking every single single primitive for a pair of objects is also too expensive First of all we use collision proxies which are simplified versions of our (display) objects A number of techniques exist to further cull computations. E.g. separating axis, closest features, BVH
Fixed Time-Step Weakness Position and orientation of body is updated at each time-step Interactions are only handled at these discrete time-steps Simulation time is incremented by fixed amount D t Large D t reduces accuracy of collision detection Smaller D t reduces efficiency of simulation
Two-phase collision detection Addressing the All-Pairs and Pair-Processing problems. Broad phase : efficiently cull pairs whose bounding boxes don’t overlap. “Sweep and Prune” exploits inter -frame coherence to achieve near O(n) performance [Cohen et al.1995] Narrow phase : utilise spatial localisation techniques to narrow in on the areas of objects which are in contact and use the underlying polygon model to determine the actual points of contact
Basic Simulation Loop Find New States Detect Collisions Respond to Collisions Collision detection is often broken down further (two phase collision detection) Broad Phase Narrow Phase Contact Modelling
Broad-phase collision detection 1. Bounding volumes 2. Spatial subdivision 3. Hierarchical hashing 4. Sweep and sort / Sweep and Prune 5. Space-time Bounds We exploit Spatial Coherence / Locality Temporal Coherency / Frame to frame coherence Kinematic knowledge
1. Bounding Volumes E.g. Bounding Sphere Find minimum enclosing sphere Find min+max (xyz) Find center of volume Find min radius Disadvantages: Not good fit for long/flat objects 2 O ( n ) Still for n = no. of spheres Collision check Advantages: D – distance between centres of 2 spheres Invariant to rotation update is simply a translation If D < sum of radii, then colliding Easy intersection test
2. Spatial subdivision E.g. Grid method Split scene up into uniform cells Each object keeps a record of grid cells that it overlaps with Only perform pair-wise collision test with objects in neighbouring grid cells Some annoying overhead, assumes finitely size scenes (closed room / box)
For more details, read [Mirtich] 3. Hierarchical Spatial Hashing Grid method problems If grid size is too big in relation to objects: too many false positives in narrow phase If grid size too small: too much work in broad phase single object could cover more than 1 grid position
4. AABB + Sweep and Prune Axis aligned Bounding Box Box with axes aligned to world x, y, and z Advantages: Computationally efficient Disadvantages: Unsatisfying fill efficiency, Not invariant to rotation: Requires, dynamic update of AABB OR Use very large AABB’s that Collision check is done through 3 x enclose object in all orientations 1d interval overlap tests, optimal solution is through sweep and prune (next slide) Representation: 6 vars (min, max in 3 dimensions) Generation: find min/max in 3 directions Update: update AABB (find min/max)
For more details, read [Cohen] 4. AABB + Sweep and Prune a.k.a. Sort and sweep X Y For each axis, s3 S3 S1 Create sorted list of start and end s1 S1 S2 points of intervals for each box 3 (use Insert Sort to exploit frame to E3 E1 e3 frame coherency) S2 S3 1 Traverse each list E1 E2 s2 Each time a startpoint is reached E2 E3 e1 insert into active list 2 If endpoint is hit remove it from active list e2 If 2 or more objects are active at the same time they overlap in the OVERLAP 1,2 specified dimension Potential colliding pairs must s1 s2 e1 s3 e2 e3 overlap in all 3 lists
5. Space Time Bounds Used in continuous collision detection Swept volumes that cover the occupancy of the object over an entire time-step
Swept-sphere Representation: Swept sphere is represented by line segment and radius Alternatively Minkowski sum of line and sphere Intersection test D = distance between 2 line segments If (D < sum of sweep radii) then intersecting
Hyper-trapezoid approximation of the Hyper-trapezoid parabolic horn Central axis calculated For a solid object from v(t- D t) Parabolic Horn is grown by r Radius at D t is <= a (t- D t) r is the radius of bounding sphere Further culling if we take into account the direction Intersection testing could be optimised through of a separating axis test see [Gomez]
Collision Management Rigid Body System A list of object to process for possible Rigid Body List collisions is usually kept in an activelist rb1 rb2 rb3 rb4 rb5 ... storing potential colliding pairs For Bounding Volume this starts off with size N^2 Active Collision List At each update, pc1 pc2 pc3 pc4 ... Update positions of object vertices, update Bounding Volumes or spatial data structure Collision_pair: Traverse active list and perform broad phase int a, b; and cull any non-colliders from active list Rigid_body *ra, Repeat traversal of active list with *rb; Further culling / BVH if applicable Then Narrow phase Rigid Body If colliding, construct contact model -Geometry and apply response -State variables
References [Cohen] Cohen, J. D., Lin, M. C., Manocha, D., and Ponamgi, M. 1995. I-COLLIDE: an interactive and exact collision detection system for large-scale environments. In Proceedings of the 1995 Symposium on interactive 3D Graphics . ( http://www.cs.jhu.edu/~cohen/Publications/icollide.pdf ) [Gomez] Miguel Gomez – “Simple Intersection Tests For Games” – Gamasutra, Oct 18, 1999 ( http://www.gamasutra.com/view/feature/3383/simple_intersection_tests_for_ games.php ) [Hashing] Demo and sample code (Spatial hashing): ( http://users.design.ucla.edu/~mflux/p5/hashcollision2/applet/ ) [Hubbard] Philip Hubbard – “Space time bounds for collision detection” TR CS -93- 04 Computer Science, Brown University, 1993. ( ftp://ftp.cs.brown.edu/pub/techreports/93/cs93-04.pdf ) [Mirtich] Brian Mirtich – “Efficient Algorithms for Two - Phase Collision Detection” TR9723 MERL, Dec, 1997. ( http://www.merl.com/reports/docs/TR97-23.pdf )
Also Read Game Physics by Dave Eberley 5.4.2 Culling with AABB (Sort and Sweep) Code available on www.geometrictools.com
Assignment 3: Broad Phase Collision Detection Demo due 15 th Feb, 2-4pm This assignment is worth ~8-10% of your final mark for the module Create a Rigid Body System (similar to particle system) to update state of a large collection of rigid bodies For this weeks lab simple linear and angular momentum should be enough (either reflect objects off edge of scene or loop around to keep them within your scene) Implement one of the following broad-phase collision detection schemes to flag potential colliders. Extra credit for some approaches. The percentage denotes the maximum mark you can get for the option Bounding sphere 70% Axis aligned bounding box 70% AABB with Sweep and Prune 100% Grid subdivision 70% Hierarchical Spatial Hashing 100% Swept-sphere space-time bounds 70%
Recommend
More recommend