game physics - utrecht university 1-2 essential physics.pdf · game physics • static friction: a...
TRANSCRIPT
Game Physics
Game and Media Technology
Master Program - Utrecht University
Dr. Amir Vaxman
Game Physics
• Lecture
– Basic mechanics for developers
– Rigid/soft body motion
– Numerical integration
– Collision detection
– Engine programming
• Project!
– frontal presentations
• Seminar
– Presentation of research papers read
Course Contents
Introduction
Game Physics
• Analyzing and simulating object interaction
– Kinematics: description of motion
• Position, velocity and acceleration
– Physics: forces on objects
• mass, inertia, etc.
• Objects interact through forces:
– Between remote objects (gravity, magnetism)
– Between touching objects (friction)
– Within an object (chemical ties)
4
The primary issues
Game Physics
• Physics for simulation:
– rigid bodies
• mechanically considered as points
• possibly connected to other bodies
– soft bodies
• deform in a continuum
• interacting with other bodies
– breakable bodies
• single rigid bodies break them into
multiple ones
5
Applications
Game Physics
• We need some basic math knowledge
– Point
– Vector
• magnitude, normalization, addition, subtraction, scalar
multiplication, transpose, dot product, cross product ...
• implicit and parametric representations, orthonormal basis ...
– Matrix
• addition, subtraction, multiplication, transpose, dot product,
inverse, rank, determinant ...
• linear and affine transformation, homogeneous coordinate ...
– Derivative and integral
– SI units
6
Prerequisites
Game Physics
• How do I control the forces to achieve an effect?
• Moving objects collide:
– Collision detection: did a collision occur and where?
– Collision resolution: what do we do?
7
The primary issues
Game Physics
• Solid body mechanics: object represented as a
point in space:
– Object Centroid
• average of all points
– Center of mass
• average weighted by density (=centroid when uniform)
• Soft body mechanics: object is represented by a
structured set of points in space.
8
Modeling objects
Kinematics
Game Physics
• Suppose object position 𝑝𝑜 and constant velocity 𝑣.
At time 𝑡:
– 𝑝𝑜 𝑡 + ∆𝑡 = 𝑝𝑜 𝑡 + 𝑣∆𝑡
– Difference: ∆𝑝𝑜 = 𝑝𝑜 𝑡 + ∆𝑡 − 𝑝𝑜 𝑡 = 𝑣∆𝑡
– If 𝑝𝑜 0 = 𝑃, then 𝑝𝑜 𝑡 = 𝑃 + 𝑣𝑡
– Position linear in velocity (in this case!)
• …𝑣 is never constant in practice
– a function of time 𝑣(𝑡), so 𝑝𝑜 𝑠 = 𝑃 + 0𝑠𝑣 𝑡 𝑑𝑡
– The position has to be accumulated (integrated in time),
taking into account acceleration.
10
Velocity
Game Physics
• The change in velocity: 𝑣 = 𝑑𝑎 𝑑𝑡.
– Constant acceleration: ∆𝑣 = 𝑎∆𝑡.
– Otherwise, integrate: 𝑣 𝑠 = V + 0𝑠𝑎 𝑡 𝑑𝑡.
• Discretization
– Sampling and calculating after every step ∆𝑡 (typically
short enough).
– Acceleration assumed constant in the time interval.
– New velocity: 𝑣 𝑡 + ∆𝑡 = 𝑣 𝑡 + 𝑎∆𝑡.
– New position: 𝑝𝑜 𝑡 + ∆𝑡 = 𝑝𝑜 𝑡 + 𝑣∆𝑡.
11
Acceleration
Physics-based system
Game Physics
• Changes in velocity and acceleration
are induced by forces.
• Forces are vectors operating on
objects, producing acceleration in the
direction of the force.
• The sum of all forces acting on an
object determines how it moves.
• The notation 𝐹 will be used in place of 𝐹, but the context indicates if it is a
scalar or a vector.
14
Forces
Game Physics
• In the late 17th century, Sir
Isaac Newton described three
laws that govern all motion on
Earth.
• ...ultimately, an approximation
– Small scale: quantum mechanics.
– Big scale: theories of relativity.
15
Newton’s laws of motion
Game Physics
• Sum of forces on an object is null there is no
change in the motion
• With zero force sum:
– An object at rest stays at rest
– An moving object continues to move at the same speed
in the same direction.
16
1st Law of Motion
If 𝐹𝑛𝑒𝑡 = 0, there is no change in motion
Game Physics
• Each force induces an acceleration in its direction,
linear to its mass:
• Consequently:
– More force faster speed-up.
– Same force lighter objects accelerate faster than
heavy objects.
17
2nd Law of Motion
𝐹𝑛𝑒𝑡 = 𝑚 ∗ 𝑎𝑚 is the mass and 𝑎 the acceleration
Game Physics
• Forces have consequences:
• All forces are actually interactions between bodies!
18
3rd Law of Motion
When two objects come into contact, they exert
equal and opposite forces upon each other.
Forces
Game Physics
• Newton’s Law of Gravitation: the gravitation force
between two masses 𝐴 and 𝐵 is:
– Proportional to the product of the masses 𝑚𝐴 and 𝑚𝐵.
– Inversely proportional to the squared distance between
them.
– In the direction of the line connecting the two masses.
𝐹𝑔 = 𝐹𝐴→𝐵 = −𝐹𝐵→𝐴 = 𝐺𝑚𝐴𝑚𝐵
𝑟2𝑢𝐴𝐵
𝐺: gravitational constant 6.673 × 10−11 [𝑚3𝑘𝑔−1𝑠−2].
𝑟: the distance.
𝑢𝐴𝐵: the unit direction between the points.
20
Gravity
Game Physics
• By applying Newton’s second law to an object with
mass 𝑚 on the surface of the Earth we obtain
𝐹𝑛𝑒𝑡 = 𝐹𝑔 = 𝑚 ∗ 𝑎
𝐺𝑚∗𝑚𝐸𝑎𝑟𝑡ℎ
𝑟𝐸𝑎𝑟𝑡ℎ2 = 𝑚 ∗ 𝑎
𝐺𝑚𝐸𝑎𝑟𝑡ℎ
𝑟𝐸𝑎𝑟𝑡ℎ2 = 𝑎
𝑎 = 6.673 × 10−115.98×1024
6.377×106 2 = 9.81 𝑚/𝑠2
21
Gravity on Earth
Mass of object is canceled out!
http://lannyland.blogspot.co.at/2012/12/10-
famous-thought-experiments-that-just.html
Game Physics
• On Earth at altitude ℎ: 𝑎 = 𝐺𝑚𝐸𝑎𝑟𝑡ℎ
𝑟𝐸𝑎𝑟𝑡ℎ+ℎ2
• On the Moon
– 𝑚𝑚𝑜𝑜𝑛 = 7.35 × 1022 𝑘𝑔
– 𝑟𝑚𝑜𝑜𝑛 = 1738 𝑘𝑚
– 𝑔𝑚𝑜𝑜𝑛 = 1.62 𝑚/𝑠2
• On Mars
– 𝑚𝑚𝑎𝑟𝑠 = 6.42 × 1023 𝑘𝑔
– 𝑟𝑚𝑎𝑟𝑠 = 3403 𝑘𝑚
– 𝑔𝑚𝑎𝑟𝑠 = 3.69 𝑚/𝑠2
22
Other gravity
Game Physics
• Weight gravitational force
𝑊 = 𝑚 ∗ 𝑔
• We weigh differently on the moon (but have the
same mass…)
• Force units: 𝑘𝑔 ∗𝑚
𝑠2.
– Denoted as Newtons (𝑁)
23
Weight1.6-1.9
Game Physics
• Force acting as a reaction to contact with plane.
– Direction normal to the surface of contact.
– Magnitude cancels the weight applied on the plane.
• Here, 𝐹𝑁 = 𝑊 cos(𝛼) = 𝑚𝑔 cos(𝛼)
• Related to collision handling (more later).
• Object slides down plane with remaining force: 𝑊sin(𝛼).
24
Normal force1.10
Game Physics
• Can the object stay in total equilibrium?
– An extra tangential friction force must cancel 𝑊sin(𝛼).
• Ability to resist movement
– Static friction keeps an object on a surface from moving.
– Kinetic friction slows down an object in contact.
25
Friction
Game Physics
• Static friction: a threshold
– object will not move unless tangential gravity is stronger.
• Kinetic friction is applied when the object is moving.
• Depends on the two materials coming in contact
– smoother less friction.
– defined by a coefficient of friction 𝜇: the ratio of friction
between two bodies and the force pressing them together.
• Friction forces are calculated from these coefficients
– Static friction: 𝐹𝑠 = 𝜇𝑠𝐹𝑁– Kinetic friction: 𝐹𝑘 = 𝜇𝑘𝐹𝑁
26
Friction
Game Physics
• The kinetic coefficient of friction is always smaller
than the static friction.
• If the tangential force is larger than the static
friction, the object moves.
• If the object moves while in contact, the kinetic
friction is applied to the object
27
Friction1.11-1.12
Game Physics
Surface Friction Static (𝝁𝒔) Kinetic (𝝁𝒌)
Steel on steel (dry) 0.6 0.4
Steel on steel (greasy) 0.1 0.05
Teflon on steel 0.041 0.04
Brake lining on cast iron 0.4 0.3
Rubber on concrete (dry) 1.0 0.9
Rubber on concrete (wet) 0.30 0.25
Metal on ice 0.022 0.02
Steel on steel 0.74 0.57
Aluminum on steel 0.61 0.47
Copper on steel 0.53 0.36
Nickel on nickel 1.1 0.53
Glass on glass 0.94 0.40
Copper on glass 0.68 0.53
28
Friction
Game Physics
• An object moving in a fluid (air is a fluid) is slowed
down by this fluid.
• This is called fluid resistance or drag and depends
on several parameters, e.g.:
– High velocity larger resistance
– More surface area larger resistance (“aerodynamics”)
29
Fluid resistance
Game Physics
• At high velocity, the drag force 𝐹𝐷ℎ𝑖𝑔ℎ is quadratic
to the relative velocity of the object 𝑣
𝐹𝐷ℎ𝑖𝑔ℎ = −1
2∗ 𝜌 ∗ 𝑣2 ∗ 𝐶𝑑 ∗ 𝐴
• 𝜌 is the density of the fluid (1.204 for air at 20℃)
• 𝐶𝑑 is the drag coefficient (depends on the shape of
the object).
• 𝐴 is the reference area (area of the projection of
the exposed shape).
30
Fluid resistance
Game Physics
• At low velocity, the drag force is approximately
linearly proportional to the velocity
𝐹𝐷𝑙𝑜𝑤 ≈ −𝑏 ∗ 𝑣
where 𝑏 depends on the properties of the fluid and
the shape of the object.
• High/low velocity threshold is defined by Reynolds
Number (Re).
31
Fluid resistance1.13
Game Physics
• Develops when an object is immersed in a fluid.
• A function of the volume of the object 𝑉 and the density of the fluid 𝜌:
𝐹𝐵 = 𝜌 ∗ 𝑔 ∗ 𝑉
• Considers the difference of pressure above and below the immersed object.
• Directed straight up, counteracting the weight.
32
Buoyancy1.14
Game Physics
• React according to Hook’s Law on extension and
compression, i.e. on the relative displacement.
• The relative length 𝑙 to the rest-length 𝑙0determines the applied force:
𝐹𝑘 = −𝐾 𝑙 − 𝑙0
• 𝐾 is the spring constant (in 𝑁/𝑚).
33
Springs
Game Physics
• Without interference, objects may oscillate
infinitely.
• Dampers slow down the oscillation between
objects 𝐴 and 𝐵 connected by a spring.
• Opposite to the relative speed between the two
objects:
𝐹𝐶 = −𝐶(𝑣𝐴 − 𝑣𝐵)
where 𝐶 is the damping coefficient and the
resulting force applied on 𝐴 (opposite on 𝐵).
• Similar to friction or drag at low velocity!
34
Dampers
Game Physics
• For body acceleration: sum forces and divide by
mass:
𝐹𝑛𝑒𝑡 = 𝑚 ∗ 𝑎
• Forces add up linearly as vectors. The Free Body
Diagram includes:
– Object shape: center of mass, contact points.
– Applied forces: direction, magnitude and point of
application.
35
Free-Body Diagram
https://www2.southeastern.edu/Academics/F
aculty/rallain/plab193/files/a8312fbf3bde480
4309096169ad22bd5-46.html
Energy-based system
Game Physics
• The work 𝑊 (in 𝐽𝑜𝑢𝑙𝑒 = 𝑁 ∗ 𝑚) is the displacement
∆𝑝𝑜of an object times the net force 𝐹 applied on
the object in the direction of the displacement
𝑊 = 𝐹 ∗ ∆𝑝𝑜
37
Work
𝐹
𝐹 cos 𝛼
𝛼
Game Physics
• The kinetic energy 𝐸𝐾 is the energy of an object in
velocity:
𝐸𝐾 =1
2𝑚 𝑣2
– the faster the object is moving, the more energy it has
– the energy is a scalar (that’s why speed is used and not
velocity)
– unit is also Joule, as 𝑘𝑔(𝑚/𝑠)2= 𝑘𝑔 ∗𝑚
𝑠2𝑚 = 𝑁 ∗ 𝑚 = 𝐽
38
Kinetic energy
Game Physics
• The Work-Energy theorem: net work change in
kinetic energy
𝑊 = ∆𝐸𝐾 = 𝐸𝐾(𝑡 + ∆𝑡) − 𝐸𝐾(𝑡)
i.e.
𝐹 ∆𝑝𝑜 =1
2𝑚 𝑣(𝑡 + ∆𝑡)2 − 𝑣(𝑡)2
– Very similar to Newton’s second law...
39
Work-Energy theorem1.15
Game Physics
• (Gravitational) Potential energy is the energy
‘stored’ in an object due to its height off the ground
– The amount of work that would be done if we set it free.
𝐸𝑃 = 𝑚 ∗ 𝑔 ∗ ℎ
– Simple product of the weight 𝑊 = 𝑚 ∗ 𝑔 and height ℎ.
– Also measured in Joules (as here 𝑘𝑔 ∗𝑚
𝑠2∗ 𝑚).
• Other potential energies exist (like a compressed
spring).
40
Potential energy
Game Physics
• Law of conservation: energy cannot be created or
destroyed.
– Energy may switch form
– May transfer between objects
– For instance, when falling:
𝐸𝐾(𝑡 + ∆𝑡) + 𝐸𝑃(𝑡 + ∆𝑡) = 𝐸𝐾(𝑡) + 𝐸𝑃(𝑡)
i.e.
1
2𝑚𝑣(𝑡 + ∆𝑡)2 +𝑚𝑔ℎ 𝑡 + ∆𝑡 =
1
2𝑚𝑣(𝑡)2 +𝑚𝑔ℎ 𝑡
41
Conservation of mechanical energy
Game Physics
• A roller-coaster cart at the top of the first hill
– Much potential energy but only a little kinetic energy.
– Going down the drop: losing height, picking up speed.
– At the bottom: almost all potential energy switched to
kinetic, cart is at its maximum speed.
42
Conservation: Example
Game Physics
• External forces are usually applied:
– Friction and air resistance.
– Where does the “reduced” energy go?
– Converted into heat and air displacements (sound
waves, wind).
• We compensate by adding an extra term 𝐸𝑂 to the
conservation equation:
𝐸𝐾 𝑡 + ∆𝑡 + 𝐸𝑃 𝑡 + ∆𝑡 = 𝐸𝐾 𝑡 + 𝐸𝑃 𝑡 + 𝐸𝑂– if 𝐸𝑂 > 0, some energy is ‘lost’.
– In game engines, 𝐸𝑂 is usually quite small and depends
on velocity and the medium.
43
Conservation of mechanical energy
1.16
Game Physics
• The linear momentum 𝑝: the mass of
an object multiplied by its velocity:
𝑝 = 𝑚 ∗ 𝑣
• Heavier object/higher velocity
more momentum (more difficult to
stop).
• unit is 𝑘𝑔 ∗ 𝑚/𝑠.
• Vector quantity (velocity).
44
Momentum
Game Physics
• The rate of change of a momentum.
• the net force applied on the object times the amount of application time.– Actually, integrated.
• From Newton’s second law 𝐹 = 𝑚 ∗ 𝑎
⇔ 𝐹 =𝑚 𝑣 𝑡 + ∆𝑡 − 𝑣 𝑡
∆𝑡
⇔ 𝐹 =𝑚 ∗ 𝑣 𝑡 + ∆𝑡 − 𝑚 ∗ 𝑣 𝑡
∆𝑡
⇔ 𝐹 =∆𝑝
∆𝑡⇔ 𝐹∆𝑡 = ∆𝑝
• unit is also 𝑘𝑔 ∗ 𝑚/𝑠 (so also different from a force)
45
Impulse1.17