Collision Detection and Resolution

25
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development [email protected] 11/28/2011 1

description

Collision Detection and Resolution. Zhi Yuan Course: Introduction to Game Development [email protected] 11/28/2011. Overview. Collision Detection Identify the intersection of objects. Collision Response Calculate the appropriate response after collision. Collision Detection. - PowerPoint PPT Presentation

Transcript of Collision Detection and Resolution

Page 1: Collision Detection and Resolution

1

Collision Detection and Resolution

Zhi YuanCourse: Introduction to Game Development

[email protected]/28/2011

Page 2: Collision Detection and Resolution

2

OverviewCollision Detection Identify the intersection of objects.

Collision ResponseCalculate the appropriate response after collision.

Page 3: Collision Detection and Resolution

3

Collision DetectionHigh complexity for two reasons:

Geometry is typically very complex, potentially requiring expensive testing.

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

Page 4: Collision Detection and Resolution

4

Dealing with ComplexityTwo directions

Complex geometry must be simplified.

Reduce number of object pair tests.

Page 5: Collision Detection and Resolution

5

Simplified GeometryApproximate complex objects with simpler geometry,

like this ellipsoid.

Simpler Shape is cheaper to test.

Page 6: Collision Detection and Resolution

6

BV: Bounding VolumeKey idea:

Surround the object with a (simpler) bounding object (the Bounding Volume).

If something does not collide with the bounding volume, it does not collide with the object inside.

Often, to intersect two objects, first intersect their bounding volumes.

Page 7: Collision Detection and Resolution

7

Choosing a Bounding VolumeLots of choices, each with tradeoffs.Tighter fitting is better. More likely to eliminate “false” intersections.

Page 8: Collision Detection and Resolution

8

Choosing a Bounding VolumeLots of choices, each with tradeoffs.Tighter fitting is better.Simpler shape is better.

Make it faster to compute with.

Page 9: Collision Detection and Resolution

9

Choosing a Bounding VolumeLots of choices, each with tradeoffs.Tighter fitting is better.Simpler shape is better.Rotation Invariant is better.

Easier to update as object moves.

Page 10: Collision Detection and Resolution

10

Choosing a Bounding VolumeLots of choices, each with tradeoffs.Tighter fitting is better.Simpler shape is better.Rotation Invariant is better.Convex is usually better.

Gives simpler shape, easier computation.

Page 11: Collision Detection and Resolution

11

Common Bounding Volumes: SphereRotationally invariant. Usually fast to compute with.Store: center point and radius.

Center point: object’s center of mass.

Radius: distance of farthest point on object from center of mass.

Often not very tight fit.

Page 12: Collision Detection and Resolution

12

Common Bounding Volumes:Axis Aligned Bounding Box (AABB)

Very fast to compute with.Store: max and min along x, y

axes. Look at all points and record max, min.Moderately tight fit.Must update after rotation.

Page 13: Collision Detection and Resolution

13

Common Bounding Volumes:Oriented Bounding Box (OBB)

Store rectangle oriented to best fit the object.

Store: Center.Orthonormal set of axes.Extent along each axis.

Tight fit, but takes work to get good initial fit.

Computation is slower than for AABBs.

Page 14: Collision Detection and Resolution

14

Testing for CollisionWill depend on type of objects and bounding

volumes.Specialized algorithms for each:

Sphere/sphereAABB/AABBOBB/OBB

Page 15: Collision Detection and Resolution

15

Collision Test Sphere vs. Sphere

Find distance between centers of spheres.Compare to sum of sphere radii.

If distance is less, they collide.For efficiency, check squared distance vs. square of

sum of radii.

dr2

r1

Page 16: Collision Detection and Resolution

16

Collision Test AABB vs. AABB

Project AABBs onto given axes.If overlapping on all axes, the boxes overlap.

Page 17: Collision Detection and Resolution

17

Collision Test OBB vs. OBB

Separating Axis Theorem:Two convex shapes do not overlap if and only if there exists an axis such that the projections of the two shapes do not overlap.

Page 18: Collision Detection and Resolution

18

Enumerating Separating AxesTwo convex shapes do not overlap if and only if there

exists an axis such that the projections of the two shapes do not overlap.

How do we find axes to test for overlap?

Page 19: Collision Detection and Resolution

19

Enumerating Separating AxesTwo convex shapes do not overlap if and only if there

exists an axis such that the projections of the two shapes do not overlap.

Page 20: Collision Detection and Resolution

20

Enumerating Separating Axes2D: check axis aligned with normal of each face.3D: check axis aligned with normal of each face and

cross product of each pair of edges.

Page 21: Collision Detection and Resolution

21

Enumerating Separating Axes2D: check axis aligned with normal of each face.3D: check axis aligned with normal of each face and

cross product of each pair of edges.

Page 22: Collision Detection and Resolution

22

Enumerating Separating AxesTwo convex shapes do not overlap if and only if there

exists an axis such that the projections of the two shapes do not overlap.

Page 23: Collision Detection and Resolution

23

Reduce number of object pair testsOne solution is to partition space uniformly.

Page 24: Collision Detection and Resolution

24

Reduce number of object pair testsAnother 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

B1A 1

A 0

R 1

R 0

C 1

C 0

Page 25: Collision Detection and Resolution

25

References Textbook: Introduction to Game Development by Steve

Rabin, 2010, Second Edition, ISBN: 1584506792

http://coitweb.uncc.edu/~tbarnes2/GameDesignFall05/.../Ch4.2-CollDet.ppt

http://www.sfu.ca/~shaw/iat410/Lectures/08CollDet.ppt

http://www.cs.duke.edu/courses/cps004/spring04/notes/collision.ppt