Collision Detection and Resolution Zhi Yuan Course Introduction

  • Slides: 25
Download presentation
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development zyuan@cs. kent. edu

Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development zyuan@cs. kent. edu 11/28/2011 1

Overview q Collision Detection Identify the intersection of objects. q Collision Response Calculate the

Overview q Collision Detection Identify the intersection of objects. q Collision Response Calculate the appropriate response after collision. 2

Collision Detection q High complexity for two reasons: Ø Geometry is typically very complex,

Collision Detection q High complexity for two reasons: Ø Geometry is typically very complex, potentially requiring expensive testing. Ø Naïve solution is O(n 2) time complexity, since every object can potentially collide with every other object. 3

Dealing with Complexity q Two directions Ø Complex geometry must be simplified. Ø Reduce

Dealing with Complexity q Two directions Ø Complex geometry must be simplified. Ø Reduce number of object pair tests. 4

Simplified Geometry q Approximate complex objects with simpler geometry, like this ellipsoid. q Simpler

Simplified Geometry q Approximate complex objects with simpler geometry, like this ellipsoid. q Simpler Shape is cheaper to test. 5

BV: Bounding Volume q Key idea: ØSurround the object with a (simpler) bounding object

BV: Bounding Volume q Key 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. 6

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting

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

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting is better. q Simpler shape is better. Make it faster to compute with. 8

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting is better. q Simpler shape is better. q Rotation Invariant is better. Easier to update as object moves. 9

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting

Choosing a Bounding Volume q Lots of choices, each with tradeoffs. q Tighter fitting is better. q Simpler shape is better. q Rotation Invariant is better. q Convex is usually better. Gives simpler shape, easier computation. 10

Common Bounding Volumes: Sphere q Rotationally invariant. q Usually fast to compute with. q

Common Bounding Volumes: Sphere q Rotationally invariant. q Usually fast to compute with. q Store: center point and radius. Ø Center point: object’s center of mass. Ø Radius: distance of farthest point on object from center of mass. q Often not very tight fit. 11

Common Bounding Volumes: Axis Aligned Bounding Box (AABB) q Very fast to compute with.

Common Bounding Volumes: Axis Aligned Bounding Box (AABB) q Very fast to compute with. q Store: max and min along x, y axes. Look at all points and record max, min. q Moderately tight fit. q Must update after rotation. 12

Common Bounding Volumes: Oriented Bounding Box (OBB) q. Store rectangle oriented to best fit

Common Bounding Volumes: Oriented Bounding Box (OBB) q. Store rectangle oriented to best fit the object. q. Store: Ø Center. Ø Orthonormal set of axes. Ø Extent along each axis. q. Tight fit, but takes work to get good initial fit. q. Computation is slower than for AABBs. 13

Testing for Collision q Will depend on type of objects and bounding volumes. q

Testing for Collision q Will depend on type of objects and bounding volumes. q Specialized algorithms for each: Ø Sphere/sphere Ø AABB/AABB Ø OBB/OBB 14

Collision Test Sphere vs. Sphere q Find distance between centers of spheres. Compare to

Collision Test Sphere vs. Sphere q Find distance between centers of spheres. Compare to sum of sphere radii. q If distance is less, they collide. q For efficiency, check squared distance vs. square of sum of radii. d r 2 r 1 15

Collision Test AABB vs. AABB q Project AABBs onto given axes. q If overlapping

Collision Test AABB vs. AABB q Project AABBs onto given axes. q If overlapping on all axes, the boxes overlap. 16

Collision Test OBB vs. OBB q Separating Axis Theorem: Two convex shapes do not

Collision Test OBB vs. OBB q 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. 17

Enumerating Separating Axes q Two convex shapes do not overlap if and only if

Enumerating Separating Axes q 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. q How do we find axes to test for overlap? 18

Enumerating Separating Axes q Two convex shapes do not overlap if and only if

Enumerating Separating Axes q 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. 19

Enumerating Separating Axes q 2 D: check axis aligned with normal of each face.

Enumerating Separating Axes q 2 D: check axis aligned with normal of each face. q 3 D: check axis aligned with normal of each face and cross product of each pair of edges. 20

Enumerating Separating Axes q 2 D: check axis aligned with normal of each face.

Enumerating Separating Axes q 2 D: check axis aligned with normal of each face. q 3 D: check axis aligned with normal of each face and cross product of each pair of edges. 21

Enumerating Separating Axes q Two convex shapes do not overlap if and only if

Enumerating Separating Axes q 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. 22

Reduce number of object pair tests q One solution is to partition space uniformly.

Reduce number of object pair tests q One solution is to partition space uniformly. 23

Reduce number of object pair tests q Another solution is the plane sweep algorithm.

Reduce number of object pair tests q Another solution is the plane sweep algorithm. 24

References q Textbook: Introduction to Game Development by Steve Rabin, 2010, Second Edition, ISBN:

References q Textbook: Introduction to Game Development by Steve Rabin, 2010, Second Edition, ISBN: 1584506792 q http: //coitweb. uncc. edu/~tbarnes 2/Game. Design. Fall 05/. . . /Ch 4. 2 -Coll. Det. ppt q http: //www. sfu. ca/~shaw/iat 410/Lectures/08 Coll. Det. ppt q http: //www. cs. duke. edu/courses/cps 004/spring 04/notes/collisi on. ppt 25