Title: S95 Arial, Bld, YW8, 37 points, 105% line spacing
1Collision Detection
MAJ Keith M. Perkins, USA kmperkin_at_nps.navy.mil
2Outline
- Overview of Collision Detection
- Classification of the Problem
- Collision Detection Algorithms/Solutions
- Public Domain Packages
- Optimizing Collision Detection
- Collision Detection in Games
- Questions
3Overview of Collision Detection
- The goal of collision detection (also known as
interference detection or contact determination)
is to automatically report a geometric contact
when it is about to occur or has actually
occurred.. - -Ming C. Lin Stefan Gottschalk
- University of North Carolina
4Where is there a need?
- Computer-Aided Design and Machining (CAD/CAM)
- Robotics and Automation
- Manufacturing
- Computer Graphics
- Animation
- Computer Simulated Environments.
5A Taxonomy of 3D Model Representations
- 3D Models
- Nonpolygonal Models
Polygonal Models - Constructive Implicit Parametric
Structured Polygon Soups - Solid Surfaces Surfaces
-
Geometry - Convex Nonconvex
6Polygonal Models
- Most Commonly Used (Graphics/Modeling)
- Simple Representation
- Versatile
- Hardware Accelerated Rendering Widely Available
- Polygon Soup (Most General Class)
- Proper Solid
- Convex
7Constructive Solid Geometry(CSG)
- Forms Objects From Primatives
- Enables an Intuitive Design Process of Building
Shapes - Finding a Collision Witness Easier
- Certain Ops Difficult to Describe
- Hard to Compute an Accurate Boundary or Surface
Representation
8Implicit Surfaces
- Defined with Mappings from Space to the Real
Numbers F R3 ? R - f(x y z) 0 Model
- f(x y z) lt 0 Inside Model
- f(x y z) gt 0 Outside Model
- Generically Closed Manifolds (a desirable
property) - Algebraic
- Quadrics
9Parametric surfaces
- Defined with Mappings from Some Subset of the
Plane to Space F R2 ? R3 - Not Generally Closed Manifolds
- Easier to Polygonalize and Render
- (NURBS)
- Bezier patches
10What do We Need to Know?
- Whether two models touch?
- Which parts (if any) touch (find their
- intersection)?
- Their separation?
- The minimum Euclidean distance between
- disjoint objects?
- Minimum translational distance required to
- separate penetrating objects?
- When will be their next collision be? (ETA Comp)
11When do We Need to Know?
- Different Applications need different Queries
- Distance Information
- Robot Motion Control
- Dynamic Simulation
- Intersection Computation
- Physically Based Modeling
- Animation Systems
- ETA Solution
- Time Step Simulation (Quidditch)
12Simulation Environments
- Pair processing vs. nbody processing
- Motions static vs. dynamic
- Temporal Coherence.
- Rigid bodies vs. deformable models
- Collision detection between geometric
- models a survey
- Ming C. Lin Stefan Gottschalk
13Algorithms
- Lin-Canny Closest Feature Algorithm
- V-Clip
- I-COLLIDE
- RAPID
- V-COLLIDE
- Q-COLLIDE
- SOLID
- OBB-Tree
- QuickCD
- KDS
- Distance computation between convex polytopes
14Lin-Canny Closest Features
- Maintain Closest Features Pair
- Find Distance
- D lt epsilon ? Collision
15V-Clip
- Tracks Closest Features Pair
- Less Complex (Lin-Canny)
- More Robust (Lin-Canny)
- Handles Penetrating Polyhedra
16I-COLLIDE
- Large Environments of Convex Polyhedra
- Exploits Coherance and convexity
- Achieving fast and exact Collision Detection
- Tested
- Time required for Collision Detection Small
17RAPID
- Robust and accurate
- For pairs
- Polygon Soups
- Close proximity configurations
18V-COLLIDE
- Unites the nbody processing algorithm of
- I-COLLIDE and the pair processing algorithm
of - RAPID
- Allows dynamic addition or deletion of objects
19Q-COLLIDE
- Simple and Exact
- Separating Plane
- Witness
- Coherence
20SOLID
- Multiple three-dimensional polygonal objects
- polygon soups
- Rigid motion
- Performance V-COLLIDE
21OBB-Tree
- Oriented Bounding Boxes
- Tightly enclosing object
- OOBs allows fewer boxes than AABBs
22QuickCD
- Bounding Volumes (BV-trees)
- K-dops
23KDS
- Proof
- Certificates
- Allows for time-cost analysis and practical
solutions
24Distance Computation
- Distance computation between convex polytopes
- Distance tracking
- Requires a list of all edges for best performance
- Performance Lin_Canny
25Optimizing Collision Detection
- O(n2) ?(n2n)/2
- Objects Collision Tests
- 2 1
- 3 3
- 4 6
- 5 10
- 6 16
- 7 21
- 8 28
- 9 36
- 10 45
- 15 105
- 20 190
26Optimizing Collision Detection
- Eliminating Collision Tests
- 1 Player Spaceship
- 5 Player Missiles
- 20 Aliens
- 10 Alien Missiles
- -----
- 36 Objects 1296 tests (n2)
- 630 tests (n2n)/2
- Can Reduce to 180 tests (71 reduction)
-
27Optimizing Collision Detection
- Spatial-Test Elimination
- Good for large numbers of objects
- Requires additional bookeeping
- Sorts objects by position
- Objects only tested with object near by
28Optimizing Collision Detection
- Axis Sorting
- Sprite X-Coord Sprite Width
- 1 10 10
- 2 15 5
- 3 18 8
- 4 40 10
- 5 45 10
29Axis (Cont)
typedef struct _SPRITE_DATA
struct _SPRITE_DATA Next
int Top / sprite location /
int Left
int Width / sprite dimensions /
int Height
SPRITE_DATA
/
Function CollisionTestSorted
Description
Tests a linked list of sorted sprites to
see if they
potentially overlap. If so, they are
collision tested.
/
void CollisionTestSorted(SPRITE_DATA SpriteList)
SPRITE_DATA s1, s2
int s1Right
s1 SpriteList
while (s1 ! NULL)
s1Right s1-gtLeft s1-gtWidth - 1
/ Compare s1 with all following sprites
until left edge /
/ of a following sprite is located
beyond the right /
/ edge of s2. /
s2 s1-gtNext
while (s2 ! NULL (s1Right gt
s2-gtLeft))
CollisionTest(s1, s2)
s2 s2-gtNext
s1 s1-gtNext
30Optimizing Collision Detection
31Optimizing Collision Detection
- Hybrid Techniques
- Game Rules and Spatial
- Sector and Game Rules
- etc
-
-
32Optimizing Collision Detection
- Quick Tests
- Bounding based (use geometric objects)
- Fast, imperfect
- Pixel based
- More precise, much slower
-
-
33Bounding based (cont)
typedef struct
int Left
int Top
int Right
int Bottom
RECT
/
Function CollisionTestRect
Description
Tests two bounding rectangles to see if
they overlap.
Returns TRUE if so, FALSE otherwise.
/
BOOL CollisionTestRect(RECT r1, RECT r2)
if (r1-gtLeft gt r2-gtRight r2-gtLeft gt
r1-gtRight
r1-gtTop gt r2-gtBottom r2-gtTop gt
r1-gtBottom)
return FALSE
else
return TRUE
34Optimizing Collision Detection
- Combine Bounding and Pixel based
- Bounding first (usually negative)
- When positive, do the More Accurate Pixel
- Getting the most out of your collision tests
- Dave Roberts
35Collision Detection in Games
- We want realism (no phantom bullets)
- Many Avatars are Biped (Whats the problem)
- Most Shooter Games Navigate the user as a simple
shape -
MDK2
36Collision Detection in Games
- Resolving Collisions
- Sliding Vt Ni (-dot(Ni,Vt)-Nd)
- Vt Desired Target or Destination of Player
- Ni Normal to the plane of impact
- Nd The "D" of the hit poly's "plane equation"
-
MDK2
37Collision Detection in Games
- Resolving Collisions
- Stepping
- When was the last time you were crossing the
street and tripped on the curb? - Users dont want to worry about small steps and
stairs - Lift path
-
MDK2
38Collision Detection in Games
- Resolving Collisions
- Climbing
- A basic extension of step up ability
- Implementing if height transition is large enough
- Climbing animation also invoked
- Ease for user, no key press required, no special
skill to learn - BSP Collision Detection As Used in MDK2 and
NeverWinter Nights -
MDK2
39Questions?
40Questions
- Name two Collision Detection Algorithms
- I-COLLIDE, RAPID, SOLID, V-CLIP, OBB
- Name two methods to Optimize CD
- Spatial, Sector method, Axis Sorting
- Compare Bounding and Pixel Base Optimization
- Bounding Base is fast/imperfect
- Pixel Base is slow/accurate
41Contact Information
- Keith M. Perkins
- 2 University Circle, 2425
- Monterey, CA 93943
- (831) 656-4679
- kmperkin_at_nps.navy.mil