Download presentation
Presentation is loading. Please wait.
Published byColin Gardner Modified over 10 years ago
1
1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net www.algds.org squirrel@eiserloh.net www.algds.org
2
2 Types of Problems Knowing when to cheat Simplifying things Giving shape to things Moving things around Simulation baggage Detecting (and resolving) collisions Sustained interactions Dealing with the impossible Making it fast enough
3
3 Knowing When To Cheat
4
4 Knowing When to Cheat 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.
5
5 Knowing When to Cheat Ask: 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
6 Simplifying Things
7
7 Simplified bodies
8
8 Simplifying Things Simplified bodies Even more simplified bodies
9
9 Simplifying Things Simplified bodies Even more simplified bodies Convex bodies
10
10 Simplifying Things Simplified bodies Even more simplified bodies Convex bodies Homogeneous bodies
11
11 Simplifying Things Simplified bodies Even more simplified bodies Convex bodies Homogeneous bodies Rigid bodies
12
12 Simplifying Things Simplified bodies Even more simplified bodies Convex bodies Homogeneous bodies Rigid bodies Indestructible bodies
13
13 Simplifying Things Movement is often assumed to be in a vacuum (ignoring air resistance)
14
14 Simplifying Things Movement is often assumed to be in a vacuum (ignoring air resistance) Even when air resistance does get simulated, it is hugely oversimplified
15
15 Simplifying Things Collisions are often assumed to be perfect and elastic That is, 100% of the energy before the collision is maintained after the collision Think billiard balls
16
16 Giving Shape to Things
17
17 Giving Shape to Things N-sphere 2d: Disc 3d: Sphere
18
18 Giving Shape to Things N-sphere 2d: Disc 3d: Sphere Simplex 2d: Triangle 3d: Tetrahedron
19
19 Giving Shape to Things N-sphere 2d: Disc 3d: Sphere Simplex 2d: Triangle 3d: Tetrahedron Convex Polytope 2d: Convex Polygon 3d: Convex Polyhedron a.k.a. Convex Hull a.k.a. Brush (Quake)
20
20 Giving Shape to Things Discrete Oriented Polytope (DOP)
21
21 Giving Shape to Things Discrete Oriented Polytope (DOP) Oriented Bounding Box (OBB)
22
22 Giving Shape to Things Discrete Oriented Polytope (DOP) Oriented Bounding Box (OBB) Axis-Aligned Bounding Box (AABB)
23
23 Giving Shape to Things Discrete Oriented Polytope (DOP) Oriented Bounding Box (OBB) Axis-Aligned Bounding Box (AABB) Capsule
24
24 Giving Shape to Things Discrete Oriented Polytope (DOP) Oriented Bounding Box (OBB) Axis-Aligned Bounding Box (AABB) Capsule Cylinder (3d only)
25
25 Moving Things Around
26
26 Moving Things Around Kinematics Describes motion Uses position, velocity, momentum, acceleration
27
27 Moving Things Around Kinematics Describes motion Uses position, velocity, momentum, acceleration Dynamics Explains motion Uses forces...and impulses
28
28 Moving Things Around Kinematics Describes motion Uses position, velocity, momentum, acceleration Dynamics Explains motion Forces (F=ma) Impulses Rotation Torque Angular momentum Moment of inertia
29
29 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator
30
30 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator
31
31 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator
32
32 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator
33
33 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator
34
34 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator Which integration method to use?
35
35 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator Which integration method to use?
36
36 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator Which integration method to use?
37
37 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator Which integration method to use?
38
38 Moving Things Around How to compute the next position and velocity from current position and velocity? This process is called integration; An algorithm for doing this in an integrator Which integration method to use?
39
39 Simulation Baggage
40
40 Simulation Baggage Flipbook syndrome
41
41 Simulation Baggage Flipbook syndrome Things can happen in-between snapshots
42
42 Simulation Baggage Flipbook syndrome Things mostly happen in-between snapshots
43
43 Simulation Baggage Flipbook syndrome Things mostly happen in-between snapshots Curved trajectories treated as piecewise linear
44
44 Simulation Baggage Flipbook syndrome Things mostly happen in-between snapshots Curved trajectories treated as piecewise linear Terms often assumed to be constant throughout the frame
45
45 Simulation Baggage (contd) Error accumulates
46
46 Simulation Baggage (contd) Error accumulates Energy is not always conserved Energy loss can be undesirable Energy gain is evil Simulations explode!
47
47 Simulation Baggage (contd) Error accumulates Energy is not always conserved Energy loss can be undesirable Energy gain is evil Simulations explode! Rotations are often assumed to happen instantaneously at frame boundaries
48
48 Simulation Baggage (contd) Error accumulates Energy is not always conserved Energy loss can be undesirable Energy gain is evil Simulations explode! Rotations are often assumed to happen instantaneously at frame boundaries Numerical nightmares!
49
49 Collision Detection
50
50 Collision Detection We need to determine if A and B intersect
51
51 Collision Detection We need to determine if A and B intersect Worse yet, they could be (and probably are) in motion
52
52 Collision Detection We need to determine if A and B intersect Worse yet, they could be (and probably are) in motion If they did collide, we probably also need to know when they collided
53
53 Collision Response...and we need to figure out how to resolve the collision
54
54 Sustained Interactions
55
55 Sustained Interactions Surface contact
56
56 Sustained Interactions Surface contact Edge contact
57
57 Sustained Interactions Surface contact Edge contact Contact points Different solutions
58
58 Sustained Interactions Surface contact Edge contact Contact points Different solutions
59
59 Sustained Interactions Surface contact Edge contact Contact points Different solutions Stacking
60
60 Sustained Interactions Surface contact Edge contact Contact points Different solutions Stacking Friction Static & Kinetic
61
61 Sustained Interactions Surface contact Edge contact Contact points Different solutions Stacking Friction Static & Kinetic Constraints & Joints
62
62 Dealing With the Impossible
63
63 Dealing With the Impossible Interpenetration
64
64 Dealing With the Impossible Interpenetration Tunneling
65
65 Dealing With the Impossible Interpenetration Tunneling
66
66 Dealing With the Impossible Interpenetration Tunneling
67
67 Dealing With the Impossible Interpenetration Tunneling
68
68 Tunneling (Sucks)
69
69 Tunneling Small objects tunnel more easily
70
70 Tunneling (contd) Possible solutions Minimum size requirement? Inadequate; fast objects still tunnel
71
71 Tunneling (contd) Fast-moving objects tunnel more easily
72
72 Tunneling (contd) 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
73
73 Tunneling (contd) Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!
74
74 Tunneling (contd) Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!
75
75 Tunneling (contd) Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!
76
76 Tunneling (contd) Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!
77
77 Tunneling (contd) 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 shouldnt Players missing a trigger boundary
78
78 Tunneling (contd) Interpenetration Tunneling Rotational tunneling
79
79 Making It Fast Enough
80
80 Making It Fast Enough Dont be too particular too soon Avoid unnecessary work
81
81 Making It Fast Enough Dont be too particular too soon Avoid unnecessary work Eschew n-squared operations Avoid the everything vs. everything case
82
82 Making It Fast Enough Dont be too particular too soon Avoid unnecessary work Eschew n-squared operations Avoid the everything vs. everything case Try using simulation islands and space partitioning to divide and conquer
83
83 Simulation Islands Consider: 1000 objects, 1 island 1000x1000 checks = 1 Million checks
84
84 Simulation Islands Consider: 1000 objects, 1 island 1000x1000 checks = 1 Million checks Verses: 1000 objects, divided into 10 islands of 100 10 x (100x100) checks = 100,000 checks 1/10 th as many!
85
85 Simulation Islands Simulation islands can go to sleep when they become stable i.e. when forces and motion remain unchanged
86
86 Simulation Islands Simulation islands can go to sleep when they become stable i.e. when forces and motion remain unchanged
87
87 Simulation Islands Simulation islands can go to sleep when they become stable i.e. when forces and motion remain unchanged When an object enters the islands bounds...
88
88 Simulation Islands Simulation islands can go to sleep when they become stable i.e. when forces and motion remain unchanged When an object enters the islands bounds...
89
89 Simulation Islands Simulation islands can go to sleep when they become stable i.e. when forces and motion remain unchanged When an object enters the islands bounds......the island wakes up
90
90 Simulation Islands Add the newcomer to this simulation island
91
91 Simulation Islands Add the newcomer to this simulation island...and put it back to sleep once it stabilizes This is just one of many ways to reduce complexity Well be covering several others later on
92
92 Making It Fast Enough Can also exploit work previously done Make educated assumptions using: Temporal / frame coherence: Things tend not to have changed a whole lot in the 15ms or so since the previous frame, so save the previous frames results! Spatial coherence: Things tend to miss each other far more often than they collide, and only things in the same neighborhood can collide with each other
93
93 Summary
94
94 Summary The nature of simulation causes us real problems... problems which cant be ignored So we cheat And we simplify things And even then, it can get quite complex...
95
95 Summary (contd) Problems were concerned with: How should we choose to represent physical bodies? How should we simulate and compute motion? How can we prevent energy build-up? How do we cope with floating point error? How can we detect collisions – especially when large numbers of objects are involved? How can we prevent tunneling? How should we resolve penetration? How should we handle contact? How do we deal with non-rigid bodies? How can we relieve CPU burden?
96
96 Questions? Feel free to reach me by email at: squirrel@eiserloh.net
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.