1 / 94

Animation and Games Development

Animation and Games Development. 242-515 , Semester 1 , 2014-2015. Objective to discuss some of the basic issues related to collision detection and collision response. 13. Collision Detection. Overview. Collision Detection Uses 2 . Collision Algorithms 3. Spatial Partitioning

donoma
Télécharger la présentation

Animation and Games Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Animation and Games Development 242-515, Semester 1, 2014-2015 • Objective • to discuss some of the basic issues related to collision detection and collision response 13. Collision Detection

  2. Overview • Collision Detection Uses 2. Collision Algorithms 3.Spatial Partitioning 4. Simplifying Shapes 5. Terrain Collision 6. Collision Time • The Tunneling Problem • More Complex Tunneling Solutions 9.Where do Objects Touch? 10. Collision Response Algorithms 11. Collision Changes 12. Momentum and Collisions 13. Complex Collisions 14. More Collision Issues 15.Summary

  3. 1. Collision Detection Uses • Determine if the player has a hit a wall or obstacle • Determine if a missile has hit a target • Detect when things should change • e.g. a hand touches a light switch • Clean up animation • Make sure a character’s feet touch the floor • To help implementing realistic motion • E.g. of cloth, water, fire

  4. Collision Detection and Response • Collision Detection • Check for the intersection of two objects • Calculate the trajectories of the objects, impact times, and impact points • Collision Response • provide a response that fits the game and (customized) laws of physics

  5. Types of Collisions • Main character and static objects: • terrain, floor, walls, furniture, buildings, etc. • Main character and dynamic objects: • enemies, bullets, arrows, particles, etc. • Dynamic game objects (e.g. enemies) and static and other dynamic objects.

  6. Convex Concave An object is convex if for every pair of points inside the object, the line joining them is also inside the object 2. Collision Algorithms • Shapes can be very complex, potentially requiring expensive testing: • points, line, convex/concave objects • Shapes move in different ways: • Use different algorithms for fast or slow moving objects • The algorithms will also depend on how frequently an object must be updated

  7. Design Principles • Design principles for collision algorithms. • Fast simple tests first to eliminate most potential collisions • e.g.: test bounding volumes before complex shapes • Exploit locality to eliminate many potential collisions • e.g. use spatial partitioning to avoid testing two objects that are far apart

  8. Use as much geometry informationas possible • e.g. spheres have special properties that make collision testing faster • Exploit coherence between successive tests • coherence means that things (objects) tend to stay the same over time

  9. Collisions in Pairs • Compare all game objects against all other objects, one pair at a time • This approach is easy to understand and to implement. • But it is slow -- O(n2) running time since every object can potentially collide with every other object.

  10. Non-collidable Objects • Include non-collidable objects in your game: • background: sky, clouds, grass, etc • dead enemies (maybe) • unimportant game objects • No need to include in collision testing, so speeds up the game.

  11. Collision Challenges • Question: • Do objects A and B intersect

  12. Collision Challenges • Question: • Do objects A and B intersect • Challenge: • Can be in motion

  13. Collision Challenges • Question: • Do objects A and B intersect • Challenge: • Can be in motion • Bigger Challenge: • Need to know whenthey collide. • Realistic physics needs the exact point of collision • Necessary for collision response

  14. Time-based Techniques • Priori: check if something is going to collide before moving it, then make the necessary correction • Posteri: check if something has collided and make the necessary corrections

  15. 3. Spatial Partitioning • Common types of spatial partitioning: • Octrees (called quadtrees in 2D) • Uniform Grids • Others types: portals (used in Quake), BSP trees (Binary Space Partitions), spatial hashing

  16. An Octree game regions game regions

  17. Data stored in each region: • coordinates defining the region • though a smart implementation can greatly simplify this • a list of objects inside a region

  18. Octree Drawbacks • Dynamic objects may move between regions • this requires the octree to be updated • A static (or dynamic) object may be positioned so it spans several regions • collision detection will involve objects from multiple regions

  19. Uniform Grids • Steps: • divide the (2D or 3D) world into a grid of equal sized cells • associate each object with the cells it is located inside • only objects sharing a cell are tested for collisions

  20. Calculating a Grid Position • What cells does the object currently occupy? • Possible calculations: • For min/max tile rows/columns: • sprite.X/tileWidth • sprite.Y/tileHeight • (sprite.X+sprite.Width)/tileWidth • (sprite.Y+sprite.Height)/tileHeight • For the 'man' object in cells (0,0), (0,1), (1,0), (1,1) • only test against: • other objects in those cells • also, don’t let an object occupy “collidable cells” (0,2), (1,2), etc 0 1 2 3 0 1 2

  21. Advantages • easy to implement • very fast: O(n) • Disadvantages • constrains look of game to a grid-like world

  22. 4. Simplifying Shapes • Typically divide an object into convex shapes • Mathematically the easiest shapes to compute with • Assumed by most algorithms • What do you do if the shape is not convex? • Break it up into several parts

  23. Bounding Volumes (BVs) • A simple geometry used in the collision tests instead of the shape’s real, complicated geometry. • Properties of good BVs: • inexpensive collision tests • tight fit to the original shape • inexpensive to create • easy to rotate and transform • uses little memory

  24. Common Bounding Volumes • AABBs:axis-aligned bounding boxes • OBBs: Oriented bounding boxes • DOPs: Discrete oriented polytopes

  25. In 3D

  26. AABBs • Axis Aligned Bounding-Boxes (AABBs) • Intersection is very cheap • Project rectangle onto axes • Two intervals per box • Check both intervals overlap • Poor fit for most objects

  27. Do AABB's Collide? • Common solution: • axis separation test • More sophisticated solution: • Plane Sweep: an extension of axis separation which is more efficient when dealing with many objects

  28. Axis Separation Test • How do we know if two AABBs are colliding? • their edges overlap on all axes NO COLLISION COLLISION A C B D

  29. Plane Sweep • Requires sorting of the objects along the axes • Running time: O(n)

  30. OBBs • Oriented Bounding Boxes (OBBs) • Tighter fit than AABB • Intersection more expensive • Must check 4 edges for overlap

  31. DOPs • Discrete Oriented Polytopes (DOPs) • Captures almost all convex shapes • Intersection is more expensive • O(a2), a = number of edges

  32. Capsule • Capsule • An OBB with rounded ends • Intersection cost is roughly the same • Efficient for swept shapes

  33. Circles/Disks • Circles/Disks • Not cheaper than AABB • Poor fit for anything other than a circle

  34. How about a Complicated Object? • We can use two AABBs to represent the object • Don’t test them against each other

  35. Multiple Bounding Boxes • Complex objects can have multiple bounding boxes • e.g. a Human object can have one big bounding box covering the whole body; or • one bounding box per limb, head, etc • Bounding boxes can be hierarchical: • Test the big 'human' box first • If there is a possible collision, test the smaller boxes inside the big one (e.g. the limb, head boxes)

  36. Bounding Box Hierarchies • Build a tree of boxes: • a parent box surrounds all the boxes of its children • Intersection test against a bounding box tree by travelling down the tree to a leaf box. • Generally used to test a moving object against lots of static obstacles • Put all the static obstacles into one large box tree

  37. 5. Terrain Collision • Utilizes the heightmap information, and the fact that the terrain is a mesh of triangles.

  38. Terrain Mesh and Heights

  39. Locate Triangle on Mesh Simplifies to a 2D problem of points inside triangles.

  40. Barycentric Coordinates • We can use Barycentric coordinates to test if a point is inside a triangle.

  41. 6. Collision Time • Given a ball with center at position p0= (x1, x2, x3), with initial velocity v = (v1, v2, v3), and a constant acceleration a = (a1, a2, a3). • When will its center hit a plane defined by f(x, y, z) = 0 ? • p = p0 + vt + ½ at2 • Solve the equation f(p) = 0

  42. Time Interval Problem • If the game is running at 30 fps, it only renders 1/30th of the object's states • sometimes called the Flipbook syndrome • Many things happen that we don’t see We don’t see the ball hit the ground

  43. 7. The Tunneling Problem • An object moves through another object because the collision testing is not done at the 'right' time: 8 7 6 time: 5

  44. Tunneling

  45. Tunneling Example

  46. Tunneling

  47. Tunneling

  48. Tunneling is a Big Problem • Things can fall through the floor • Cars can pass through people or walls • Players can enter rooms with no doors • Players can travel over holes • etc...

  49. Tunneling • Small objects can tunnel more easily than large shapes:

More Related