1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo...

96
1 Physics for Games Physics for Games Programmers Programmers Problem Problem Overview Overview Squirrel Eiserloh Technical Director MumboJumbo Games [email protected] www.algds.org

Transcript of 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo...

Page 1: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

1

Physics for Games Physics for Games Programmers Programmers Problem Problem

OverviewOverview

Squirrel Eiserloh

Technical DirectorMumboJumbo Games

[email protected]

Page 2: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 3: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

3

Knowing When To Cheat

Page 4: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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.

Page 5: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 6: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

6

Simplifying Things

Page 7: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

7

Simplifying Things

Simplified bodies

Page 8: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

8

Simplifying Things

Simplified bodies Even more

simplified bodies

Page 9: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

9

Simplifying Things

Simplified bodies Even more

simplified bodies Convex bodies

Page 10: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

10

Simplifying Things

Simplified bodies Even more

simplified bodies Convex bodies Homogeneous

bodies

Page 11: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

11

Simplifying Things

Simplified bodies Even more

simplified bodies Convex bodies Homogeneous

bodies Rigid bodies

Page 12: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

12

Simplifying Things

Simplified bodies Even more

simplified bodies Convex bodies Homogeneous

bodies Rigid bodies Indestructible

bodies

Page 13: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

13

Simplifying Things

Movement is often assumed to be in a vacuum (ignoring air resistance)

Page 14: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 15: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 16: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

16

Giving Shape to Things

Page 17: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

17

Giving Shape to Things

N-sphere 2d: Disc 3d: Sphere

Page 18: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

18

Giving Shape to Things

N-sphere 2d: Disc 3d: Sphere

Simplex 2d: Triangle 3d: Tetrahedron

Page 19: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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)

Page 20: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

20

Giving Shape to Things

Discrete Oriented Polytope (DOP)

Page 21: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

21

Giving Shape to Things

Discrete Oriented Polytope (DOP)

Oriented Bounding Box (OBB)

Page 22: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

22

Giving Shape to Things

Discrete Oriented Polytope (DOP)

Oriented Bounding Box (OBB)

Axis-Aligned Bounding Box (AABB)

Page 23: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

23

Giving Shape to Things

Discrete Oriented Polytope (DOP)

Oriented Bounding Box (OBB)

Axis-Aligned Bounding Box (AABB)

Capsule

Page 24: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

24

Giving Shape to Things

Discrete Oriented Polytope (DOP)

Oriented Bounding Box (OBB)

Axis-Aligned Bounding Box (AABB)

Capsule Cylinder (3d only)

Page 25: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

25

Moving Things Around

Page 26: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

26

Moving Things Around Kinematics

Describes motion Uses position,

velocity, momentum, acceleration

Page 27: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

27

Moving Things Around Kinematics

Describes motion Uses position,

velocity, momentum, acceleration

Dynamics Explains motion Uses forces ...and impulses

Page 28: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 29: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 30: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 31: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 32: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 33: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 34: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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?

Page 35: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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?

Page 36: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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?

Page 37: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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?

Page 38: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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?

Page 39: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

39

Simulation Baggage

Page 40: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

40

Simulation Baggage

Flipbook syndrome

Page 41: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

41

Simulation Baggage

Flipbook syndrome Things can happen

in-between snapshots

Page 42: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

42

Simulation Baggage

Flipbook syndrome Things mostly

happen in-between snapshots

Page 43: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

43

Simulation Baggage

Flipbook syndrome Things mostly

happen in-between snapshots

Curved trajectories treated as piecewise linear

Page 44: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 45: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

45

Simulation Baggage (cont’d)

Error accumulates

Page 46: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

46

Simulation Baggage (cont’d)

Error accumulates Energy is not

always conserved Energy loss can be

undesirable Energy gain is evil

Simulations explode!

Page 47: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

47

Simulation Baggage (cont’d)

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

Page 48: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

48

Simulation Baggage (cont’d)

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!

Page 49: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

49

Collision Detection

Page 50: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

50

Collision Detection

We need to determine if A and B intersect

Page 51: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

51

Collision Detection

We need to determine if A and B intersect

Worse yet, they could be (and probably are) in motion

Page 52: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

Page 53: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

53

Collision Response

...and we need to figure out how to resolve the collision

Page 54: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

54

Sustained Interactions

Page 55: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

55

Sustained Interactions

Surface contact

Page 56: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

56

Sustained Interactions

Surface contact Edge contact

Page 57: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

57

Sustained Interactions

Surface contact Edge contact Contact points

Different solutions

Page 58: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

58

Sustained Interactions

Surface contact Edge contact Contact points

Different solutions

Page 59: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

59

Sustained Interactions

Surface contact Edge contact Contact points

Different solutions Stacking

Page 60: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

60

Sustained Interactions

Surface contact Edge contact Contact points

Different solutions Stacking Friction

Static & Kinetic

Page 61: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

61

Sustained Interactions

Surface contact Edge contact Contact points

Different solutions Stacking Friction

Static & Kinetic Constraints & Joints

Page 62: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

62

Dealing With the Impossible

Page 63: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

63

Dealing With the Impossible

Interpenetration

Page 64: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

64

Dealing With the Impossible

Interpenetration Tunneling

Page 65: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

65

Dealing With the Impossible

Interpenetration Tunneling

Page 66: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

66

Dealing With the Impossible

Interpenetration Tunneling

Page 67: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

67

Dealing With the Impossible

Interpenetration Tunneling

Page 68: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

68

Tunneling(Sucks)

Page 69: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

69

Tunneling

Small objects tunnel more easily

Page 70: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

70

Tunneling (cont’d)

Possible solutions Minimum size requirement?

Inadequate; fast objects still tunnel

Page 71: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

71

Tunneling (cont’d)

Fast-moving objects tunnel more easily

Page 72: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

72

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

Page 73: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

73

Tunneling (cont’d)

Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!

Page 74: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

74

Tunneling (cont’d)

Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!

Page 75: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

75

Tunneling (cont’d)

Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!

Page 76: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

76

Tunneling (cont’d)

Besides, even with min. size requirements and speed limits and a small timestep, you still have degenerate cases that cause tunneling!

Page 77: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

77

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

Page 78: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

78

Tunneling (cont’d)

Interpenetration Tunneling Rotational

tunneling

Page 79: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

79

Making It Fast Enough

Page 80: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

80

Making It Fast Enough

Don’t be too particular too soon Avoid unnecessary

work

Page 81: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

81

Making It Fast Enough

Don’t be too particular too soon Avoid unnecessary

work Eschew n-squared

operations Avoid the

“everything vs. everything” case

Page 82: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

82

Making It Fast Enough

Don’t 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

Page 83: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

83

Simulation Islands

Consider: 1000 objects, 1

island 1000x1000 checks = 1 Million checks

Page 84: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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/10th as many!

Page 85: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

85

Simulation Islands

Simulation islands can “go to sleep” when they become stable i.e. when forces and

motion remain unchanged

Page 86: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

86

Simulation Islands

Simulation islands can “go to sleep” when they become stable i.e. when forces and

motion remain unchanged

Page 87: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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 island’s bounds...

Page 88: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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 island’s bounds...

Page 89: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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 island’s bounds...

...the island wakes up

Page 90: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

90

Simulation Islands

Add the newcomer to this simulation island

Page 91: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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

We’ll be covering several others later on

Page 92: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

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 frame’s 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

Page 93: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

93

Summary

Page 94: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

94

Summary The nature of simulation causes us

real problems... problems which can’t be ignored

So we cheat And we simplify things And even then, it can get quite

complex...

Page 95: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

95

Summary (cont’d)

Problems we’re 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?

Page 96: 1 Physics for Games Programmers Problem Overview Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net  squirrel@eiserloh.net.

96

Questions?

Feel free to reach me by email at:

[email protected]