Download presentation

Presentation is loading. Please wait.

Published byJulian Brooks Modified over 3 years ago

1
Physics for Games Programmers Reframing the Problem Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net www.algds.org squirrel@eiserloh.net www.algds.org

2
Physics for Games Programmers Reframing the Problem a.k.a. Its All Relative Squirrel Eiserloh Technical Director MumboJumbo Games squirrel@eiserloh.net www.algds.org squirrel@eiserloh.net www.algds.org

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

4
Tunneling (Sucks)

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

6
6 Tunneling

7
7

8
8

9
9

10
10 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 Tunneling is a false negative Okay, so tunneling really sucks. What can we do about it?

11
Movement Bounds

12
12 Movement Bounds Disc / Sphere

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

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

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

16
16 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 dont know for sure (false positive).

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

18
Swept Shapes

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

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

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

22
22 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

23
23 Swept Shapes (contd) Like movement bounds, only with a perfect fit!

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

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

26
26 Swept Shapes (contd) 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.

27
27 Swept Shapes (contd) 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.

28
28 Swept Shapes (contd) 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.

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

30
30

31
31 Einstein Says... Coordinate systems are relative

32
Relative Coordinate Systems

33
33 Relative Coordinate Systems World coordinates

34
34 Relative Coordinate Systems World coordinates As local coordinates

35
35 Relative Coordinate Systems World coordinates As local coordinates Bs local coordinates

36
36 Relative Coordinate Systems World coordinates As local coordinates Bs local coordinates Many others (e.g. origin at point of impact)

37
37 Relative Coordinate Systems (contd) Ball vs. world...

38
38 Relative Coordinate Systems (contd) Ball vs. world... in world coordinates

39
39 Relative Coordinate Systems (contd) Ball vs. world... in world coordinates x component y component

40
40 Relative Coordinate Systems (contd) Ball vs. world... in world coordinates x component y component in impact coordinates

41
41 Relative Coordinate Systems (contd) Ball vs. world... in world coordinates x component y component in impact coordinates parallel component perpendicular component

42
42 Relative Coordinate Systems (contd) Ball vs. world... in world coordinates x component y component in impact coordinates parallel component perpendicular component Change in motion happens along the perpendicular axis

43
43 Relative Coordinate Systems (contd) Ball vs. ball...

44
44 Relative Coordinate Systems (contd) Ball vs. ball... in world coordinates

45
45 Relative Coordinate Systems (contd) Ball vs. ball... in world coordinates x component y component

46
46 Relative Coordinate Systems (contd) Ball vs. ball... in world coordinates x component y component in impact coordinates

47
47 Relative Coordinate Systems (contd) Ball vs. ball... in world coordinates x component y component in impact coordinates parallel component perpendicular component Energy is exchanged along the perpendicular axis

48
48 Relative Coordinate Systems (contd) x 2 + y 2 = r 2 x 2 - 2xh + h 2 + y 2 - 2yk + k 2 = r 2 Also, math is often nicer at the origin.

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

50
Relative Motion

51
51 Relative Motion "Frames of Reference" World frame

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

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

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

55
55 Relative Motion (contd) 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)

56
56 (Does Not Suck)

57
Relative Collision Bodies

58
58 Relative Collision Bodies Collision check equivalencies (disc)

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

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

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

62
62 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 bodys origin

63
63 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 bodys origin

64
64 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 bodys origin

65
65 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 bodys origin

66
66 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 bodys origin

67
67 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 bodys origin

68
68 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 bodys origin

69
69 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 bodys origin

70
70 Relative Collision Bodies (contd) Disc + disc

71
71 Relative Collision Bodies (contd) Disc + disc AABB + AABB

72
72 Relative Collision Bodies (contd) Disc + disc AABB + AABB Triangle + AABB

73
73 Relative Collision Bodies (contd) Disc + disc AABB + AABB Triangle + AABB AABB + triangle

74
74 Relative Collision Bodies (contd) Disc + disc AABB + AABB Triangle + AABB AABB + triangle Polytope + polytope

75
75 Relative Collision Bodies (contd) Disc + disc AABB + AABB Triangle + AABB AABB + triangle Polytope + polytope Polytope + disc

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

77
Minkowski Arithmetic

78
78 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.

79
79 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)

80
80 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.

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

82
82 Minkowski Differences (contd) 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

83
83 Minkowski Differences (contd) If the singularity is outside the combined body, A and B do not overlap.

84
84 Minkowski Differences (contd) 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.

85
85 Minkowski Differences (contd) In world space, A-B is near the origin

86
86 Minkowski Differences (contd) A origin vs. B origin -B origin ___ (A-B) origin vs. 0

87
87 Minkowski Differences (contd) 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.

88
88 Minkowski Differences (contd) 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)

89
89 Minkowski Differences (contd) 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)

90
90 Minkowski Differences (contd) Translations in A or B simply translate the CSO

91
91 Minkowski Differences (contd) Rotations in A or B mutate the CSO

92
92 (Does Not Suck)

93
Relative Everything

94
94 Relative Everything Lets combine: Relative Coordinate Systems Relative Motion Relative Collision Bodies

95
95 Relative Everything (contd) A vs. B in world frame

96
96 Relative Everything (contd) A vs. B in world frame A is CSO, B is point

97
97 Relative Everything (contd) A vs. B in world frame A is CSO, B is point A is moving CSO, B is still point

98
98 Relative Everything (contd) A vs. B in world frame A is CSO, B is point A is moving CSO, B is still point A is still CSO, B is moving point This is the one we want!

99
99 Relative Everything (contd) 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 dont know WHEN they collided...

100
100 Relative Everything (contd) 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

101
101 Relative Everything (contd) Question #4: When, during the frame, did A and B collide? The time at which the ray intersects the CSO is the time at which the collision occurred. Finally, the right question - and we have a complete answer!

102
102 Relative Everything (contd) 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.

103
Quality vs. Quantity or You Get What You Pay For

104
104 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?

105
Rotations (Suck)

106
106 Rotations Continuous rotational collision detection sucks Rotational tunneling alone is problematic

107
107 Rotations Continuous rotational collision detection sucks Rotational tunneling alone is problematic Methods weve discussed here often dont work on rotations, or their rotational analogue is quite complex

108
108 Rotations (contd) 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

109
Summary

110
110 Summary 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.

111
111 Summary (contd) Einstein and Minkowski are cool. Rotations suck. Doing real-time collision detection doesnt have to be hard. Or expensive. Or confusing.

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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google