Chapter 11 of the lecture Game Programming taught at HAW Hamburg.
Introduction to kinematics and dynamics, numerical integration, rigid bodies, collision detection and resolving.
2. Objectives
• To understand the basics of kinematics and dynamics in games
• To get an overview of a simple numeric integration approach for
phyics
• To learn how to resolve rigid body collisions
2 / 83
3. Motivation
• Next thing to make your game feel right, besides graphics and
sound
• Can be integral part of your gameplay
• Usually just a close approximation to real physics will be enough
“Speedy thing goes in, speedy thing comes out.”
- GLaDOS
3 / 83
4. Kinematics vs. Dynamics
• Kinematics is the study of movement over time.
▪ Doesn’t matter why things are where there are now
▪ Doesn’t matter what causes the movement
▪ Just deals with the actual movement itself
• Dynamics is the study of forces and masses that cause kinematic
quantities to change over time.
4 / 83
7. Change of velocity
Solving for v and integrating yields the velocity after a given time t,
aside from some unknown constant C:
7 / 83
𝐚 =
𝐝𝐯
𝐝𝐭
𝒅𝒗 = 𝒂 𝒅𝒕
𝒗(𝒕) = න 𝒂 𝒅𝒕
𝒗(𝒕) = 𝒂𝒕 + 𝑪
8. Change of velocity
We can find the unknown constant to be the initial velocity by
computing the initial velocity:
8 / 83
𝒗 = 𝒂𝒕 + 𝑪
𝒗 𝟎 = 𝟎𝒂 + 𝑪
𝒗 𝟎 = 𝑪
9. Change of velocity
Thus, given the acceleration a and initial velocity v0, the velocity after
any given time t is
9 / 83
𝒗(𝒕) = 𝒂𝒕 + 𝒗 𝟎
10. Change of position
The position after any given time t can be found the same way:
10 / 83
𝐯 =
𝐝𝐱
𝐝𝐭
𝒅𝒙 = 𝒗 𝒅𝒕
𝒅𝒙 = 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕
𝒙(𝒕) = න 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕
𝒙(𝒕) =
𝟏
𝟐
𝒂𝒕 𝟐
+ 𝒗 𝟎 𝒕 + 𝒙 𝟎
12. Dynamics – Force
Force is the rate of change of momentum over time (Newton’s Second
Law).
12 / 83
𝑭 =
𝒅𝒑
𝒅𝒕
13. Change of acceleration
For constant mass, force and acceleration are related as follows:
13 / 83
𝐹 = 𝐝𝐩
𝐝𝐭
definition force
= 𝒅 𝒎𝒗
𝒅𝒕
definition
momentum
=
𝒎
𝒅𝒗
𝒅𝒕
constant mass
= 𝒎𝒂 definition
acceleration
14. Numerical Integration
• Start at a certain initial position and velocity
• Take a small step forward in time to find the velocity and position at
the next time value
• Do this repeatedly to go forward in time in small increments, each
time taking the results of the previous integration as the starting
point for the next
14 / 83
15. Explicit Euler Integration
C#
15 / 83
// Fixed time step and constant force.
const float dt = 1;
const float force = 10.0f;
// Create new body without initial velocity.
var body = new Body
{
Mass = 1.0f,
Position = 0.0f,
Velocity = 0.0f
};
// Simulate ten steps.
for (float t = 1; t <= 10; t++)
{
body.Position += body.Velocity * dt;
var acceleration = force / body.Mass;
body.Velocity += acceleration * dt;
}
19. Variable vs. fixed time steps
Usually, we’re working with variable time steps in game simulations:
However, this approach has major drawbacks in when simulating
physics.
19 / 83
public void Update(float deltaTime)
{
// Do something awesome here...
}
20. Variable time steps in physics
• Physics will “feel” slightly different depending on your framerate
• Fast objects won’t collide as expected
• Spring simulation will explode to infinity
20 / 83
21. Fixed time steps in physics
• In order to ensure a fixed time step that feels right, we need to have
the physics simulation …
▪ Don’t update too often if frames are rendered very fast
▪ Catch up if frames are rendered very slowly
• This is achieved by accumulating deltas across frames, updating
several times per frame if necessary.
21 / 83
22. Fixed time steps in physics
C#
22 / 83
var random = new Random();
// Fixed time step and constant force.
const float fixedDt = 1f / 60f;
const float force = 10.0f;
float totalTime = 0.0f;
float accumulatedDt = 0.0f;
// Create new body without initial velocity.
var body = new Body { Mass = 1.0f, Position = 0.0f, Velocity = 0.0f };
// Simulate ten steps.
for (int t = 0; t <= 10; t++)
{
// Random delta.
float dt = (float)random.NextDouble() / 45;
totalTime += dt;
accumulatedDt += dt;
while (accumulatedDt > fixedDt)
{
var acceleration = force / body.Mass;
body.Velocity += acceleration * fixedDt;
body.Position += body.Velocity * fixedDt;
accumulatedDt -= fixedDt;
}
}
24. Gotcha!
Accumulated time steps can cause an
infinite loop if your physics simulation
takes more time than your fixed time
step!
Clamp at a maximum number of
simulation steps per frame to avoid this.
24 / 83
25. Rigid bodies
• All of the above assumes a constant mass concentrated in a single
point
• However, in games we have to deal with bodies having their mass
distributed over their area (or volume)
• Rigid bodies are shapes that don’t change or deform during physics
simulation
• We’ll focus on these for the time being
25 / 83
26. Rigid bodies
• For the time being, we’ll model our rigid body as a set of point
masses
• The total momentum of the rigid body equals the sum of all
momentums of all points that make up that body
𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 =
𝑖
𝑚𝑖 𝑣𝑖
26 / 83
27. Center of mass
We define the center of mass of a rigid body as the linear combination
of the position vectors of all points that make up that body, weighted by
their masses, divided by the total mass of the body.
𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 =
σ𝑖 𝑥𝑖 𝑚𝑖
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
27 / 83
28. Center of mass
Let’s modify this equation a bit:
28 / 12
𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 = σ𝑖 𝑥𝑖 𝑚𝑖
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 =
𝑖
𝑥𝑖 𝑚𝑖
multiplied with
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
=
𝑖
𝑑(𝑥𝑖 𝑚𝑖)
𝑑𝑡
𝑑/𝑑𝑡
=
𝑖
𝑚𝑖
𝑑𝑥𝑖
𝑑𝑡
constant mass
=
𝑖
𝑚𝑖 𝑣𝑖
definition velocity
= 𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 definition
momentum
29. Center of mass
Now, let’s take a look at the second part again:
29 / 83
𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
=
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠
𝑑𝑡
constant
mass
= 𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 definitio
n
velocity
30. Center of mass
Combining both results yields a stunning property
of the center of mass!
𝒑 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 = 𝑴 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 𝒗 𝑪𝒆𝒏𝒕𝒆𝒓𝑶𝒇𝑴𝒂𝒔𝒔
30 / 83
31. Center of mass
Combining both results yields a stunning property
of the center of mass!
𝒑 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 = 𝑴 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 𝒗 𝑪𝒆𝒏𝒕𝒆𝒓𝑶𝒇𝑴𝒂𝒔𝒔
For finding the momentums of any rigid body, we
can treat that body as single point mass and
velocity.
31 / 83
32. Center of mass
This further applies to forces, as well:
32 / 83
𝐹𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 = 𝑑𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑡
= 𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
as we’ve just proven
=
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠
𝑑𝑡
constant mass
= 𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑎 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 definition
acceleration
33. Center of mass
This further applies to forces, as well:
We can treat all forces acting our rigid body as if
their sum is acting on a point at the center of mass
with the mass of the entire body.
33 / 83
𝐹𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 = 𝑑𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑡
= 𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
as we’ve just proven
=
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠
𝑑𝑡
constant mass
= 𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑎 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 definition
acceleration
34. Rotation
• So far, we’ve been talking all about linear momentum and linear
acceleration.
• Now, we want to figure out how forces applied to our rigid bodies
make them rotate.
• Where these forces are applied to the body will play an important
role.
34 / 83
35. Kinematics – Orientation
The orientation Ω of an object is the angular difference between the
world coordinate system and a coordinate system fixed in that object, in
radians.
35 / 83
36. Kinematics – Angular Velocity
Angular Velocity is the rate of change of orientation over time.
36 / 83
𝝎 =
𝒅Ω
𝒅𝒕
37. Kinematics – Angular Acceleration
Angular Acceleration is the rate of change of angular velocity over time.
37 / 83
𝜶 =
𝒅 𝜔
𝒅𝒕
38. Linear Velocity from Angular Velocity
• We often need to find the velocity of an arbitrary point on our object
▪ i.e. velocity of colliding points to compute how hard they hit each
other
• Without rotation, the velocity of any point in the body is the same
▪ Velocity of the center of mass
• With rotation, every point might have a different velocity
▪ Obviously, we can’t keep track of the velocity of each of the
infinity of points
38 / 83
39. Linear Velocity from Angular Velocity
Claim:
The linear velocity of any point P inside an object that is rotating about
its origin O, but not translating, is given by the following equation:
39 / 83
𝒗 𝑷 = 𝝎𝑶𝑷⊥
40. Hint
In 2D, the perpendicular of a
vector (x, y) is (-y, x).
40 / 83
41. Linear Velocity from Angular Velocity - Proof
𝝎𝑶𝑷⊥ has the correct magnitude, because
and Ω 𝑶𝑷 is the length P is moving when moving Ω
radians along the arc whose radius vector is 𝑶𝑷 , by
definition of radians. 41 / 83
𝜔𝑂𝑃⊥
= 𝜔 𝑂𝑃⊥
= 𝜔 𝑂𝑃 perpendiculary
doesn’t change
length
= 𝑑Ω
𝑑𝑡
𝑂𝑃
definition 𝜔
= 𝑑(Ω 𝑂𝑃 )
𝑑𝑡
𝑂𝑃 is constant
42. Linear Velocity from Angular Velocity - Proof
𝝎𝑶𝑷⊥ has the correct direction, because a point
rotating around another fixed point can only move
perpendicularly to the vector between the points,
or the movement wouldn’t be a simple rotation.
𝝎𝑶𝑷⊥ has the correct sign, because we’re
measuring Ω in the counterclockwise direction. ω
is positive when the point is rotating
counterclockwise. The perpendicular operator
points in the counterclockwise direction relative to
the radius vector.
42 / 83
43. Linear Velocity from Angular Velocity
The linear velocity of any point P inside an object that is rotating about
its origin O, but not translating, is given by the following equation:
43 / 83
𝒗 𝑷 = 𝝎𝑶𝑷⊥
44. Linear Velocity from Angular Velocity
The linear velocity of any point P inside an object that is rotating about
its origin O, and is translating, is given by the following equation:
44 / 83
?
45. Chasles’ Theorem
• Chasles’ Theorem breaks up motion into linear and angular
components.
• We consider any movement of our rigid body as
▪ translating a single point in the body
▪ rotating the rest of the body around that point
45 / 83
46. Chasles’ Theorem
The linear velocity of any point P inside a moving object that is rotating
about its origin O is given by the following equation:
(without proof)
46 / 83
𝒗 𝑷 = 𝒗 𝑶 + 𝝎𝑶𝑷⊥
47. Kinematics – Angular Momentum
The Angular Momentum of a point P tells us how much of the linear
momentum pP of P is rotating around the origin.
47 / 83
𝑳 𝑶𝑷 = 𝑶𝑷⊥ × 𝒑 𝑷
48. Kinematics – Angular Momentum
The Angular Momentum of a point P tells us how much of the linear
momentum pP of P is rotating around the origin.
Note how angular momentum of a point P needs a reference (here: O),
in contrast to linear momentum.
48 / 83
𝑳 𝑶𝑷 = 𝑶𝑷⊥ × 𝒑 𝑷
49. Dynamics – Torque
Torque is the rate of change of angular momentum over time.
49 / 83
𝝉 𝑶𝑷 =
𝒅 𝑳 𝑶𝑷
𝒅𝒕
50. Dynamics – Torque
We can use the torque to determine how much of the force applied at
point P is causing the object to rotate:
50 / 83
𝜏 𝑂𝑃 = dLOP
dt
definition torque
= d(OP⊥× pP)
dt
definition
angular momentum
=
OP⊥ ×
dpp
dt
+
dOP⊥
dt
× pp
product rule
= (OP⊥ × 𝐹𝑃) + (vP × 𝑝P) def. linear force,
def. linear velocity
= OP⊥ × 𝐹𝑃
velocity and momentum of
P are parallel
51. Calculating Angular Momentum
Again, just like change in velocity can be numerically integrated using
acceleration, change in angular momentum can be integrated using
torque, from an applied force and position of application:
𝐿 𝑂𝑃 𝑡 = න 𝜏 𝑂𝑃 𝑑𝑡 = න OP⊥ × 𝐹𝑃 𝑑𝑡
51 / 83
52. Moment of Inertia
• The moment of inertia I of an object is a measure of how hard it is to
rotate the object about its center of mass.
• It is the sum of the squared distances from the center of mass to
each other point in the body, scaling each squared distance by the
mass of the respective point.
𝐼 =
𝑖
𝑚𝑖Oi⊥
2
52 / 83
53. Moment of Inertia
The moment of inertia can be used to derive the total angular
momentum:
𝐿 =
𝑖
Oi⊥ × pi
definition
angular momentum
=
𝑖
Oi⊥ × (𝑚𝑖 𝑣𝑖)
Definition linear momentum
=
𝑖
Oi⊥ × (𝑚𝑖 𝜔𝑂𝑖⊥)
Linear velocity from angular
velocity
=
𝜔
𝑖
Oi⊥ × (𝑚𝑖 𝑂𝑖⊥)
Angular velocity same for all
points i
=
𝜔
𝑖
𝑚𝑖Oi⊥
2
= 𝜔𝐼 definition moment of intertia
54. Hint
As the moment of inertia is
based on the mass and relative
position of all points of a rigid
body, only, it is constant and has
to be computed only once!
54 / 83
55. Dynamics – Torque
Integration shows how torque and angular acceleration are related:
𝜏 = 𝑑𝐿
𝑑𝑡
definition torque
= 𝑑𝜔𝐼
𝑑𝑡
as we’ve just proven
=
𝐼
𝑑𝜔
𝑑𝑡
moment of inertia constant
= 𝐼𝛼 Definition
angular acceleration
55 / 83
56. Dynamics – Torque
Thus, knowing the torque on our body, we can compute angular
acceleration, and then find angular velocity and orientation by numeric
integration.
𝝉 = 𝑰𝜶
56 / 83
57. Full Physics Simulation – Setup
For each rigid body:
1. Calculate center of mass and moment of inertia at the center of
mass.
2. Set initial position, orientation, linear velocity and angular velocity.
57 / 83
58. Full Physics Simulation – Loop
For each rigid body:
1. Collect all forces on the body, including their points of application.
2. Sum all forces and compute linear acceleration.
3. Compute the torque caused by each force.
4. Sum all torque and compute angular acceleration.
5. Numerically integrate linear acceleration and angular acceleration to
update linear velocity and angular velocity, and position and
orientation.
58 / 83
59. Hint
Usually, games will treat both
mass and moment of inertia as
properties of the rigid body.
59 / 83
60. Collision Response
• Given we know that there is a collision, the task is to find out how to
handle that collision.
• We need to decide where the colliding objects move, and if and how
they start spinning.
• By now, velocities never changes instantly, but by means forces
applied over time, only.
60 / 83
61. Impulse
• An impulse changes the momentum (and thus, the velocity) of a
rigid body instantly, without the need of integration over time.
• We’re going to use Newton’s Law of Restitution for Instantaneous
Collisions with No Friction to find the impulses to apply in case of a
collision.
61 / 83
62. Newton’s Law of Restitution for Instantaneous Collisions with No
Friction
• Instantaneous: in no time
• Restitution: coefficient of restitution models the compression and
restitution of impacting bodies with a single scalar
• No friction: impulse is entirely pointed in the direction of the collision
normal
62 / 83
63. Collision Data
• Collision point P
• Center of mass of both bodies A, B
• Velocity of the collision point of both bodies 𝑣 𝐴, 𝑣 𝐵
• Collision normal n
63 / 83
65. Coefficient of Restitution
• The Coefficient of Restitution 𝜖 tells us how much of the incoming
energy is dissipated during the collision.
• 𝜖 = 1 yields a totally elastic collision (super ball)
• 𝜖 = 0 yields a totally plastic collision (all energy absorbed)
𝑣 𝐴𝐵
′
𝑛 = −𝜖𝑣 𝐴𝐵 𝑛
65 / 83
66. Collision Impulse
By understanding the collision impulse j as change of momentum, we
expect the resulting velocities 𝑣 𝐴
′
and 𝑣 𝐵
′
to yield the following:
𝑣 𝐴
′
= 𝑣 𝐴 +
𝑗
𝑀𝐴
𝑛
𝑣 𝐵
′
= 𝑣 𝐵 −
𝑗
𝑀 𝐵
𝑛
66 / 83
69. Finding the Collision Impulse
Now that we’ve got everything in place, we can finally compute the
collision impulse.
69 / 83
𝑗 = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛
= −𝑣 𝐴𝐵 𝑛(1 + ϵ)
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛
distribution
= −𝑣 𝐴𝐵 𝑛(1 + ϵ)
𝑛𝑛(
1
𝑀𝐴
+
1
𝑀 𝐵
)
distribution
70. Finding the Collision Impulse
Now that we’ve got everything in place, we can finally compute the
collision impulse.
70 / 83
𝑗 = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛
= −𝑣 𝐴𝐵 𝑛(1 + ϵ)
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛
distribution
= −𝑣 𝐴𝐵 𝑛(1 + ϵ)
𝑛𝑛(
1
𝑀𝐴
+
1
𝑀 𝐵
)
distribution
Plugging in j back into our collision impulse equation yields the new velocities of A
and B!
71. Collision Impulse II
Finally, we need to understand how to have the collision impulse j
change the angular momentum:
𝜔 𝐴
′
= 𝜔 𝐴 +
𝐴𝑃⊥ 𝑗𝑛
𝐼𝐴
𝜔 𝐵
′
= 𝜔 𝐵 −
𝐵𝑃⊥ 𝑗𝑛
𝐼 𝐵
71 / 83
74. Collision Detection
• Now that we know how to handle collisions, all that’s left is to
understand how to detect them
• As detecting intersections between arbitrary polygons is quite
expensive, they are usually wrapped by some kind of collision shape
• With these shapes, typical test like shape-shape intersection and
ray-shape intersection become far cheaper
• The quality of the collision detection depends on how good the
shapes fit the actual body
74 / 83
78. Axis-Aligned Bounding Boxes
Detecting whether two axis-aligned bounding boxes 𝐴 𝑚𝑖𝑛, 𝐴 𝑚𝑎𝑥 and
(𝐵 𝑚𝑖𝑛, 𝐵 𝑚𝑎𝑥) intersect can be easily checked using the separating axis
theorem:
78 / 83
79. Axis-Aligned Bounding Boxes
Detecting whether two axis-aligned bounding boxes 𝐴 𝑚𝑖𝑛, 𝐴 𝑚𝑎𝑥 and
(𝐵 𝑚𝑖𝑛, 𝐵 𝑚𝑎𝑥) intersect can be easily checked using the separating axis
theorem:
𝐴 𝑚𝑖𝑛 𝑥 > 𝐵 𝑚𝑎𝑥 𝑥 or 𝐵 𝑚𝑖𝑛 𝑥 > 𝐴 𝑚𝑎𝑥 𝑥 or
𝐴 𝑚𝑖𝑛 𝑦 > 𝐵 𝑚𝑎𝑥 𝑦 or 𝐵 𝑚𝑖𝑛 𝑦 > 𝐴 𝑚𝑎𝑥 𝑦 or
𝐴 𝑚𝑖𝑛 𝑧
> 𝐵 𝑚𝑎𝑥 𝑧
or 𝐵 𝑚𝑖𝑛 𝑧
> 𝐴 𝑚𝑎𝑥 𝑧
79 / 83
80. Tunneling
• If your objects move too fast, you run in danger of missing collisions
due to your numerical integration step size.
• Imagine a sphere moving fast towards a thin wall.
80 / 83
81. Tunneling – Possible Solutions
• Make the wall thicker.
▪ Need to instruct all level designers.
• Impose an upper bound on object speed.
• Find the speculative contact through the bounding box of the
previous position of the moving object and the current one, and sub-
step from the contact point
▪ Arbitrary convex polygons are a challenge (see Continuous
Collision by Erin Catto in References)
81 / 83
82. Octrees
• Checking every pair of objects can be very expensive
• The number of required checks can be reduced by subdividing the
space into smaller parts, and checking only pairs of objects who are
found within the same part
82 / 83
Image by Bill Jacobs
83. Octree Construction
• Start with an empty root node covering the entire world
• Whenever you add an object to the world, start at the root node and
traverse the tree, finding the node farthest from the root that fully
contains the object
• If the node has reached its maximum capacity now, subdivide it into
children
83 / 83
84. Collision Detection using Octrees
• Given an octree containing shapes, we only need to check all pairs
of shapes that are found within the same node
• Shaped in non-leaf nodes need to be checked against all shapes of
all child nodes, and their children
84 / 83
85. Optimizing Octrees
• If the average object size begins to exceed the node size, objects
will start to be put in parent nodes more often.
• Limiting the depth of the octree helps avoiding this issue.
• For the same reason, it might be necessary to merge nodes again if
objects have moved away.
85 / 83
86. Future Work
• 3D (Matrices & Quaternions)
• Joints
• Non-rigid bodies
• Detecting Arbitrary Collisions
86 / 83
87. References
• Fiedler. Game Physics – Integration Basics. http://gafferongames.com/game-physics/integration-
basics/, 2006.
• Fielder. Game Physics – Fix Your Timestep! http://gafferongames.com/game-physics/fix-your-
timestep/, 2006.
• Hecker. Physics, The Next Frontier. Game Developer Magazine, October/November 1996.
• Hecker. Physics, Part 2: Angular Effects. Game Developer Magazine, December 1996/January
1997.
• Hecker. Physics, Part 3: Collision Response. Game Developer Magazine, March 1997.
• Catto. Box2D User Manual. http://box2d.org/manual.pdf, 2007.
• Catto. Physics for Game Programmers – Continuous Collision.
http://www.gdcvault.com/play/1018239/Physics-for-Game-Programmers-Continuous, 2013.
• Baraff. Physically Based Modelling – Rigid Body Simulation.
http://www.pixar.com/companyinfo/research/pbm2001/pdf/notesg.pdf, 2001.
• Jacobs. OpenGL Tutorial – Collision Detection.
http://www.videotutorialsrock.com/opengl_tutorial/collision_detection/text.php, 2014.
• Su. Ray-Sphere Intersection. http://www.cs.tufts.edu/~sarasu/courses/comp175-
2009fa/pdf/comp175-15-ray-sphere.pdf, November 11, 2009.
87 / 83
89. 10 Minute Review Session
• What’s the difference between kinematics and dynamics?
• What is velocity?
• What is acceleration?
• What is momentum?
• What is force?
• In your own words: How does Explicit Euler Integration work?
• Why are fixed time steps important in physics simulation?
• What is a rigid body?
90. 10 Minute Review Session
• What is the center of mass?
• In your own words: Explain Chasles’ Theorem!
• What is torque?
• What is moment of inertia?
• What is an impulse?
• Which data is required for resolving collisions?
• Which collision shapes do you know?
• How can you prevent tunneling?
• How can you reduce the number of collisions to check for?