1 / 48

Lecture 17 – Physics 4

Lecture 17 – Physics 4. Wesley Kerr CS 490/590. Lecture Acknowledgements. Physics for Game Programmers: Problem Overview GDC 2008 Physics Tutorial Squirrel Eiserloh Physics for Game Programmers: Reframing the Problem GDC 2008 Physics Tutorial Squirrel Eiserloh Both Available

landis
Télécharger la présentation

Lecture 17 – Physics 4

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. Lecture 17 – Physics 4 Wesley Kerr CS 490/590

  2. Lecture Acknowledgements • Physics for Game Programmers: Problem Overview • GDC 2008 Physics Tutorial • Squirrel Eiserloh • Physics for Game Programmers: Reframing the Problem • GDC 2008 Physics Tutorial • Squirrel Eiserloh • Both Available • http://www.essentialmath.com/tutorial.html

  3. Types of Problems • Knowing when to cheat • Simplifying things • Giving shape to things • Moving things around • Discussed on Monday • Simulation Baggage • Detecting (and resolving) collisions • Sustained interactions • Dealing with the impossible • Making it fast enough

  4. Knowing When to Cheat • “Real” physics is prohibitively expensive… • … so we cheat • Keeps the computation running in real time • Cheats have to be carefully selected • Cannot break in jarring noticeable ways • Cannot result in unrecoverable physics • The challenge is really knowing how and when to cheat

  5. Knowing When to Cheat • Ask the following questions: • “Will the player notice?” • “Will the player care?” • “Will the results be predictable?” • “Are we at least cheating in a consistent way?” • “Will the simulation break?” • If the simulation breaks, they will notice and they will care • Some crimes are greater than others

  6. Simplifying Things • Simplified bodies • Collisions require geometry • Moving point masses is not enough • Must know where objects meet • Typically use convex shapes • Lines remain inside shape • Mathematically the easiest shapes to compute with • Assumed by most algorithms • Historical research performed on convex shapes • What do you do if the shape is not convex? • Break it up into several primitives

  7. Primitives • Axis Aligned Bounding-Box (AABB) • Intersection is very cheap • Project rectangle onto axes • Two intervals per box • Check both intervals overlap • Poor fit for most objects • Super Mario Bros. – works great • Diagonal boxes – not so great • False positives are likely

  8. Primitives • Axis Aligned Bounding-Box (AABB) • Intersection is very cheap • Project rectangle onto axes • Two intervals per box • Check both intervals overlap • Poor fit for most objects • Super Mario Bros. – works great • Diagonal boxes – not so great • False positives are likely

  9. Primitives • Axis Aligned Bounding-Box (AABB) • Oriented Bounding Box (OBB) • Tighter fit than AABB • Intersection more expensive • Must check 4 edges for overlap

  10. Primitives • Axis Aligned Bounding-Box (AABB) • Oriented Bounding Box (OBB) • Discrete Oriented Polytope (DOP) • Captures almost all convex shapes • Intersection is more expensive • O(n2), n = number of edges

  11. Primitives • Axis Aligned Bounding-Box (AABB) • Oriented Bounding Box (OBB) • Discrete Oriented Polytope (DOP) • Capsule • An OBB with rounded ends • Intersection cost is roughly the same • Efficient for swept shapes (circles)

  12. Primitives • Axis Aligned Bounding-Box (AABB) • Oriented Bounding Box (OBB) • Discrete Oriented Polytope (DOP) • Capsule • Circles/Disks • Not cheaper than AABB • Poor fit for approximating anything other than a circle

  13. Collision Detection • Question: • Do objects A and B intersect

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

  15. Collision Detection • Question: • Do objects A and B intersect • Challenge: • Can be in motion • Bigger Challenge: • Need to know when they collided. • Realistic physics needs the exact point of collision • Necessary for contact resolution

  16. Tunneling

  17. Tunneling

  18. Tunneling

  19. Tunneling

  20. Tunneling • Small objects tunnel more easily

  21. Tunneling • Possible solutions • Minimum size requirement? • Inadequate; fast objects can still tunnel

  22. Tunneling • Possible solutions • Minimum size requirement? • Inadequate; fast objects can still tunnel • Maximum speed limit? • Inadequate; speed limit is a function of object size, so small and fast objects (bullets) wouldn’t be allowed • Smaller time step? • Helpful but inadequate; essentially the same as a speed limit

  23. Tunneling • Why this is important! • Things can fall through the world • Bullets pass through people or walls • Players getting places they shouldn’t • Players missing trigger boundaries • Tunneling is a false negative • So what can we do about it?

  24. Movement Bounds • Disc / Sphere

  25. Movement Bounds • Disc / Sphere • AABB

  26. Movement Bounds • Disc / Sphere • AABB • OBB

  27. Movement Bounds • Question: • Could A and B have collided during the frame? • Better than our earlier question because it handles tunneling, but…

  28. Movement Bounds • Question: • Could A and B have collided during the frame? • Better than our earlier question because it handles tunneling, but… • … even if the answer is “yes”, we still don’t know for sure • false positives

  29. Movement Bounds • Conclusion • Good: they prevent tunneling • Bad: they produce false positives • Good: cheap, effective early rejection test

  30. Swept Shapes • Swept disc: capsule

  31. Swept Shapes • Swept disc: capsule • Swept AABB: polygon

  32. Swept Shapes • Swept disc: capsule • Swept AABB: polygon • Swept triangle: polygon

  33. Swept Shapes • Swept disc: capsule • Swept AABB: polygon • Swept triangle: polygon • Swept polytope: polygon

  34. Swept Shapes • Better fit than movement bounds

  35. Swept Shapes • Better fit than movement bounds • No false negatives (tunneling)

  36. Swept Shapes • Better fit than movement bounds • No false negatives (tunneling) • No false positives either!

  37. Swept Shapes • Better fit than movement bounds • No false negatives (tunneling) • No false positives either! • Nope! False positives still exist

  38. Swept Shapes • Better fit than movement bounds • No false negatives (tunneling) • No false positives either! • Nope! False positives still exist

  39. Collision Detection • Occurs in three phases • Broad Phase • Determine all pairs of objects that potentially collide • Sweep and Prune or Spatial Hashing • Mid phase • Determine potentially colliding primitives • Movement Bounds using AABBs • Narrow phase • Determine exact contact between two shapes • The Gilbert-Johnson-Keerthi (GJK) algorithm

  40. Collision Resolution • What happens once we finally find the collision? • Two types of collisions elastic and inelastic • Inelastic collisions • No energy preserved in collision • Ensure objects do not overlap • Extremely easy to implement • Elastic collisions • 100% energy preserved • More complicated to implement

  41. Simple Case: Circles • Simple collisions • Single point of contact • Impact coordinates • Point of contact is origin

  42. Simple Case: Circles • Simple collisions • Single point of contact • Impact coordinates • Point of contact is origin

  43. Simple Case: Circles • Simple collisions • Single point of contact • Impact coordinates • Point of contact is origin • Perpendicular component • Parallel component

  44. Simple Case: Circles • Simple collisions • Single point of contact • Impact coordinates • Point of contact is origin • Perpendicular component • Parallel component • Change in motion happens along the perpendicular axis

  45. Simple Case: Circles • Simple collisions • Single point of contact • Impact coordinates • Point of contact is origin • Perpendicular component • Parallel component • Exchange in energy happens along the perpendicular axis

  46. Complex Case • With complex shapes, the point of contact is more complex • Could be a single point • Could be an edge • Solution: • Break object into several points • Connect the points by constraints • Apply forces to each of the points • Transfer forces to other points while obeying constraints • Requires constraint solver

  47. Complex Case • With complex shapes, the point of contact is more complex • Could be a single point • Could be an edge • Solution: • Break object into several points • Connect the points by constraints • Apply forces to each of the points • Transfer forces to other points while obeying constraints • Requires constraint solver

  48. Summary • Accurate physics is challenging • We didn’t even cover rotational motion! • Accurate collision detection is challenging • We’ve seen the problems that a physics engine must solve • Tips for moving ahead • Structure game to make collision detection easy • Use circles, AABBs, grids, etc. • Kinematic dynamics is straightforward and may produce “good enough” results • Use a physics engine rather than writing your own.

More Related