Chapter 4.2 Collision Detection and Resolution

Post on 20-Feb-2016

56 views 2 download

Tags:

description

Chapter 4.2 Collision Detection and Resolution. Collision Detection. Complicated for two reasons 1. Geometry is typically very complex, potentially requiring expensive testing 2. Naïve solution is O(n 2 ) time complexity, since every object can potentially collide with every other object. - PowerPoint PPT Presentation

transcript

Chapter 4.2Collision Detection and Resolution

2

Collision DetectionComplicated for two reasons

1. Geometry is typically very complex, potentially requiring expensive testing

2. Naïve solution is O(n2) time complexity, since every object can potentially collide with every other object

Collision DetectionTwo basic techniques

1. Overlap testing Detects whether a collision has already

occurred2. Intersection testing

Predicts whether a collision will occur in the future

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

5

Overlap Testing:Useful Results Useful results of detected collision

Time collision took place Collision normal vector

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

t1

t0.375

t0.25

B

t0

I ter a tio n 1F o rw ard 1 /2

I ter a tio n 2Bac k w ar d 1 /4

I ter a tio n 3F o rw ar d 1 /8

I ter a tio n 4F o r w ar d 1 /1 6

I ter atio n 5Bac k w ard 1 /3 2

I n it ia l O v er lapT es t

t0.5t0.4375 t0.40625

BB B

A

A

A

AA A

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

t0t -1 t1 t2b u lle t

w in d o w

8

Intersection Testing Predict future collisions When predicted:

Move simulation to time of collision Resolve collision Simulate remaining time step

9

Intersection Testing:Swept Geometry Extrude geometry in direction of

movement Swept sphere turns into a “capsule”

shapet0

t1

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

11

Intersection Testing:Sphere-Sphere Collision Smallest distance ever separating

two spheres:

If there is a collision

2

222

BAd BA

22QP rrd

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

13

Dealing with ComplexityTwo issues

1. Complex geometry must be simplified

2. Reduce number of object pair tests

14

Dealing with Complexity:Simplified Geometry Approximate complex objects with

simpler geometry, like this ellipsoid

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

16

Dealing with Complexity:Minkowski Sum

Y}B and :{ XABAYX

X Y =YX X Y =

17

Dealing with Complexity:Minkowski Sum

t0

t1

t0

t1

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

19

Dealing with Complexity:Box Bounding Volumes

Ax is -Alig n ed Bo u n d in g Bo x O r ien ted Bo u n d in g Bo x

20

Dealing with Complexity:Achieving O(n) Time ComplexityOne solution is to partition space

21

Dealing with Complexity:Achieving O(n) Time ComplexityAnother solution is the plane sweep

algorithm

C

B

R

A

x

y

A0 A 1 R 0 B0 R 1 C 0 C 1B1

B0

B1A1

A0

R 1

R 0

C 1

C 0

22

Terrain Collision Detection:Height Field Landscape

T o p - D o wn Vie w

P e r sp e c t iv e Vie w

T o p - D o wn Vie w ( h e igh t s a dde d)

P e r sp e c t iv e Vie w ( h e igh t s a dde d)

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

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

0PND

0P 00 PNNNN zyx zyx

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

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 in t = w 0P 0 + w 1P 1 + w 2P 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

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

12

121

212

22

212

22

12

1 1VSVS

VVVV

VV VV

VVww

022

011

0

PPVPPVPQS

210 1 www

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

29

Collision Resolution:Parts Resolution has three parts

1. Prologue2. Collision3. Epilogue

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

31

Collision Resolution:Collision Place objects at point of impact Assign new velocities

Using physics or Using some other decision logic

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

33

Collision Resolution:Resolving Overlap Testing1. Extract collision normal2. Extract penetration depth3. Move the two objects apart4. Compute new velocities

34

Collision Resolution:Extract Collision Normal Find position of objects before impact Use two closest points to construct the

collision normal vector

35

Collision Resolution:Extract Collision Normal Sphere collision normal vector

Difference between centers at point of collision

t0

t0

t0 . 2 5

t0 . 5

t0 . 2 5

t0 . 5

t0 . 7 5

t0 . 7 5

t1

t1

C o llis io n

N o rm a l

36

Collision Resolution:Resolving Intersection Testing Simpler than resolving overlap

testing No need to find penetration depth or

move objects apart Simply

1. Extract collision normal2. Compute new velocities