SlideShare a Scribd company logo
1 of 90
Download to read offline
Game Programming
Physics
Nick Prühs
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
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
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
Kinematics – Velocity
Velocity is the rate of change of position over time.
5 / 83
𝒗 =
𝒅𝒙
𝒅𝒕
Kinematics – Acceleration
Acceleration is the rate of change of velocity over time.
6 / 83
𝒂 =
𝒅𝒗
𝒅𝒕
Change of velocity
Solving for v and integrating yields the velocity after a given time t,
aside from some unknown constant C:
7 / 83
𝐚 =
𝐝𝐯
𝐝𝐭
𝒅𝒗 = 𝒂 𝒅𝒕
𝒗(𝒕) = න 𝒂 𝒅𝒕
𝒗(𝒕) = 𝒂𝒕 + 𝑪
Change of velocity
We can find the unknown constant to be the initial velocity by
computing the initial velocity:
8 / 83
𝒗 = 𝒂𝒕 + 𝑪
𝒗 𝟎 = 𝟎𝒂 + 𝑪
𝒗 𝟎 = 𝑪
Change of velocity
Thus, given the acceleration a and initial velocity v0, the velocity after
any given time t is
9 / 83
𝒗(𝒕) = 𝒂𝒕 + 𝒗 𝟎
Change of position
The position after any given time t can be found the same way:
10 / 83
𝐯 =
𝐝𝐱
𝐝𝐭
𝒅𝒙 = 𝒗 𝒅𝒕
𝒅𝒙 = 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕
𝒙(𝒕) = න 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕
𝒙(𝒕) =
𝟏
𝟐
𝒂𝒕 𝟐
+ 𝒗 𝟎 𝒕 + 𝒙 𝟎
Kinematics – Momentum
Momentum is the product of the mass and velocity of an object.
11 / 83
𝒑 = 𝒎𝒗
Dynamics – Force
Force is the rate of change of momentum over time (Newton’s Second
Law).
12 / 83
𝑭 =
𝒅𝒑
𝒅𝒕
Change of acceleration
For constant mass, force and acceleration are related as follows:
13 / 83
𝐹 = 𝐝𝐩
𝐝𝐭
definition force
= 𝒅 𝒎𝒗
𝒅𝒕
definition
momentum
=
𝒎
𝒅𝒗
𝒅𝒕
constant mass
= 𝒎𝒂 definition
acceleration
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
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;
}
Explicit Euler Integration
t position velocity
1 0 10
2 10 20
3 30 30
4 60 40
5 100 50
6 150 60
7 210 70
8 280 80
9 360 90
10 450 100
16 / 83
Explicit Euler integration with dt = 1
Inaccuracy
𝒙 = 𝟎. 𝟓𝒂𝒕 𝟐
+ 𝒗𝒕 + 𝒙 𝟎 with 𝒂 = 𝟏𝟎, 𝒕 = 𝟏𝟎, 𝒗 = 𝟎, 𝒙 𝟎 =
𝟎
= 0.5 × 10 × 102
+ 0𝑡
+ 0
= 0.5 × 10 × 100
= 500
17 / 83
Exact physical position at t = 10 is:
This implies an error of (500 – 450) / 500 = 10% after only ten seconds for dt = 1!
Explicit Euler Integration
t position velocity
1 4.5 10
2 19 20
3 43.5 30
4 78 40
5 122.5 50
6 177 60
7 241.5 70
8 316 80
9 400.5 90
10 495 100
18 / 83
Explicit Euler integration with dt = 0.1
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...
}
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
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
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;
}
}
Fixed time steps in physics
t dt accumulatedTime position velocity
0 0.022 0.022 0 0
0 0.022 0.005 0.003 0.167
1 0.020 0.026 0.003 0.167
1 0.020 0.009 0.008 0.333
2 0.005 0.014 0.008 0.333
3 0.003 0.017 0.008 0.333
3 0.003 0 0.017 0.500
4 0.011 0.011 0.017 0.500
5 0.019 0.030 0.017 0.500
5 0.019 0.013 0.028 0.667
23 / 83
Fixed time steps with dt = 1 / 60 = 0.016
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
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
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
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
Center of mass
Let’s modify this equation a bit:
28 / 12
𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 = σ𝑖 𝑥𝑖 𝑚𝑖
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 =
෍
𝑖
𝑥𝑖 𝑚𝑖
multiplied with
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
=
෍
𝑖
𝑑(𝑥𝑖 𝑚𝑖)
𝑑𝑡
𝑑/𝑑𝑡
=
෍
𝑖
𝑚𝑖
𝑑𝑥𝑖
𝑑𝑡
constant mass
=
෍
𝑖
𝑚𝑖 𝑣𝑖
definition velocity
= 𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 definition
momentum
Center of mass
Now, let’s take a look at the second part again:
29 / 83
𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
=
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑥 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠
𝑑𝑡
constant
mass
= 𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 definitio
n
velocity
Center of mass
Combining both results yields a stunning property
of the center of mass!
𝒑 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 = 𝑴 𝑹𝒊𝒈𝒊𝒅𝒃𝒐𝒅𝒚 𝒗 𝑪𝒆𝒏𝒕𝒆𝒓𝑶𝒇𝑴𝒂𝒔𝒔
30 / 83
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
Center of mass
This further applies to forces, as well:
32 / 83
𝐹𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 = 𝑑𝑝 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑡
= 𝑑(𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠)
𝑑𝑡
as we’ve just proven
=
𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦
𝑑𝑣 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠
𝑑𝑡
constant mass
= 𝑀 𝑅𝑖𝑔𝑖𝑑𝑏𝑜𝑑𝑦 𝑎 𝐶𝑒𝑛𝑡𝑒𝑟𝑂𝑓𝑀𝑎𝑠𝑠 definition
acceleration
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
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
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
Kinematics – Angular Velocity
Angular Velocity is the rate of change of orientation over time.
36 / 83
𝝎 =
𝒅Ω
𝒅𝒕
Kinematics – Angular Acceleration
Angular Acceleration is the rate of change of angular velocity over time.
37 / 83
𝜶 =
𝒅 𝜔
𝒅𝒕
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
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
𝒗 𝑷 = 𝝎𝑶𝑷⊥
Hint
In 2D, the perpendicular of a
vector (x, y) is (-y, x).
40 / 83
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
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
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
𝒗 𝑷 = 𝝎𝑶𝑷⊥
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
?
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
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
𝒗 𝑷 = 𝒗 𝑶 + 𝝎𝑶𝑷⊥
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
𝑳 𝑶𝑷 = 𝑶𝑷⊥ × 𝒑 𝑷
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
𝑳 𝑶𝑷 = 𝑶𝑷⊥ × 𝒑 𝑷
Dynamics – Torque
Torque is the rate of change of angular momentum over time.
49 / 83
𝝉 𝑶𝑷 =
𝒅 𝑳 𝑶𝑷
𝒅𝒕
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
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
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
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
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
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
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
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
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
Hint
Usually, games will treat both
mass and moment of inertia as
properties of the rigid body.
59 / 83
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
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
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
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
Derived Collision Data
Relative velocity
𝑣 𝐴𝐵 = 𝑣 𝐴 − 𝑣 𝐵
Relative normal velocity
𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴 − 𝑣 𝐵 𝑛
64 / 83
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
Collision Impulse
By understanding the collision impulse j as change of momentum, we
expect the resulting velocities 𝑣 𝐴
′
and 𝑣 𝐵
′
to yield the following:
𝑣 𝐴
′
= 𝑣 𝐴 +
𝑗
𝑀𝐴
𝑛
𝑣 𝐵
′
= 𝑣 𝐵 −
𝑗
𝑀 𝐵
𝑛
66 / 83
Finding the Collision Impulse
Now that we’ve got everything in place, we can finally compute the
collision impulse.
67 / 83
−𝜖𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴𝐵
′
𝑛 definition
coefficient of restitution
= (𝑣 𝐴
′
− 𝑣 𝐵
′
)𝑛 definition
relative velocity
=
(𝑣 𝐴 +
𝑗
𝑀𝐴
𝑛 − 𝑣 𝐵 +
𝑗
𝑀 𝐵
𝑛)𝑛
definition
collision impulse
=
𝑣 𝐴 𝑛 +
𝑗
𝑀𝐴
𝑛𝑛 − 𝑣 𝐵 𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛
distribution
=
𝑣 𝐴 𝑛 − 𝑣 𝐵 𝑛 +
𝑗
𝑀𝐴
𝑛𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛
commutative property
=
𝑣 𝐴𝐵 𝑛 +
𝑗
𝑀𝐴
𝑛𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛
definition
relative velocity
Finding the Collision Impulse
Now that we’ve got everything in place, we can finally compute the
collision impulse.
68 / 83
𝑣 𝐴𝐵 𝑛 +
𝑗
𝑀𝐴
𝑛𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛
= −𝜖𝑣 𝐴𝐵 𝑛
𝑗
𝑀𝐴
𝑛𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛
= −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛
𝑗(
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛) = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛 distribution
𝑗 = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛
1
𝑀𝐴
𝑛𝑛 +
1
𝑀 𝐵
𝑛𝑛
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
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!
Collision Impulse II
Finally, we need to understand how to have the collision impulse j
change the angular momentum:
𝜔 𝐴
′
= 𝜔 𝐴 +
𝐴𝑃⊥ 𝑗𝑛
𝐼𝐴
𝜔 𝐵
′
= 𝜔 𝐵 −
𝐵𝑃⊥ 𝑗𝑛
𝐼 𝐵
71 / 83
Finding the Collision Impulse
Let’s close by computing the collision impulse with spin:
72 / 12
−𝜖𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴𝐵
′
𝑛 definition
coefficient of restitution
= (𝑣 𝐴𝑃
′
− 𝑣 𝐵𝑃
′
)𝑛 definition
relative velocity
= (𝑣 𝐴
′
+ 𝜔 𝐴
′
𝐴𝑃⊥ − (𝑣 𝐵
′
+ 𝜔 𝐵
′
𝐵𝑃⊥))𝑛 Chasles’ Theorem
= (𝑣 𝐴
′
+ 𝜔 𝐴
′
𝐴𝑃⊥ − 𝑣 𝐵
′
− 𝜔 𝐵
′
𝐵𝑃⊥)𝑛
=
(𝑣 𝐴 +
𝑗
𝑀𝐴
𝑛 + (𝜔 𝐴 +
𝐴𝑃⊥ 𝑗𝑛
𝐼𝐴
)𝐴𝑃⊥ − (𝑣 𝐵 −
𝑗
𝑀 𝐵
𝑛) − (𝜔 𝐵 −
𝐵𝑃⊥ 𝑗𝑛
𝐼 𝐵
)𝐵𝑃⊥)𝑛
definition
collision impulse
=
(𝑣 𝐴 +
𝑗
𝑀𝐴
𝑛 + 𝜔 𝐴 𝐴𝑃⊥ +
𝐴𝑃⊥
2
𝑗𝑛
𝐼𝐴
− 𝑣 𝐵 +
𝑗
𝑀 𝐵
𝑛 − 𝜔 𝐵 𝐵𝑃⊥ +
𝐵𝑃⊥
2
𝑗𝑛
𝐼 𝐵
)𝑛
=
𝑣 𝐴 𝑛 +
𝑗
𝑀𝐴
𝑛𝑛 + 𝜔 𝐴 𝐴𝑃⊥ 𝑛 +
𝐴𝑃⊥
2
𝑗𝑛𝑛
𝐼𝐴
− 𝑣 𝐵 𝑛 +
𝑗
𝑀 𝐵
𝑛𝑛 − 𝜔 𝐵 𝐵𝑃⊥ 𝑛
+
𝐵𝑃⊥
2
𝑗𝑛𝑛
𝐼 𝐵
distribution
Finding the Collision Impulse
Let’s close by computing the collision impulse with spin:
73 / 12
𝑗
𝑀𝐴
𝑛𝑛 +
𝐴𝑃⊥
2
𝑗𝑛𝑛
𝐼𝐴
+
𝑗
𝑀 𝐵
𝑛𝑛 +
𝐵𝑃⊥
2
𝑗𝑛𝑛
𝐼 𝐵
= −𝑣 𝐴 𝑛 − 𝜔 𝐴 𝐴𝑃⊥ 𝑛 + 𝑣 𝐵 𝑛 + 𝜔 𝐵 𝐵𝑃⊥ 𝑛
− 𝜖𝑣 𝐴𝐵 𝑛
j to left side,
non-j to right
side
𝑗𝑛𝑛(
1
𝑀𝐴
+
𝐴𝑃⊥
2
𝐼𝐴
+
1
𝑀 𝐵
+
𝐵𝑃⊥
2
𝐼 𝐵
)
= −𝑛(𝑣 𝐴 + 𝜔 𝐴 𝐴𝑃⊥ − 𝑣 𝐵 − 𝜔 𝐵 𝐵𝑃⊥ + 𝜖𝑣 𝐴𝐵) distribution
𝑗𝑛𝑛(
1
𝑀𝐴
+
𝐴𝑃⊥
2
𝐼𝐴
+
1
𝑀 𝐵
+
𝐵𝑃⊥
2
𝐼 𝐵
)
= −𝑛(𝑣 𝐴𝑃 − 𝑣 𝐵𝑃 + 𝜖𝑣 𝐴𝐵) Chasles’
Theorem
𝑗𝑛𝑛(
1
𝑀𝐴
+
𝐴𝑃⊥
2
𝐼𝐴
+
1
𝑀 𝐵
+
𝐵𝑃⊥
2
𝐼 𝐵
)
= −𝑛(𝑣 𝐴𝐵 + 𝜖𝑣 𝐴𝐵) definition
relative velocity
𝑗𝑛𝑛(
1
𝑀𝐴
+
𝐴𝑃⊥
2
𝐼𝐴
+
1
𝑀 𝐵
+
𝐵𝑃⊥
2
𝐼 𝐵
)
= −𝑛𝑣 𝐴𝐵(1 + 𝜖) distribution
𝑗 = −𝑛𝑣 𝐴𝐵(1 + 𝜖)
𝑛𝑛(
1
𝑀𝐴
+
𝐴𝑃⊥
2
𝐼𝐴
+
1
𝑀 𝐵
+
𝐵𝑃⊥
2
𝐼 𝐵
)
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
Collision Spheres
Detecting whether two spheres A and B intersect is as easy as
comparing their distance to the sum of their radii.
75 / 83
Collision Spheres
The potential collision point lies on the ray from sphere A to B at the
exact radius of A.
76 / 83
Collision Spheres
Detecting whether a ray intersects a sphere requires some tedious, but
basic math (see References)
77 / 83
Axis-Aligned Bounding Boxes
Detecting whether two axis-aligned bounding boxes 𝐴 𝑚𝑖𝑛, 𝐴 𝑚𝑎𝑥 and
(𝐵 𝑚𝑖𝑛, 𝐵 𝑚𝑎𝑥) intersect can be easily checked using the separating axis
theorem:
78 / 83
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
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
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
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
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
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
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
Future Work
• 3D (Matrices & Quaternions)
• Joints
• Non-rigid bodies
• Detecting Arbitrary Collisions
86 / 83
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
Thank you!
http://www.npruehs.de
https://github.com/npruehs
@npruehs
nick.pruehs@daedalic.com
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?
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?

More Related Content

What's hot

Aft713 fundamental of game design 1.2
Aft713 fundamental of game design 1.2Aft713 fundamental of game design 1.2
Aft713 fundamental of game design 1.2krishn verma
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game EngineSeth Sivak
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game DevelopmentSumit Jain
 
Game development pipeline
Game development pipelineGame development pipeline
Game development pipelineGAME Studios
 
Game Design Principle
Game Design PrincipleGame Design Principle
Game Design PrincipleNaquiah Daud
 
Game Economy Balancing Workshop
Game Economy Balancing WorkshopGame Economy Balancing Workshop
Game Economy Balancing WorkshopMariana Boucault
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Unity Technologies
 
2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)Hafiz Ammar Siddiqui
 
LAFS Game Mechanics - Narrative Elements
LAFS Game Mechanics - Narrative ElementsLAFS Game Mechanics - Narrative Elements
LAFS Game Mechanics - Narrative ElementsDavid Mullich
 
LAFS PREPRO Session 2 - Game Documentation
LAFS PREPRO Session 2 - Game DocumentationLAFS PREPRO Session 2 - Game Documentation
LAFS PREPRO Session 2 - Game DocumentationDavid Mullich
 
INTRODUCTION OF GAME DESIGN AND DEVELOPMENT
INTRODUCTION OF GAME DESIGN AND DEVELOPMENTINTRODUCTION OF GAME DESIGN AND DEVELOPMENT
INTRODUCTION OF GAME DESIGN AND DEVELOPMENTLaili Farhana M.I.
 
LAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicLAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicDavid Mullich
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game DesignGraeme Smith
 
Unity 3D game engine seminar
Unity 3D game engine  seminarUnity 3D game engine  seminar
Unity 3D game engine seminarNikhilThorat15
 
Unity Introduction
Unity IntroductionUnity Introduction
Unity IntroductionJuwal Bose
 
Game Design 2: Lecture 5 - Game UI Wireframes and Paper Prototypes
Game Design 2: Lecture 5 - Game UI Wireframes and Paper PrototypesGame Design 2: Lecture 5 - Game UI Wireframes and Paper Prototypes
Game Design 2: Lecture 5 - Game UI Wireframes and Paper PrototypesDavid Farrell
 
LOD and Culling Systems That Scale - Unite LA
LOD and Culling Systems That Scale  - Unite LALOD and Culling Systems That Scale  - Unite LA
LOD and Culling Systems That Scale - Unite LAUnity Technologies
 

What's hot (20)

Aft713 fundamental of game design 1.2
Aft713 fundamental of game design 1.2Aft713 fundamental of game design 1.2
Aft713 fundamental of game design 1.2
 
What Is A Game Engine
What Is A Game EngineWhat Is A Game Engine
What Is A Game Engine
 
Introduction to Game Development
Introduction to Game DevelopmentIntroduction to Game Development
Introduction to Game Development
 
Game development pipeline
Game development pipelineGame development pipeline
Game development pipeline
 
Game Design Principle
Game Design PrincipleGame Design Principle
Game Design Principle
 
Game Economy Balancing Workshop
Game Economy Balancing WorkshopGame Economy Balancing Workshop
Game Economy Balancing Workshop
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019
 
2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)
 
LAFS Game Mechanics - Narrative Elements
LAFS Game Mechanics - Narrative ElementsLAFS Game Mechanics - Narrative Elements
LAFS Game Mechanics - Narrative Elements
 
LAFS PREPRO Session 2 - Game Documentation
LAFS PREPRO Session 2 - Game DocumentationLAFS PREPRO Session 2 - Game Documentation
LAFS PREPRO Session 2 - Game Documentation
 
Game Design Process
Game Design ProcessGame Design Process
Game Design Process
 
INTRODUCTION OF GAME DESIGN AND DEVELOPMENT
INTRODUCTION OF GAME DESIGN AND DEVELOPMENTINTRODUCTION OF GAME DESIGN AND DEVELOPMENT
INTRODUCTION OF GAME DESIGN AND DEVELOPMENT
 
LAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core MechanicLAFS Game Mechanics - The Core Mechanic
LAFS Game Mechanics - The Core Mechanic
 
Introduction to Game Design
Introduction to Game DesignIntroduction to Game Design
Introduction to Game Design
 
Game Mechanics
Game MechanicsGame Mechanics
Game Mechanics
 
Intro to Game Design
Intro to Game DesignIntro to Game Design
Intro to Game Design
 
Unity 3D game engine seminar
Unity 3D game engine  seminarUnity 3D game engine  seminar
Unity 3D game engine seminar
 
Unity Introduction
Unity IntroductionUnity Introduction
Unity Introduction
 
Game Design 2: Lecture 5 - Game UI Wireframes and Paper Prototypes
Game Design 2: Lecture 5 - Game UI Wireframes and Paper PrototypesGame Design 2: Lecture 5 - Game UI Wireframes and Paper Prototypes
Game Design 2: Lecture 5 - Game UI Wireframes and Paper Prototypes
 
LOD and Culling Systems That Scale - Unite LA
LOD and Culling Systems That Scale  - Unite LALOD and Culling Systems That Scale  - Unite LA
LOD and Culling Systems That Scale - Unite LA
 

Viewers also liked

Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AINick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentNick Pruehs
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationNick Pruehs
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - LocalizationNick Pruehs
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesNick Pruehs
 
What Would Blizzard Do
What Would Blizzard DoWhat Would Blizzard Do
What Would Blizzard DoNick Pruehs
 
Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git FlowNick Pruehs
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - GitNick Pruehs
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsNick Pruehs
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with PonyNick Pruehs
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - ShadersNick Pruehs
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - IntroductionNick Pruehs
 
Game Development Challenges
Game Development ChallengesGame Development Challenges
Game Development ChallengesNick Pruehs
 
Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameNick Pruehs
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsNick Pruehs
 
Physics for Game Programmers
Physics for Game ProgrammersPhysics for Game Programmers
Physics for Game ProgrammersUng-Su Lee
 
Game Programming 05 - Development Tools
Game Programming 05 - Development ToolsGame Programming 05 - Development Tools
Game Programming 05 - Development ToolsNick Pruehs
 
Game Programming 06 - Automated Testing
Game Programming 06 - Automated TestingGame Programming 06 - Automated Testing
Game Programming 06 - Automated TestingNick Pruehs
 

Viewers also liked (20)

Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance Optimization
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - Localization
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
 
What Would Blizzard Do
What Would Blizzard DoWhat Would Blizzard Do
What Would Blizzard Do
 
Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git Flow
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - Git
 
Game Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity SystemsGame Programming 02 - Component-Based Entity Systems
Game Programming 02 - Component-Based Entity Systems
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with Pony
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
 
Game Development Challenges
Game Development ChallengesGame Development Challenges
Game Development Challenges
 
Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great Game
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small Teams
 
Physics for Game Programmers
Physics for Game ProgrammersPhysics for Game Programmers
Physics for Game Programmers
 
Game Programming 05 - Development Tools
Game Programming 05 - Development ToolsGame Programming 05 - Development Tools
Game Programming 05 - Development Tools
 
Game Programming 06 - Automated Testing
Game Programming 06 - Automated TestingGame Programming 06 - Automated Testing
Game Programming 06 - Automated Testing
 
Final econo dx(1)
Final econo dx(1)Final econo dx(1)
Final econo dx(1)
 

Similar to Game Programming 11 - Game Physics

Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuo
Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuoCajamarca isaac diseño y construccion de la maqueta de movimiento perpetuo
Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuoJASSONISAACCAJAMARCA
 
Dinamica rotacional
Dinamica rotacionalDinamica rotacional
Dinamica rotacionalKramerCaiza
 
3c. uniform circular motion
3c. uniform circular motion3c. uniform circular motion
3c. uniform circular motiondukies_2000
 
2.2 Acceleration
2.2 Acceleration2.2 Acceleration
2.2 Accelerationmlong24
 
2.2 Phy I - Acceleration
2.2 Phy I - Acceleration2.2 Phy I - Acceleration
2.2 Phy I - Accelerationmlong24
 
1.Day 1 Rectilinera Motion Part 01.pdf
1.Day 1 Rectilinera Motion Part 01.pdf1.Day 1 Rectilinera Motion Part 01.pdf
1.Day 1 Rectilinera Motion Part 01.pdfruwan dissanayake
 
PPT-Rectilinear Motion.pptx
PPT-Rectilinear Motion.pptxPPT-Rectilinear Motion.pptx
PPT-Rectilinear Motion.pptxKenneth Arlando
 
Chapter 12 kinematics of a particle part-i
Chapter 12 kinematics of a particle   part-iChapter 12 kinematics of a particle   part-i
Chapter 12 kinematics of a particle part-iSajid Yasin
 
Force of rotating system
Force of rotating systemForce of rotating system
Force of rotating systemdaveson700
 
Rotational Motion & Equilibrium
Rotational Motion & EquilibriumRotational Motion & Equilibrium
Rotational Motion & EquilibriumTimothy Welsh
 
Lab 05 – Gravitation and Keplers Laws Name __________________.docx
Lab 05 – Gravitation and Keplers Laws Name __________________.docxLab 05 – Gravitation and Keplers Laws Name __________________.docx
Lab 05 – Gravitation and Keplers Laws Name __________________.docxDIPESH30
 
Hatten spring 1561232600_stablesprings0.7.3
Hatten spring 1561232600_stablesprings0.7.3Hatten spring 1561232600_stablesprings0.7.3
Hatten spring 1561232600_stablesprings0.7.3widgetdog
 
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...physics 9702 theory pdf fr A level cambridge.This will assist in understandin...
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...PermissionTafadzwaCh
 
Velocity time graphs , Free fall.pdf
Velocity time graphs , Free fall.pdfVelocity time graphs , Free fall.pdf
Velocity time graphs , Free fall.pdfdaminorteystephen
 

Similar to Game Programming 11 - Game Physics (20)

Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuo
Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuoCajamarca isaac diseño y construccion de la maqueta de movimiento perpetuo
Cajamarca isaac diseño y construccion de la maqueta de movimiento perpetuo
 
Ch2 2011 s
Ch2 2011 sCh2 2011 s
Ch2 2011 s
 
Dinamica rotacional
Dinamica rotacionalDinamica rotacional
Dinamica rotacional
 
Moments
MomentsMoments
Moments
 
3c. uniform circular motion
3c. uniform circular motion3c. uniform circular motion
3c. uniform circular motion
 
2.1 linear motion
2.1   linear motion2.1   linear motion
2.1 linear motion
 
2.2 Acceleration
2.2 Acceleration2.2 Acceleration
2.2 Acceleration
 
2.2 Phy I - Acceleration
2.2 Phy I - Acceleration2.2 Phy I - Acceleration
2.2 Phy I - Acceleration
 
1.Day 1 Rectilinera Motion Part 01.pdf
1.Day 1 Rectilinera Motion Part 01.pdf1.Day 1 Rectilinera Motion Part 01.pdf
1.Day 1 Rectilinera Motion Part 01.pdf
 
PPT-Rectilinear Motion.pptx
PPT-Rectilinear Motion.pptxPPT-Rectilinear Motion.pptx
PPT-Rectilinear Motion.pptx
 
Chapter 12 kinematics of a particle part-i
Chapter 12 kinematics of a particle   part-iChapter 12 kinematics of a particle   part-i
Chapter 12 kinematics of a particle part-i
 
Force of rotating system
Force of rotating systemForce of rotating system
Force of rotating system
 
Simulation And Modelling
Simulation And ModellingSimulation And Modelling
Simulation And Modelling
 
Simple Harmonic Motion
Simple Harmonic MotionSimple Harmonic Motion
Simple Harmonic Motion
 
Rotational Motion & Equilibrium
Rotational Motion & EquilibriumRotational Motion & Equilibrium
Rotational Motion & Equilibrium
 
Lab 05 – Gravitation and Keplers Laws Name __________________.docx
Lab 05 – Gravitation and Keplers Laws Name __________________.docxLab 05 – Gravitation and Keplers Laws Name __________________.docx
Lab 05 – Gravitation and Keplers Laws Name __________________.docx
 
Hatten spring 1561232600_stablesprings0.7.3
Hatten spring 1561232600_stablesprings0.7.3Hatten spring 1561232600_stablesprings0.7.3
Hatten spring 1561232600_stablesprings0.7.3
 
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...physics 9702 theory pdf fr A level cambridge.This will assist in understandin...
physics 9702 theory pdf fr A level cambridge.This will assist in understandin...
 
Shm 1
Shm 1Shm 1
Shm 1
 
Velocity time graphs , Free fall.pdf
Velocity time graphs , Free fall.pdfVelocity time graphs , Free fall.pdf
Velocity time graphs , Free fall.pdf
 

More from Nick Pruehs

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsNick Pruehs
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceNick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesNick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayNick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorNick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkNick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud DevelopmentNick Pruehs
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - GitNick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - ExamsNick Pruehs
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsNick Pruehs
 

More from Nick Pruehs (10)

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
 
Tool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool ChainsTool Development 10 - MVVM, Tool Chains
Tool Development 10 - MVVM, Tool Chains
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Game Programming 11 - Game Physics

  • 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
  • 5. Kinematics – Velocity Velocity is the rate of change of position over time. 5 / 83 𝒗 = 𝒅𝒙 𝒅𝒕
  • 6. Kinematics – Acceleration Acceleration is the rate of change of velocity over time. 6 / 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 𝐯 = 𝐝𝐱 𝐝𝐭 𝒅𝒙 = 𝒗 𝒅𝒕 𝒅𝒙 = 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕 𝒙(𝒕) = න 𝒂𝒕 + 𝒗 𝟎 𝒅𝒕 𝒙(𝒕) = 𝟏 𝟐 𝒂𝒕 𝟐 + 𝒗 𝟎 𝒕 + 𝒙 𝟎
  • 11. Kinematics – Momentum Momentum is the product of the mass and velocity of an object. 11 / 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; }
  • 16. Explicit Euler Integration t position velocity 1 0 10 2 10 20 3 30 30 4 60 40 5 100 50 6 150 60 7 210 70 8 280 80 9 360 90 10 450 100 16 / 83 Explicit Euler integration with dt = 1
  • 17. Inaccuracy 𝒙 = 𝟎. 𝟓𝒂𝒕 𝟐 + 𝒗𝒕 + 𝒙 𝟎 with 𝒂 = 𝟏𝟎, 𝒕 = 𝟏𝟎, 𝒗 = 𝟎, 𝒙 𝟎 = 𝟎 = 0.5 × 10 × 102 + 0𝑡 + 0 = 0.5 × 10 × 100 = 500 17 / 83 Exact physical position at t = 10 is: This implies an error of (500 – 450) / 500 = 10% after only ten seconds for dt = 1!
  • 18. Explicit Euler Integration t position velocity 1 4.5 10 2 19 20 3 43.5 30 4 78 40 5 122.5 50 6 177 60 7 241.5 70 8 316 80 9 400.5 90 10 495 100 18 / 83 Explicit Euler integration with dt = 0.1
  • 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; } }
  • 23. Fixed time steps in physics t dt accumulatedTime position velocity 0 0.022 0.022 0 0 0 0.022 0.005 0.003 0.167 1 0.020 0.026 0.003 0.167 1 0.020 0.009 0.008 0.333 2 0.005 0.014 0.008 0.333 3 0.003 0.017 0.008 0.333 3 0.003 0 0.017 0.500 4 0.011 0.011 0.017 0.500 5 0.019 0.030 0.017 0.500 5 0.019 0.013 0.028 0.667 23 / 83 Fixed time steps with dt = 1 / 60 = 0.016
  • 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
  • 64. Derived Collision Data Relative velocity 𝑣 𝐴𝐵 = 𝑣 𝐴 − 𝑣 𝐵 Relative normal velocity 𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴 − 𝑣 𝐵 𝑛 64 / 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
  • 67. Finding the Collision Impulse Now that we’ve got everything in place, we can finally compute the collision impulse. 67 / 83 −𝜖𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴𝐵 ′ 𝑛 definition coefficient of restitution = (𝑣 𝐴 ′ − 𝑣 𝐵 ′ )𝑛 definition relative velocity = (𝑣 𝐴 + 𝑗 𝑀𝐴 𝑛 − 𝑣 𝐵 + 𝑗 𝑀 𝐵 𝑛)𝑛 definition collision impulse = 𝑣 𝐴 𝑛 + 𝑗 𝑀𝐴 𝑛𝑛 − 𝑣 𝐵 𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 distribution = 𝑣 𝐴 𝑛 − 𝑣 𝐵 𝑛 + 𝑗 𝑀𝐴 𝑛𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 commutative property = 𝑣 𝐴𝐵 𝑛 + 𝑗 𝑀𝐴 𝑛𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 definition relative velocity
  • 68. Finding the Collision Impulse Now that we’ve got everything in place, we can finally compute the collision impulse. 68 / 83 𝑣 𝐴𝐵 𝑛 + 𝑗 𝑀𝐴 𝑛𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 = −𝜖𝑣 𝐴𝐵 𝑛 𝑗 𝑀𝐴 𝑛𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛 𝑗( 1 𝑀𝐴 𝑛𝑛 + 1 𝑀 𝐵 𝑛𝑛) = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛 distribution 𝑗 = −𝜖𝑣 𝐴𝐵 𝑛 − 𝑣 𝐴𝐵 𝑛 1 𝑀𝐴 𝑛𝑛 + 1 𝑀 𝐵 𝑛𝑛
  • 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
  • 72. Finding the Collision Impulse Let’s close by computing the collision impulse with spin: 72 / 12 −𝜖𝑣 𝐴𝐵 𝑛 = 𝑣 𝐴𝐵 ′ 𝑛 definition coefficient of restitution = (𝑣 𝐴𝑃 ′ − 𝑣 𝐵𝑃 ′ )𝑛 definition relative velocity = (𝑣 𝐴 ′ + 𝜔 𝐴 ′ 𝐴𝑃⊥ − (𝑣 𝐵 ′ + 𝜔 𝐵 ′ 𝐵𝑃⊥))𝑛 Chasles’ Theorem = (𝑣 𝐴 ′ + 𝜔 𝐴 ′ 𝐴𝑃⊥ − 𝑣 𝐵 ′ − 𝜔 𝐵 ′ 𝐵𝑃⊥)𝑛 = (𝑣 𝐴 + 𝑗 𝑀𝐴 𝑛 + (𝜔 𝐴 + 𝐴𝑃⊥ 𝑗𝑛 𝐼𝐴 )𝐴𝑃⊥ − (𝑣 𝐵 − 𝑗 𝑀 𝐵 𝑛) − (𝜔 𝐵 − 𝐵𝑃⊥ 𝑗𝑛 𝐼 𝐵 )𝐵𝑃⊥)𝑛 definition collision impulse = (𝑣 𝐴 + 𝑗 𝑀𝐴 𝑛 + 𝜔 𝐴 𝐴𝑃⊥ + 𝐴𝑃⊥ 2 𝑗𝑛 𝐼𝐴 − 𝑣 𝐵 + 𝑗 𝑀 𝐵 𝑛 − 𝜔 𝐵 𝐵𝑃⊥ + 𝐵𝑃⊥ 2 𝑗𝑛 𝐼 𝐵 )𝑛 = 𝑣 𝐴 𝑛 + 𝑗 𝑀𝐴 𝑛𝑛 + 𝜔 𝐴 𝐴𝑃⊥ 𝑛 + 𝐴𝑃⊥ 2 𝑗𝑛𝑛 𝐼𝐴 − 𝑣 𝐵 𝑛 + 𝑗 𝑀 𝐵 𝑛𝑛 − 𝜔 𝐵 𝐵𝑃⊥ 𝑛 + 𝐵𝑃⊥ 2 𝑗𝑛𝑛 𝐼 𝐵 distribution
  • 73. Finding the Collision Impulse Let’s close by computing the collision impulse with spin: 73 / 12 𝑗 𝑀𝐴 𝑛𝑛 + 𝐴𝑃⊥ 2 𝑗𝑛𝑛 𝐼𝐴 + 𝑗 𝑀 𝐵 𝑛𝑛 + 𝐵𝑃⊥ 2 𝑗𝑛𝑛 𝐼 𝐵 = −𝑣 𝐴 𝑛 − 𝜔 𝐴 𝐴𝑃⊥ 𝑛 + 𝑣 𝐵 𝑛 + 𝜔 𝐵 𝐵𝑃⊥ 𝑛 − 𝜖𝑣 𝐴𝐵 𝑛 j to left side, non-j to right side 𝑗𝑛𝑛( 1 𝑀𝐴 + 𝐴𝑃⊥ 2 𝐼𝐴 + 1 𝑀 𝐵 + 𝐵𝑃⊥ 2 𝐼 𝐵 ) = −𝑛(𝑣 𝐴 + 𝜔 𝐴 𝐴𝑃⊥ − 𝑣 𝐵 − 𝜔 𝐵 𝐵𝑃⊥ + 𝜖𝑣 𝐴𝐵) distribution 𝑗𝑛𝑛( 1 𝑀𝐴 + 𝐴𝑃⊥ 2 𝐼𝐴 + 1 𝑀 𝐵 + 𝐵𝑃⊥ 2 𝐼 𝐵 ) = −𝑛(𝑣 𝐴𝑃 − 𝑣 𝐵𝑃 + 𝜖𝑣 𝐴𝐵) Chasles’ Theorem 𝑗𝑛𝑛( 1 𝑀𝐴 + 𝐴𝑃⊥ 2 𝐼𝐴 + 1 𝑀 𝐵 + 𝐵𝑃⊥ 2 𝐼 𝐵 ) = −𝑛(𝑣 𝐴𝐵 + 𝜖𝑣 𝐴𝐵) definition relative velocity 𝑗𝑛𝑛( 1 𝑀𝐴 + 𝐴𝑃⊥ 2 𝐼𝐴 + 1 𝑀 𝐵 + 𝐵𝑃⊥ 2 𝐼 𝐵 ) = −𝑛𝑣 𝐴𝐵(1 + 𝜖) distribution 𝑗 = −𝑛𝑣 𝐴𝐵(1 + 𝜖) 𝑛𝑛( 1 𝑀𝐴 + 𝐴𝑃⊥ 2 𝐼𝐴 + 1 𝑀 𝐵 + 𝐵𝑃⊥ 2 𝐼 𝐵 )
  • 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
  • 75. Collision Spheres Detecting whether two spheres A and B intersect is as easy as comparing their distance to the sum of their radii. 75 / 83
  • 76. Collision Spheres The potential collision point lies on the ray from sphere A to B at the exact radius of A. 76 / 83
  • 77. Collision Spheres Detecting whether a ray intersects a sphere requires some tedious, but basic math (see References) 77 / 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?