Physically based animation

advertisement
Physically Based Animation
and Modeling
CSE 3541
Matt Boggus
Overview
• Newton’s three laws of physics
• Integrating acceleration to find position
• Particle Systems
• Common forces in physically based animation
Mass and Momentum
• Associate a mass with an object. We assume that the
mass is constant
m'  m
• Define a vector quantity called momentum (p),
which is the product of mass and velocity
p  mv
Newton’s First Law
• A body in motion will remain in motion
• A body at rest will remain at rest, unless acted upon
by some force
• Without a force acting on it, a moving object travels
in a straight line
a0
v'  v
x'  x  vt
p'  p  mv
Newton’s Second Law
• Newton’s Second Law says:
dp
f
 ma
dt
• This relates the kinematic quantity of acceleration
to the physical quantity of force
(Kinematics – the branch of mechanics concerned with the motion of
objects without reference to the forces that cause the motion)
Newton’s Third Law
• Newton’s Third Law says that any force that body A applies to
body B will be met by an equal and opposite force from B to A
f AB  f BA
• Every action has an equal and opposite reaction
– Do we really want this for games and animation?
Integration
Given acceleration,
compute velocity &
position by integrating
over time
f  ma
a  f /m
v'  v  a  t
1
p '  p  vt  at 2
2
Physics review, equations for:
Zero acceleration
Constant acceleration
No acceleration
a0
v  v0
x  x0  v 0 t
Constant acceleration
a
f  ma
a  f /m
v'  v  a  t
(v  v ' )
x'  x 
t
2
m
v’
vave
a
v
f
Pseudocode for motion within an
animation loop (Euler method)
To update an object at point x with velocity v:
a = (sum all forces acting on x) / m
[ ∑vectors scalar: m ]
v = v + a * dt
[ vectors: v, a scalar: dt ]
x = x + v * dt
[ vectors: x, v scalar: dt ]
Pseudocode for motion within an
animation loop (Euler 2)
To update an object at point x with velocity v:
a = (sum all forces acting on x) / m
endv = v + a * dt
x=x+
𝑒𝑛𝑑𝑣+𝑣
2
v = endv
∗ dt
[ ∑vectors scalar: m ]
[vectors: endv, v, a scalar: dt]
[vectors: x, endv, v scalars: 2, dt]
[vectors: endv, v]
Comparison of methods
See spreadsheet example
Particle Systems
• A collection of a large number of point-like elements
• Model “fuzzy” or “fluid” things
– Fire, explosions, smoke, water, sparks, leaves, clouds, fog,
snow, dust, galaxies, special effects
• Model strands
– Fur, hair, grass
• Star Trek 2 – genesis sequence (1982)
– The making of the scene
• More examples
Particle Systems
Lots of small particles - local rules of behavior
Create ‘emergent’ element
Common rules for particle motion:
Do collide with the environment
Do not collide with other particles
Common rules for particle rendering:
Do not cast shadows on other particles
Might cast shadows on environment
Do not reflect light - usually emit it
Particle
Example
Collides with environment
but not other particles
Particle’s midlife with
modified color and shading
Particle’s demise, based on
constrained and randomized life span
source
Particle’s birth: constrained and time with
initial color and shading (also randomized)
Particle system implementation
Update Steps
1. for each particle
1. if dead, reallocate and assign new attributes
2. animate particle, modify attributes
2. render particles
Use constrained randomization to keep control of
the simulation while adding interest to the visuals
Constrained randomization
particleX = x
particleY = y
particleX = x + random(-1,1)
particleY = y + random(-1,1)
Particle (partial example in C#)
class Particle {
Vector3 position;
// Updates frame to frame
Vector3 velocity;
// Updates frame to frame
Vector3 force;
// Reset and recomputed each frame
GameObject geom;
// other variables for mass, lifetime, …
public:
void Update(float deltaTime);
void ApplyForce(Vector3 &f) { force.Add(f); }
void ResetForce() { force = Vector3.zero; }
// other methods…
};
Particle emitter (partial example in C#)
using System.Collections.Generic;
using System.Collections;
class ParticleEmitter {
ArrayList Particles = new ArrayList();
public:
void Update(deltaTime);
};
Particle Emitter Update()
Update(float deltaTime) {
foreach (Particle p in Particles) {
// …add up all forces acting on p…
}
foreach (Particle p in Particles){
p.Update(deltaTime);
p.ResetForce();
}
}
Creating GameObjects
for(int i = 0; i < numberOfAsteroids; i++){
GameObject aSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
aSphere.transform.parent = transform;
aSphere.name = "sphere" + i.ToString();
aSphere.transform.position = new Vector3(Random.Range(-10.0f, 10.0f),
Random.Range(-10.0f, 10.0f),
Random.Range(-10.0f, 10.0f));
aSphere.transform.localScale = new Vector3(Random.Range(0.0f, 1.0f),
Random.Range(0.0f, 1.0f),
Random.Range(0.0f, 1.0f));
}
Deleting GameObjects
GameObject myParticle;
// …create, animate, etc. …
Destroy(myParticle);
Note: this affects the
associated GameObject;
it does not delete the
variable myParticle
Lab3
• Implement a particle system where each
particle is a GameObject
• Restrictions
– No RigidBodies
– No Colliders
– Minimal credit if you use these for lab3
Forces – gravity
Gm1m2
F
d2
Gmearthm2
F
2
d earth radius
F
a
 9 .8 m / s 2
m2
Forces
f st  k st f N
Static friction
f k  kk f N
Kinetic friction
f vis   K vis nv
K vis  6r
Viscosity
for small objects
No turbulence
For sphere
Forces
• Aerodynamic drag is complex and difficult to model accurately
• A reasonable simplification it to describe the total
aerodynamic drag force on an object using:
f aero
1
2
  v cd ae
2
v
e
v
• Where ρ is the density of the air (or water, mud, etc.), cd is the
coefficient of drag for the object, a is the cross sectional area
of the object, and e is a unit vector in the opposite direction
of the velocity
– In short – create a scaled vector in the opposite direction of velocity
Forces – spring-damper
Hooke’s Law
F  k s ( Lcurrent  Lrest )
F  k s ( Lcurrent  Lrest )  k dVspring
Damping example
Animation from http://www.acs.psu.edu/drussell/Demos/SHO/damp.html
Spring-mass-damper system
f
-f
Springs
• At rest length l, the force f is zero
• Points are located at r1 and r2
f  xe
x  r1  r2  l
[scalar displacement]
r1  r2
e
r1  r2
[direction of displacement]
Spring-mass system
V3
E23
E31
V1
E12
V2
Example – Jello cube
http://www.youtube.com/watch?v=b_8ci0ZW4vI
Spring mesh – properties for cloth
Each vertex is a point mass
Each edge is a spring-damper
Diagonal springs for rigidity
Angular springs connect every
other mass point
Global forces: gravity, wind
Example http://www.youtube.com/watch?v=ib1vmRDs8Vw
Virtual springs – soft constraints
Download