Collision Detection Collision detection weaknesses Naive collision - - PowerPoint PPT Presentation
Collision Detection Collision detection weaknesses Naive collision - - PowerPoint PPT Presentation
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
Collision detection weaknesses
Naive collision detection suffers from 3 known weaknesses Two-phase collision detection addresses most of these weaknesses using an initial broadphase that optimises the process by culling unneeded work
Fixed-timestep weakness All-pairs weakness Pair-processing weakness
All pairs weakness
Normally Pairwise comparisons are required However much of these is wasted work that could be eliminated by taking spatial coherence into account (i.e. Check object only against
- thers in the neighbourhood)
20 – objects = 190 pairs 2 objects: 10000 polygons
) ( ) (
2
n O 2 1 n n
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
- ur (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 Dt
Large Dt reduces accuracy of collision detection Smaller Dt 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
Broad Phase Narrow Phase Contact Modelling
Collision detection is often broken down further (two phase collision detection)
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 Still for n = no. of spheres
Advantages:
Invariant to rotation update is simply a translation Easy intersection test
Collision check
D – distance between centres of 2 spheres If D < sum of radii, then colliding
) (
2
n O
- 2. Spatial subdivision
E.g. Grid method Split scene up into uniform cells Each object keeps a record
- f 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)
- 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
For more details, read [Mirtich]
- 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 enclose object in all orientations Representation: 6 vars (min, max in 3 dimensions) Generation: find min/max in 3 directions Update: update AABB (find min/max) Collision check is done through 3 x 1d interval overlap tests, optimal solution is through sweep and prune (next slide)
- 4. AABB + Sweep and Prune
a.k.a. Sort and sweep For each axis,
Create sorted list of start and end points of intervals for each box (use Insert Sort to exploit frame to frame coherency)
Traverse each list
Each time a startpoint is reached insert into active list If endpoint is hit remove it from active list If 2 or more objects are active at the same time they overlap in the specified dimension Potential colliding pairs must
- verlap in all 3 lists
S3 S1 E3 S2 E1 E2 1 2 3 s3 e3 e1 s1 s2 e2 e2 e1 s2 e3 s1 s3 S1 S2 E1 S3 E2 E3 X Y OVERLAP 1,2 For more details, read [Cohen]
- 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
Central axis calculated from v(t-Dt) Radius at Dt is <= a(t- Dt) For a solid object Parabolic Horn is grown by r
r is the radius of bounding sphere
Hyper-trapezoid approximation of the parabolic horn
Further culling if we take into account the direction
- f a
Intersection testing could be optimised through separating axis test see [Gomez]
Collision Management
A list of object to process for possible collisions is usually kept in an activelist storing potential colliding pairs
For Bounding Volume this starts off with size N^2
At each update,
Update positions of object vertices, update Bounding Volumes or spatial data structure Traverse active list and perform broad phase and cull any non-colliders from active list Repeat traversal of active list with Further culling / BVH if applicable Then Narrow phase If colliding, construct contact model and apply response
Collision_pair: int a, b; Rigid_body *ra, *rb; Active Collision List Rigid Body System Rigid Body List Rigid Body
- Geometry
- State variables
rb1 rb2 rb3 rb4 rb5 ... pc1 pc2 pc3 pc4 ...
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 15th 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
- ff 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%