Download - 4.2 collision detection
![Page 1: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/1.jpg)
Chapter 4.2Collision Detection and Resolution
![Page 2: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/2.jpg)
2
Collision Detection
Complicated for two reasons1. Geometry is typically very complex,
potentially requiring expensive testing2. Naïve solution is O(n2) time complexity,
since every object can potentially collide with every other object
![Page 3: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/3.jpg)
Collision Detection
Two basic techniques1. Overlap testing
Detects whether a collision has already occurred
2. Intersection testing Predicts whether a collision will occur in the
future
![Page 4: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/4.jpg)
4
Overlap Testing Facts
Most common technique used in games Exhibits more error than intersection
testing Concept
For every simulation step, test every pair of objects to see if they overlap
Easy for simple volumes like spheres, harder for polygonal models
![Page 5: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/5.jpg)
5
Overlap Testing:Useful Results Useful results of detected collision
Time collision took place Collision normal vector
![Page 6: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/6.jpg)
6
Overlap Testing:Collision Time Collision time calculated by moving object
back in time until right before collision Bisection is an effective technique
B B
t 1
t 0 . 3 7 5
t 0 . 2 5
B
t 0
I t e r a t i o n 1F o r w a r d 1 / 2
I t e r a t i o n 2B a c k w a r d 1 / 4
I t e r a t i o n 3F o r w a r d 1 / 8
I t e r a t i o n 4F o r w a r d 1 / 1 6
I t e r a t i o n 5B a c k w a r d 1 / 3 2
I n i t i a l O v e r l a pT e s t
t 0 . 5t 0 . 4 3 7 5 t 0 . 4 0 6 2 5
BB B
A
A
A
AA A
![Page 7: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/7.jpg)
7
Overlap Testing:Limitations Fails with objects that move too fast
Unlikely to catch time slice during overlap Possible solutions
Design constraint on speed of objects Reduce simulation step size
t 0t - 1 t 1 t 2
b u l l e t
w i n d o w
![Page 8: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/8.jpg)
8
Intersection Testing Predict future collisions When predicted:
Move simulation to time of collision Resolve collision Simulate remaining time step
![Page 9: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/9.jpg)
9
Intersection Testing:Swept Geometry Extrude geometry in direction of movement Swept sphere turns into a “capsule” shape
t 0
t 1
![Page 10: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/10.jpg)
10
Intersection Testing:Sphere-Sphere Collision
Q 1
Q 2
P 1
P 2
P
Q
t = 0
t = 0
t = 1
t = 1
t
( ) ( ) ( )( ),
2
2222
B
rrΑBt
QP +−−⋅−⋅−=
BAΒΑ( ) ( ).QQPPB
QPA
1212
11
−−−=−=
![Page 11: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/11.jpg)
11
Intersection Testing:Sphere-Sphere Collision Smallest distance ever separating two
spheres:
If there is a collision
( )2
222
BAd
BA ⋅−=
( ) 22QP rrd +>
![Page 12: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/12.jpg)
12
Intersection Testing:Limitations Issue with networked games
Future predictions rely on exact state of world at present time
Due to packet latency, current state not always coherent
Assumes constant velocity and zero acceleration over simulation step Has implications for physics model and choice of
integrator
![Page 13: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/13.jpg)
13
Dealing with Complexity
Two issues1. Complex geometry must be simplified2. Reduce number of object pair tests
![Page 14: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/14.jpg)
14
Dealing with Complexity:Simplified Geometry Approximate complex objects with
simpler geometry, like this ellipsoid
![Page 15: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/15.jpg)
15
Dealing with Complexity:Minkowski Sum By taking the Minkowski Sum of two
complex volumes and creating a new volume, overlap can be found by testing if a single point is within the new volume
![Page 16: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/16.jpg)
16
Dealing with Complexity:Minkowski Sum
Y}B and :{ ∈∈+=⊕ XABAYX
X ⊕ Y⊕ =YX X ⊕ Y =
![Page 17: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/17.jpg)
17
Dealing with Complexity:Minkowski Sum
t 0
t 1
t 0
t 1
![Page 18: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/18.jpg)
18
Dealing with Complexity:Bounding Volumes Bounding volume is a simple geometric
shape Completely encapsulates object If no collision with bounding volume, no
more testing is required Common bounding volumes
Sphere Box
![Page 19: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/19.jpg)
19
Dealing with Complexity:Box Bounding Volumes
A x i s - A l i g n e d B o u n d i n g B o x O r i e n t e d B o u n d i n g B o x
![Page 20: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/20.jpg)
20
Dealing with Complexity:Achieving O(n) Time Complexity
One solution is to partition space
![Page 21: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/21.jpg)
21
Dealing with Complexity:Achieving O(n) Time Complexity
Another solution is the plane sweep algorithm
C
B
R
A
x
y
A 0 A 1 R 0 B 0 R 1 C 0 C 1B 1
B 0
B 1A 1
A 0
R 1
R 0
C 1
C 0
![Page 22: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/22.jpg)
22
Terrain Collision Detection:Height Field Landscape
T o p - D o w n V i e w
P e r s p e c t i v e V i e w
T o p - D o w n V i e w ( h e i g h t s a d d e d )
P e r s p e c t i v e V i e w ( h e i g h t s a d d e d )
![Page 23: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/23.jpg)
23
Terrain Collision Detection:Locate Triangle on Height Field
Q
R
Q
Q z > Q x
Q z < = Q x
z
x
R z > 1 - R x
R z < = 1 - R x
R
![Page 24: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/24.jpg)
24
Terrain Collision Detection:Locate Point on Triangle Plane equation: A, B, C are the x, y, z components of
the plane’s normal vector Where
with one of the triangles vertices being
Giving:
0=+++ DCzByAx
0PN ⋅−=D
0P
( ) ( ) ( ) ( ) 00 =⋅−+++ PNNNN zyx zyx
![Page 25: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/25.jpg)
25
Terrain Collision Detection:Locate Point on Triangle The normal can be constructed by taking the
cross product of two sides:
Solve for y and insert the x and z components of Q, giving the final equation for point within triangle:
( ) ( )0201 PPPPN −×−=
( )y
zzxxy N
PNQNQNQ 0⋅+−−
=
![Page 26: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/26.jpg)
26
Terrain Collision Detection:Locate Point on Triangle Triangulated Irregular Networks (TINs)
Non-uniform polygonal mesh Barycentric Coordinates
P 1
P 2
P 0
Q
P o i n t = w 0 P 0 + w 1 P 1 + w 2 P 2
Q = ( 0 ) P 0 + ( 0 . 5 ) P 1 + ( 0 . 5 ) P 2
R = ( 0 . 3 3 ) P 0 + ( 0 . 3 3 ) P 1 + ( 0 . 3 3 ) P 2R
![Page 27: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/27.jpg)
27
Terrain Collision Detection:Locate Point on Triangle Calculate barycentric coordinates for point
Q in a triangle’s plane
If any of the weights (w0, w1, w2) are negative, then the point Q does not lie in the triangle
( )
⋅⋅
⋅−
⋅−⋅−
=
2
1
2121
212
22
212
22
12
1 1
VS
VS
VV
VV
VV V
V
VVw
w
022
011
0
PPV
PPV
PQS
−=−=
−=
210 1 www −−=
![Page 28: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/28.jpg)
28
Collision Resolution:Examples Two billiard balls strike
Calculate ball positions at time of impact Impart new velocities on balls Play “clinking” sound effect
Rocket slams into wall Rocket disappears Explosion spawned and explosion sound effect Wall charred and area damage inflicted on nearby
characters Character walks through wall
Magical sound effect triggered No trajectories or velocities affected
![Page 29: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/29.jpg)
29
Collision Resolution:Parts Resolution has three parts
1. Prologue2. Collision3. Epilogue
![Page 30: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/30.jpg)
30
Collision Resolution:Prologue Collision known to have occurred Check if collision should be ignored Other events might be triggered
Sound effects Send collision notification messages
![Page 31: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/31.jpg)
31
Collision Resolution:Collision Place objects at point of impact Assign new velocities
Using physics or Using some other decision logic
![Page 32: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/32.jpg)
32
Collision Resolution:Epilogue Propagate post-collision effects Possible effects
Destroy one or both objects Play sound effect Inflict damage
Many effects can be done either in the prologue or epilogue
![Page 33: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/33.jpg)
33
Collision Resolution:Resolving Overlap Testing
1. Extract collision normal2. Extract penetration depth3. Move the two objects apart4. Compute new velocities
![Page 34: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/34.jpg)
34
Collision Resolution:Extract Collision Normal Find position of objects before impact Use two closest points to construct the
collision normal vector
![Page 35: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/35.jpg)
35
Collision Resolution:Extract Collision Normal Sphere collision normal vector
Difference between centers at point of collision
t 0
t 0
t 0 . 2 5
t 0 . 5
t 0 . 2 5
t 0 . 5
t 0 . 7 5
t 0 . 7 5
t 1
t 1
C o l l i s i o n
N o r m a l
![Page 36: 4.2 collision detection](https://reader035.vdocuments.us/reader035/viewer/2022062317/58f2e90a1a28aba4648b4571/html5/thumbnails/36.jpg)
36
Collision Resolution:Resolving Intersection Testing Simpler than resolving overlap testing
No need to find penetration depth or move objects apart
Simply1. Extract collision normal2. Compute new velocities