Physics for Games Programmers Tutorial Motion and Collision – It’s All Relative Squirrel Eiserloh squirrel@eiserloh.net Lead Programmer Ritual Entertainment.

Slides:



Advertisements
Similar presentations
1 Radio Maria World. 2 Postazioni Transmitter locations.
Advertisements

The Fall Messier Marathon Guide
Números.
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
AGVISE Laboratories %Zone or Grid Samples – Northwood laboratory
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.

PDAs Accept Context-Free Languages
ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala
/ /17 32/ / /
Reflection nurulquran.com.
EuroCondens SGB E.
Worksheets.
& dding ubtracting ractions.
Physics for Games Programmers Reframing the Problem Squirrel Eiserloh Technical Director MumboJumbo Games
Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director Ritual Entertainment
1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games
RM WD-97 WD-101 WD-102 WD-124 a IIIh-H : RM110 (2.1) Hainan c agGY Ia-1 (2) Anhui agGY Ia-2 (3) agGY Ia WD-2 WD-8 WD-36 agGY Ia
STATISTICS Linear Statistical Models
Addition and Subtraction Equations
Multiplication X 1 1 x 1 = 1 2 x 1 = 2 3 x 1 = 3 4 x 1 = 4 5 x 1 = 5 6 x 1 = 6 7 x 1 = 7 8 x 1 = 8 9 x 1 = 9 10 x 1 = x 1 = x 1 = 12 X 2 1.
By John E. Hopcroft, Rajeev Motwani and Jeffrey D. Ullman
1 When you see… Find the zeros You think…. 2 To find the zeros...
Western Public Lands Grazing: The Real Costs Explore, enjoy and protect the planet Forest Guardians Jonathan Proctor.
Add Governors Discretionary (1G) Grants Chapter 6.
CALENDAR.
CHAPTER 18 The Ankle and Lower Leg
Summative Math Test Algebra (28%) Geometry (29%)
ASCII stands for American Standard Code for Information Interchange
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
The 5S numbers game..
突破信息检索壁垒 -SciFinder Scholar 介绍
A Fractional Order (Proportional and Derivative) Motion Controller Design for A Class of Second-order Systems Center for Self-Organizing Intelligent.
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
The basics for simulations
Factoring Quadratics — ax² + bx + c Topic
© 2010 Concept Systems, Inc.1 Concept Mapping Methodology: An Example.
MM4A6c: Apply the law of sines and the law of cosines.
2002 Prentice Hall, Inc. All rights reserved. Outline 25.1Introduction 25.2Basic HTML Tables 25.3Intermediate HTML Tables and Formatting 25.4Basic HTML.
Figure 3–1 Standard logic symbols for the inverter (ANSI/IEEE Std
The Camo Bots Hiding Since Team Members Mr. Brian Landry - Advisor Mr. Patrick Farley - Advisor Mr. Marty OHora - Advisor Doug Yatsonsky.
Dynamic Access Control the file server, reimagined Presented by Mark on twitter 1 contents copyright 2013 Mark Minasi.
Progressive Aerobic Cardiovascular Endurance Run
Slide P- 1. Chapter P Prerequisites P.1 Real Numbers.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
When you see… Find the zeros You think….
2011 WINNISQUAM COMMUNITY SURVEY YOUTH RISK BEHAVIOR GRADES 9-12 STUDENTS=1021.
Before Between After.
2011 FRANKLIN COMMUNITY SURVEY YOUTH RISK BEHAVIOR GRADES 9-12 STUDENTS=332.
ST/PRM3-EU | | © Robert Bosch GmbH reserves all rights even in the event of industrial property rights. We reserve all rights of disposal such as copying.
Subtraction: Adding UP
Numeracy Resources for KS2
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Static Equilibrium; Elasticity and Fracture
ANALYTICAL GEOMETRY ONE MARK QUESTIONS PREPARED BY:
Resistência dos Materiais, 5ª ed.
& dding ubtracting ractions.
Lial/Hungerford/Holcomb/Mullins: Mathematics with Applications 11e Finite Mathematics with Applications 11e Copyright ©2015 Pearson Education, Inc. All.
Doc.: IEEE /0333r2 Submission July 2014 TGaj Editor Report for CC12 Jiamin Chen, HuaweiSlide 1 Date: Author:
WARNING This CD is protected by Copyright Laws. FOR HOME USE ONLY. Unauthorised copying, adaptation, rental, lending, distribution, extraction, charging.
UNDERSTANDING THE ISSUES. 22 HILLSBOROUGH IS A REALLY BIG COUNTY.
A Data Warehouse Mining Tool Stephen Turner Chris Frala
1 Dr. Scott Schaefer Least Squares Curves, Rational Representations, Splines and Continuity.
Chart Deception Main Source: How to Lie with Charts, by Gerald E. Jones Dr. Michael R. Hyman, NMSU.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Introduction Embedded Universal Tools and Online Features 2.
What impact does the address have on the tribe?
Schutzvermerk nach DIN 34 beachten 05/04/15 Seite 1 Training EPAM and CANopen Basic Solution: Password * * Level 1 Level 2 * Level 3 Password2 IP-Adr.
Presentation transcript:

Physics for Games Programmers Tutorial Motion and Collision – It’s All Relative Squirrel Eiserloh squirrel@eiserloh.net Lead Programmer Ritual Entertainment www.ritual.com www.algds.org

Takeaway A comfortable, intuitive understanding of: The Problems of Discrete Simulation Continuous Collision Detection Applying Relativity to Game Physics Configuration Space Collisions in Four Dimensions The Problems of Rotation Why this is all really important even if you’re doing simple cheesy 2d games at home in your underwear in your spare time

The Problem Discrete physics simulation falls embarrassingly short of reality. “Real” physics is prohibitively expensive... ...so we cheat. We need to cheat enough to be able to run in real time. We need to not cheat so much that things break in a jarring and unrecoverable way. Much of the challenge is knowing how and when to cheat.

Overview Simulation Tunneling Movement Bounds Swept Shapes Einstein Says... Minkowski Says... Rotation

Also, I promise... No math

Simulation (Sucks)

Problems with Simulation Flipbook syndrome

Problems with Simulation Flipbook syndrome Things can happen in-between snapshots

Problems with Simulation Flipbook syndrome Things mostly happen in-between snapshots

Problems with Simulation Flipbook syndrome Things mostly happen in-between snapshots Curved trajectories treated as piecewise linear

Problems with Simulation Flipbook syndrome Things mostly happen in-between snapshots Curved trajectories treated as piecewise linear Terms often assumed to be constant throughout the frame

Problems with Simulation Flipbook syndrome Things mostly happen in-between snapshots Curved trajectories treated as piecewise linear Terms often assumed to be constant throughout the frame Error accumulates

Problems with Simulation (cont’d) Rotations are often assumed to happen instantaneously at frame boundaries

Problems with Simulation (cont’d) Rotations are often assumed to happen instantaneously at frame boundaries Energy is not always conserved Energy loss can be undesirable Energy gain is evil Simulations explode!

Problems with Simulation (cont’d) Rotations are often assumed to happen instantaneously at frame boundaries Energy is not always conserved Energy loss can be undesirable Energy gain is evil Simulations explode! Tunneling (Also evil!)

Overlapping Objects Question #1: Do A and B overlap? Plenty of reference material to help solve this, but... ...this is often the wrong question to ask (begs tunneling).

Tunneling (Sucks)

Tunneling Small objects tunnel more easily

Tunneling (cont’d) Possible solutions Minimum size requirement? Inadequate; fast objects still tunnel

Tunneling (cont’d) Fast-moving objects tunnel more easily

Tunneling (cont’d) Possible solutions Minimum size requirement? Inadequate; fast objects still tunnel Maximum speed limit? Inadequate; since speed limit is a function of object size, this would mean small & fast objects (bullets) would not be allowed Smaller time step? Helpful, but inadequate; this is essentially the same as a speed limit

Tunneling (cont’d) Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling

Tunneling (cont’d) Tunneling is very, very bad – this is not a “mundane detail” Things falling through world Bullets passing through people or walls Players getting places they shouldn’t Players missing a trigger boundary Okay, so tunneling really sucks. What can we do about it?

Movement Bounds

Movement Bounds Disc / Sphere

Movement Bounds Disc / Sphere AABB (Axis-Aligned Bounding Box)

Movement Bounds Disc / Sphere AABB (Axis-Aligned Bounding Box) OBB (Oriented Bounding Box)

Movement Bounds Question #2: Could A and B have collided during the frame? Better than Question #1 (solves tunneling!), but...

Movement Bounds Question #2: Could A and B have collided during the frame? Better than Question #1 (solves tunneling!), but... ...even if the answer is “yes”, we still don’t know for sure (false positives).

Movement Bounds Conclusion Good: They prevent tunneling! (i.e. no false negatives) Bad: They don’t actually tell us whether A and B collided (still have false positives). Good: They can be used as a cheap, effective early rejection test.

Swept Shapes

Swept Shapes Swept disc / sphere (n-sphere): capsule

Swept Shapes Swept disc / sphere (n-sphere): capsule Swept AABB: convex polytope (polygon in 2d, polyhedron in 3d)

Swept Shapes Swept disc / sphere (n-sphere): capsule Swept AABB: convex polytope (polygon in 2d, polyhedron in 3d) Swept triangle / tetrahedron (simplex): convex polytope

Swept Shapes Swept disc / sphere (n-sphere): capsule Swept AABB: convex polytope (polygon in 2d, polyhedron in 3d) Swept triangle / tetrahedron (simplex): convex polytope Swept polytope: convex polytope

Swept Shapes (cont’d) Like movement bounds, only with a perfect fit!

Swept Shapes (cont’d) Like movement bounds, only with a perfect fit! Still no false negatives (tunneling).

Swept Shapes (cont’d) Like movement bounds, only with a perfect fit! Still no false negatives (tunneling). Finally, no false positives, either!

Swept Shapes (cont’d) Like movement bounds, only with a perfect fit! Still no false negatives (tunneling). Finally, no false positives, either! No, wait, nevermind. Still have ‘em. Rats.

Swept Shapes (cont’d) Conclusion Suck? Can be used as early rejection test, but... ...movement bounds are better for that. If you’re not too picky... ...they DO solve a large number of nasty problems (especially tunneling) ...and can serve as a poor man’s continuous collision detection for a basic engine.

Einstein Says... Coordinate systems are relative

Relative Coordinate Systems

Relative Coordinate Systems World coordinates

Relative Coordinate Systems World coordinates A’s local coordinates

Relative Coordinate Systems World coordinates A’s local coordinates B’s local coordinates

Relative Coordinate Systems Math is often nicer at the origin. (x-h)2 + (y-k)2 = r2 x2 + y2 = r2

Einstein Says... Coordinate systems are relative Motion is relative

Relative Motion

Relative Motion "Frames of Reference" World frame

Relative Motion "Frames of Reference" World frame A's frame

Relative Motion "Frames of Reference" World frame A's frame B's frame

Relative Motion "Frames of Reference" World frame A's frame B's frame Inertial frame

Relative Motion A Rule of Relativistic Collision Detection: It is always possible to reduce a collision check between two moving objects to a collision check between a moving object and a stationary object (by reframing)

(Does Not Suck)

Relative Collision Bodies

Relative Collision Bodies Collision check equivalencies (disc)

Relative Collision Bodies Collision check equivalencies (disc) ...AABB

Relative Collision Bodies Collision check equivalencies (disc) ...AABB Can even reduce one body to a singularity

Relative Collision Bodies Collision check equivalencies (disc) ...AABB Can even reduce one body to a singularity “Tracing” or “Rubbing” collision bodies together

Relative Collision Bodies Collision check equivalencies (disc) ...AABB Can even reduce one body to a singularity “Tracing” or “Rubbing” collision bodies together Spirograph-out the reduced body’s origin

Relative Collision Bodies (cont’d) Disc + disc

Relative Collision Bodies (cont’d) Disc + disc AABB + AABB

Relative Collision Bodies (cont’d) Disc + disc AABB + AABB Triangle + AABB

Relative Collision Bodies (cont’d) Disc + disc AABB + AABB Triangle + AABB AABB + triangle

Relative Collision Bodies (cont’d) Disc + disc AABB + AABB Triangle + AABB AABB + triangle Polytope + polytope

Relative Collision Bodies (cont’d) Disc + disc AABB + AABB Triangle + AABB AABB + triangle Polytope + polytope Polytope + disc

Relative Collision Bodies (cont’d) Things start to get messy when combining bodies explicitly / manually. (Especially in 3d.) General solution?

Minkowski Arithmetic

Minkowski Sums The Minkowski Sum (A+B) of A and B is the result of adding every point in A to every point in B.

Minkowski Sums The Minkowski Sum (A+B) of A and B is the result of adding every point in A to every point in B. Minkowski Sums are commutative: A+B = B+A Minkowski Sum of convex objects is convex

Minkowski Differences The Minkowski Difference (A-B) of A and B is the result of subtracting every point in B from every point in A (or A + -B)

Minkowski Differences The Minkowski Difference (A-B) of A and B is the result of subtracting every point in B from every point in A Resulting shape is different from A+B.

Minkowski Differences (cont’d) Minkowski Differences are not commutative: A-B != B-A Minkowski Difference of convex objects is convex (since A-B = A+ -B)

Minkowski Differences (cont’d) Minkowski Differences are not commutative: A-B != B-A Minkowski Difference of convex objects is convex (since A-B = A+ -B) Minkowski Difference produces the same shape as “Spirograph”

Minkowski Differences (cont’d) If the singularity is outside the combined body, A and B do not overlap.

Minkowski Differences (cont’d) If the singularity is outside the combined body, A and B do not overlap. If the singularity is inside the combined body (A-B), then A and B overlap.

Minkowski Differences (cont’d) Aorigin vs. Borigin -Borigin -Borigin ___ ___ (A-B)origin vs. 0

Minkowski Differences (cont’d) In world space, A-B is “near” the origin

Minkowski Differences (cont’d) Since the singularity point is always at the origin (B-B), we can say... If (A-B) does not contain the origin, A and B do not overlap.

Minkowski Differences (cont’d) If (A-B) contains the origin, A and B overlap. In other words, we reduce A vs. B to: combined body (A-B) vs. point (B-B, or origin)

Minkowski Differences (cont’d) If A and B are in the same coordinate system, the comparison between A-B and the origin is said to happen in configuration space ...in which case A-B is said to be a configuration space obstacle (CSO)

Minkowski Differences (cont’d) Translations in A or B simply translate the CSO

Minkowski Differences (cont’d) Rotations in A or B mutate the CSO

Minkowski Sum vs. Difference Lots of confusion over Minkowski “Sum” vs. “Difference”. Sum is used to “fatten” an object by “adding” another object (in local coordinates) to it Difference is used to put the objects in configuration space, i.e. A-B vs. origin. Difference sometimes called Sum since A-B can be expressed as A+(-B)!

Minkowski Sum vs. Difference (cont’d) Difference is the same as “Spirograph” or “rubbing” Difference is not commutative! A-B != B-A Difference and sum produce different-shaped results Difference produces CSO (configuration space obstacle)

(Does Not Suck)

Relative Everything

Relative Everything Let’s combine: Relative Coordinate Systems Relative Motion Relative Collision Bodies

Relative Everything (cont’d) A vs. B in world frame

Relative Everything (cont’d) A vs. B in world frame A vs. B, inertial frame

Relative Everything (cont’d) A vs. B in world frame A vs. B, inertial frame A is moving, B is still

Relative Everything (cont’d) A vs. B in world frame A vs. B, inertial frame A is moving, B is still A is CSO, B is point

Relative Everything (cont’d) A vs. B in world frame A vs. B, inertial frame A is moving, B is still A is CSO, B is point A is moving CSO, B is still point

Relative Everything (cont’d) A vs. B in world frame A vs. B, inertial frame A is moving, B is still A is CSO, B is point A is moving CSO, B is still point A is still CSO, B is moving point

Relative Everything (cont’d) Question #3: Did A and B collide during the frame? Yes! We can now get an exact answer. No false negatives, no false positives! However, we still don’t know WHEN they collided...

Relative Everything (cont’d) Why does the exact collision time matter? Outcomes can be different Order of events (e.g. multiple collisions) is relevant Collision response is easier when you can reconstruct the exact moment of impact

Relative Everything (cont’d) The Minkowski Difference (A-B) / CSO can also be thought of as “the set of all translations [from the origin] that would cause a collision”. A.K.A. the set of “inadmissible translations”.

Determining Collision Time

Determining Collision Time Method #1: Frame Subdivision

Subdividing Movement Frame If a swept-shape (or movement bounds) test says “yes”:

Subdividing Movement Frame If a swept-shape (or movement bounds) test says “yes”: Cut the frame in half; perform two separate tests (first half first, second half second). First positive test is when the collision occurred.

Subdividing Movement Frame (cont’d) Can recurse (1/2, 1/4, 1/8...) to the desired level of granularity

Subdividing Movement Frame (cont’d) Can recurse (1/2, 1/4, 1/8...) to the desired level of granularity If both tests negative, no collision (was a false positive). Still inexact (minimizing, not eliminating, false positives) Gets expensive

Determining Collision Time Method #1: Frame Subdivision Method #2: 4D* Continuous Collision Detection *(N+1 dimensions; 3D for 2D physics, etc.)

Spacetime

Spacetime Spacetime is a Physics construct which combines N-dimensional space with an extra dimension for time, yielding a unified model with N+1 dimensions. Space (1D) + time (1D) = spacetime (2D) Space (2D) + time (1D) = spacetime (3D) Space (3D) + time (1D) = spacetime (4D)

Spacetime Diagrams 1D space + time = 2D Just an X vs. T graph!

Spacetime Diagrams 1D space + time = 2D 2D space + time = 3D Just an X vs. T graph! 2D space + time = 3D No problem.

Spacetime Diagrams 1D space + time = 2D 2D space + time = 3D Just an X vs. T graph! 2D space + time = 3D No problem. Another example (2d space + time = 3D)

Spacetime Diagrams 1D space + time = 2D 2D space + time = 3D ? Just an X vs. T graph! 2D space + time = 3D No problem. Another example (2d space + time = 3D) 3D space + time = 4D Brainbuster! ?

Spacetime Diagrams (cont’d) Note that an N-dimensional system in motion is the same as a still snapshot in N+1 dimensions 1D animation = 2D spacetime still image 2D animation = 3D spacetime still image 3D animation = 4D spacetime still image

Spacetime Diagrams (cont’d) 1D animation 2D spacetime still image

Spacetime Diagrams (cont’d) 2D animation 3D spacetime still image

Spacetime Diagrams (cont’d) How do you envision a 4D object? Use 2D animation -> 3D spacetime diagram as a mental analogy. Fun reading: Flatland by Edwin Abbott Think about a 4D object that you’re already familiar with. (The universe in motion!)

Spacetime Diagrams (cont’d) Invented by Hermann Minkowski Also called “Minkowski Diagrams”

(Rules)

Time-Swept Shapes

Time-Swept Shapes Sweep out shapes, but do it over time in a spacetime diagram Define time over frame as being in the interval [0,1] As before, we can play around with lots of relativistic variations:

Time-Swept Shapes (cont’d) A vs. B in world frame

Time-Swept Shapes (cont’d) A vs. B in world frame A is moving, B is still

Time-Swept Shapes (cont’d) A vs. B in world frame A is moving, B is still A is CSO, B is point

Time-Swept Shapes (cont’d) A vs. B in world frame A is moving, B is still A is CSO, B is point A is still CSO, B is moving (swept) point

Time-Swept Shapes (cont’d) To solve for collision time, we intersect the point-swept ray against the CSO The ‘t’ coordinate at the intersection point is the time [0,1] of collision Collision check is done in N+1 dimensions Which means, in a 3D game, we collide a 4D ray vs. a 4D body! (What?)

Time-Swept Shapes (cont’d) Wait, it gets easier... When we view this diagram (CSO vs moving point) down the time axis, i.e. from “overhead”: Since CSO is not moving, it looks 2D from overhead...

Time-Swept Shapes (cont’d) We can reduce this back down to N dimensions (from N+1) since we are looking down the time axis! So it becomes an N-dimesional ray vs. N-dimensional body again. Which means, in a 3D game, we collide a 3D ray vs. a 3D body.

Time-Swept Shapes (cont’d) Question #4: When, during the frame, did A and B collide? Finally, the right question - and we have a complete answer! With fixed cost, and with exact results (no false anything).

Time-Swept Shapes (cont’d) BTW, this is essentially the same as solving for the fraction of the singularity-translation ray from our original Minkowski Difference “inadmissible translations” picture!

or “You Get What You Pay For” Quality vs. Quantity or “You Get What You Pay For”

Quality vs. Quantity The more you ask, the more you pay. Question #1: Do A and B overlap? Question #2: Could A and B have collided during the frame? Question #3: Did A and B collide during the frame? Question #4: When, during the frame, did A and B collide?

Rotations (Suck)

Rotations Continuous rotational collision detection sucks Rotational tunneling alone is problematic

Rotations Continuous rotational collision detection sucks Rotational tunneling alone is problematic Methods we’ve discussed here often don’t work on rotations, or their rotational analogue is quite complex

Rotations (cont’d) However: Rotational tunneling is usually not as jarring as translational tunneling Rotational speed limits are actually feasible Can do linear approximations of swept rotations Can use bounding shapes to contain pre- and post-rotated positions This is something that many engines never solve robustly

Summary

Summary The nature of simulation causes us real problems... problems which can’t be ignored. Have to worry about false negatives (tunneling!) as well as false positives. Knowing when a collision event took place can be very important (especially when resolving it). Sometimes a problem (and math) looks easier when we look at it from a different viewpoint. Can combine bodies in cheaty ways to simplify things even further.

Summary (cont’d) Einstein and Minkowski are cool. Rotations suck. Doing real-time collision detection in 4D spacetime doesn’t have to be hard. Or expensive. Or confusing.

Questions? Feel free to reach me by email at: squirrel@eiserloh.net or squirrel@ritual.com