Physics: The very basics

Download Report

Transcript Physics: The very basics

Computer Game Physics
The very basics
1
The Basics
• Force F
• Mass m
• Acceleration a: a = F/m
• Velocity v: v = a*t
• Position s: s = v*t
…if F is constant
2
Conservation of Energy
Kinetic Energy + Potential Energy = const.
Ek = ½ m * v²
Ep = m * g * h
3
How far and high will a ball fly, if it is kicked
with a speed of 10m/s and an angle of 45
degrees ?
4
Game Physics
• Not trying to build a perfect physical model
• Most things can be approximated assuming
Newtonian physics and rigid bodies
• Use discrete simulation (constant step)
techniques
• Just worry about center of mass for most
things
5
Position and Velocity
• Where is object at time t ?
• Equations
x(t) = t * x_velocity + x_initial
y(t) = t * y_velocity + y_initial
• Computation
x = x + x_velocity
y = y + y_velocity
6
Acceleration
• Computation
x_velocity = x_velocity + x_acceleration
y_velocity = y_velocity + y_acceleration
• Use piecewise linear approximation
to continuous functions
7
Projectile Motion
•
•
•
•
•
•
X = x + Vx *t
Y = y + Vy * t
Vxi = cos(A) * Vi
Vyi = sin(A) * Vi
Vx = Vx - WR(Vx - W)*t
Vy = Vy – (WR(Vy) + G(y))*t
•
•
•
•
•
W = windspeed (x only)
A = inclination angle
Vi = initial velocity
WR = wind resistance
G(y) = gravity,
depending on height
(constant if height
doesn’t change
dramatically)
8
Friction
• Conversion of kinetic energy into heat
• Different types:
– Static friction
– Kinetic or sliding friction
– Rolling friction
9
Friction
Static friction
• For non moving objects only
• Can be seen as threshold of force
needed to accelerate a mass
10
Friction
Kinetic and rolling friction
• Depending on velocity
• Can be modeled as functions of velocity
11
Collisions
• Detect that collision has occurred
(bounding box)
• Determine the time of the collision
(may need to back up to point of collision)
• Determine where objects are when they touch
• Determine the collision normal
(angle of incidence = angle of reflection)
• Determine the velocity vectors after the collision
using the
momentum
12
Momentum
Momentum p = m * v
The total momentum of a closed system is
constant, as is the energy.
This observation totally defines all collisions
13
Example: Collision of 2 spheres
Assumption:
• Sphere 2 has zero velocity before collision
• Both spheres have same mass
We get:
Conservation of momentum:
Conservation of energy:
=>
p1
= p1’ + p2’
m/2 v1² = m/2 v1’² + m/2 v2’²
p1²
= p1’² + p2’²
These 2 equations together tell us that (because of the assumption of
same mass !) the angle between v1’ and v2’ is 90deg .
This makes life simple…
14
Collision of 2 spheres
p1’
p1
p2’
15
Time-Based Modeling
• Time t is used in all kinematic equations that
move objects (to avoid discontinuities caused
by “slower” frame rates)
• This involves scaling dx and dy based on
elapsed time (rather than a virtual clock)
• This allows constant movement regardless of
processor slow downs
16