Download Dynamics 101 - Essential Math for Games Programmers

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Dynamics 101
Marq Singer
Red Storm Entertainment
[email protected]
2
Talk Summary

Going to talk about:
A brief history of motion theory
 Newtonian motion for linear and rotational
dynamics
 Handling this in the computer

3
Physically Based-Motion
Want game objects to move consistent with
world
 Match our real-world experience
 But this is a game, so…
 Can’t be too expensive
 (no atomic-level interactions)

4
History I: Aristotle

Observed:



From this, deduced:





Push an object, stop, it stops
Rock falls faster than feather
Objects want to stop
Motion is in a line
Motion only occurs with action
Heavier object falls faster
Note: was not actually beggar for a bottle
5
History I: Aristotle

Motion as changing position
6
History I: Aristotle
Called kinematics
 Games: move controller, stop on a dime,
move again
 Not realistic

7
History II: Galileo

Observed:



Object in motion slows down
Cannonballs fall equally
Theorized:






Slows due to unseen force: friction
Object in motion stays in motion
Object at rest stays at rest
Called inertia
Also: force changes velocity, not position
Oh, and mass has no effect on velocity
8
History II: Galileo

Force as changing velocity
Velocity changes position

Called dynamics

9
History III: Newton

Observed:


Planet orbit like continuous falling
Theorized:
Planet moves via gravity
 Planets and small objects linked
 Force related to velocity by mass
 Calculus helps formulate it all

10
History III: Newton
Sum of forces sets acceleration
 Acceleration changes velocity
 Velocity changes position

g
11
History III: Newton

Games: Move controller, add force, then
drift
12
History III: Newton

As mentioned, devised calculus


Differential calculus:


rates of change
Integral calculus:



(concurrent with Leibniz)
areas and volumes
antiderivatives
Did not invent the Fig Newton™
13
Differential Calculus Review
Have position function x(t)
 Derivative x'(t) describes how x changes
as t changes (also written dx/dt, or x )
 x'(t) gives tangent vector at time t

x(ti)
y
y(t)
x'(ti)
t
14
Differential Calculus Review
Our function is position:x(t )
 Derivative is velocity:

dx
v(t )  x(t ) 
 x
dt

Derivative of velocity is acceleration
dv
 v
dt
d 2x
 x(t )  2  x
dt
a(t )  v(t ) 
15
Newtonian Dynamics
Summary

All objects affected by forces
Gravity
 Ground (pushing up)
 Other objects pushing against it

Force determines acceleration (F = ma)
dv
 a)
 Acceleration changes velocity (
dx dt
 Velocity changes position (
v )

dt
16
Dynamics on Computer

Break into two parts
Linear dynamics (position)
 Rotational dynamics (orientation)


Simpler to start with position
17
Linear Dynamics

Simulating a single object with:





Last frame position xi
Last frame velocity vi
Mass m
Sum of forces F
Want to know


Current frame position xi+1
Current frame velocity vi+1
18
Linear Dynamics

Could use Newton’s equations
a  F /m
x i1  x i  v i t  1/2at 2
v i1  v i  at



Problem: assumes F constant across frame
Not always true:


E.g. spring force: Fspring = –kx
E.g. drag force: Fdrag = –mv
19
Linear Dynamics
Need numeric solution
 Take stepwise approximation of function

20
Linear Dynamics
Basic idea: derivative (velocity) is going
in the right direction
 Step a little way in that direction (scaled
by frame time h)
 Do same with velocity/acceleration
 Called Euler’s method

21
Linear Dynamics

Euler’s method
x i1  x i  hv i
a  F(x i ,v i ) /m
v i1  v i  ha

22
Linear Dynamics

Another way: use linear momentum
P  mv
P  F

Then
x i1  x i  hvi
Pi1  Pi  hF(x i ,v i )
v i1  Pi1 /m
23
Linear: Final Formulas

Using Euler’s method with time step h
F   Fk (x i ,v i )
k
F
ai 
m
x i1  x i  hv i
v i1  v i  ha i
24
Rotational Dynamics

Simulating a single object with:





Last frame orientation Ri or qi
Last frame angular velocity i
Inertial tensor I
Sum of torques 
Want to know


Current frame orientation Ri+1 or qi+1
Current frame ang. velocity i+1
25
Rotational Dynamics

Orientation

Represented by
Rotation matrix R
 Quaternion q

Which depends on your needs
 Hint: quaternions are cheaper

26
Rotational Dynamics

Angular velocity
Represents change in rotation
 How fast object spinning
 3-vector

Direction is axis of rotation
 Length is amount of rotation (in radians)
 Ccw around axis (r.h. rule)

27
Rotational Dynamics

Angular velocity
Often need to know linear velocity at point
 Solution: cross product

 r  v
v
r

28
Moments of Inertia

Inertial tensor






I is rotational equivalent of mass
3 x 3 matrix, not single scalar factor (unlike m)
Many factors - rotation depends on shape
Describe how object rotates around various axes
Not always easy to compute
Change as object changes orientation
29
Rotational Dynamics

Computing I
Can use values for closest box or cylinder
 Alternatively, can compute based on
geometry

Assume constant density, constant mass at each
vertex
 Solid integral across shape
 See Mirtich,Eberly for more details
 Blow and Melax do it with sums of tetrahedra

30
Rotational Dynamics

Torque
Force equivalent
 Apply to offset from center of mass – creates
rotation
 Add up torques just like forces

31
Rotational Dynamics

Computing torque

Cross product of vector r (from CoM to point
where force is applied), and force vector F
r

F
 r F
Applies torque ccw around vector (r.h. rule)

32
Rotational Dynamics

Center of Mass





Point on body where applying a force acts just like
single particle
“Balance point” of object
Varies with density, shape of object
Pull/push anywhere but CoM, get torque
Generally falls out of inertial tensor calculation
33
Rotational Dynamics
Have matrix R and vector 
 How to compute Ri1  Ri  hi ?
 Convert  to give change in R

Convert to symmetric skew matrix
 Multiply by orientation matrix

 Can use Euler's method after that

34
Computing New Orientation

If have matrix R, then
˜ iRi
Ri1  Ri  h
where

 0

˜   3


 2
 3
0
1
 2 

1

0 
35
Computing New Orientation

If have quaternion q, then
h
q i 1  q i  w i q i
2
where
wi  (0,i )


See Baraff or Eberly for derivation
36
Computing Angular Velocity

Can’t easily integrate angular velocity from
angular acceleration:
  I
 I    I

Can no longer “divide” by I and do Euler step
37
Computing Angular
Momentum

Easier way: use angular momentum
L  I
 
L

Then
L i1  L i  h (Ri , i )
 i1  I L i1
1
i1
38
Using I in World Space
Remember,   I1L
 I computed in local space, must
transform to world space
 If using rotation matrix R, use formula



1
i
1
i 0
I Li  R I R Li
T
i
If using quaternion, convert to matrix
39
Rotational Formulas
   rk  Fk
k
~
R i 1  R n  hi R i
L i 1  L i  h
I
1
i 1
1
i 1 0
R I R
i 1  I i11L i 1
T
i 1
40
Impulses

Normally force acts over period of time
F

E.g., pushing a chair
t
41
Impulses

Even if constant over frame
F
sim assumes application over entire time
t
42
Impulses

But if instantaneous change in velocity?
Discontinuity!
F


t
Still force, just instantaneous
Called impulse - good for collisions/constraints
43
Summary

Basic Newtonian dynamics


Linear simulation


Position, velocity, force, momentum
Force -> acceleration -> velocity -> position
Rotational simulation

Torque -> ang. mom. -> ang. vel. ->
orientation
44
Questions?
45
References




Burden, Richard L. and J. Douglas Faires, Numerical
Analysis, PWS Publishing Company, Boston, MA,
1993.
Hecker, Chris, “Behind the Screen,” Game Developer,
Miller Freeman, San Francisco, Dec. 1996-Jun. 1997.
Witken, Andrew, David Baraff, Michael Kass,
SIGGRAPH Course Notes, Physically Based Modelling,
SIGGRAPH 2002.
Eberly, David, Game Physics, Morgan Kaufmann,
2003.