cs559: computer graphics lecture 36: animation li zhang spring 2008 many slides from james...

61
CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class a

Upload: karin-parker

Post on 14-Dec-2015

222 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

CS559: Computer Graphics

Lecture 36: AnimationLi Zhang

Spring 2008

Many slides from James Kuffner’s graphics class at CMU

Page 2: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Today• Traditional Animation, Computer Animation

• Reading• (Optional) Shirley, ch 16, overview of animation

Page 3: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Animation• Traditional Animation – without using a computer

Page 4: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Animation• Computer Animation

Page 5: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation

Page 6: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation

Page 7: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation

Nguyen, D., Fedkiw, R. and Jensen, H., "Physically Based Modeling and Animation of Fire", SIGGRAPH 2002

Page 8: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation

Enright, D., Marschner, S. and Fedkiw, R., "Animation and Rendering of Complex Water Surfaces", SIGGRAPH 2002

Page 9: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation• Data driven animation

Page 10: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation• Data driven animation

Page 11: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation• Data driven animation

Page 12: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Cartoon Animation• Key Frame Animation • Physics based animation• Data driven animation

Page 13: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Principles of Animation

John Lasseter. Principles of traditional animation applied to 3D computer animation. Proceedings of SIGGRAPH (Computer Graphics) 21(4): 35-44, July 1987.

• Goal: make characters that move in a convincing way to communicate personality and mood.

• Walt Disney developed a number of principles.– ~1930

• Computer graphics animators have adapted them to 3D animation.

Page 14: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Principles of Animation• The following are a set of principles to keep in mind:

1. Squash and stretch2. Staging3. Timing4. Anticipation5. Follow through6. Overlapping action7. Secondary action8. Straight-ahead vs. pose-to-pose vs. blocking9. Arcs10. Slow in, slow out11. Exaggeration12. Appeal

Page 15: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Squash and stretch• Squash: flatten an object or character by pressure

or by its own power.• Stretch: used to increase the sense of speed and

emphasize the squash by contrast.• Note: keep volume constant!

• http://www.siggraph.org/education/materials/HyperGraph/animation/character_animation/principles/squash_and_stretch.htm

• http://www.siggraph.org/education/materials/HyperGraph/animation/character_animation/principles/bouncing_ball_example_of_slow_in_out.htm

Page 16: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Squash and stretch (cont’d)

Page 17: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Squash and stretch (cont’d)

Page 18: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Anticipation• An action has three parts: anticipation, action,

reaction.• Anatomical motivation: a muscle must extend before

it can contract.

• Prepares audience for action so they know what to expect.

• Directs audience's attention.• Watch: bugs-bunny.virtualdub.new.mpg

Page 19: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Anticipation (cont’d)• Amount of anticipation (combined with timing)

can affect perception of speed or weight.

Page 20: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Arcs• Avoid straight lines since most things in nature

move in arcs.

Page 21: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Slow in and slow out• An extreme pose can be emphasized by slowing

down as you get to it (and as you leave it).• In practice, many things do not move abruptly

but start and stop gradually.

Page 22: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Exaggeration• Get to the heart of the idea and emphasize it so

the audience can see it.

Page 23: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Exaggeration• Get to the heart of the idea and emphasize it so

the audience can see it.

Page 24: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Appeal• The character must interest the viewer.• It doesn't have to be cute and cuddly.• Design, simplicity, behavior all affect appeal.• Example: Luxo, Jr. is made to appear childlike.

Page 25: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Appeal (cont’d)• Note: avoid perfect symmetries.

Page 26: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Appeal (cont’d)• Note: avoid perfect symmetries.

Page 27: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle Systems• http://en.wikipedia.org/wiki/Particle_system

Page 28: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

What are particle systems?• A particle system is a collection of point masses

that obeys some physical laws (e.g, gravity, heat convection, spring behaviors, …).

• Particle systems can be used to simulate all sorts of physical phenomena:

Page 29: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle in a flow field• We begin with a single particle with:

– Position,

– Velocity,

• Suppose the velocity is actually dictated by some driving function g:

( , )tx g x

/

/

dx dtddy dtdt

xv x

x

g(x,t)

x

y

x

y

x

Page 30: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Vector fields• At any moment in time, the function g defines a

vector field over x:

• How does our particle move through the vector field?

Page 31: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Diff eqs and integral curves• The equation

• is actually a first order differential equation.• We can solve for x through time by starting at an initial

point and stepping along the vector field:

• This is called an intial value problem and the solution is called an integral curve.

Start Here

( , )tx g x

Page 32: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Euler’s method• One simple approach is to choose a time step, t, and take linear

steps along the flow:

• Writing as a time iteration:

• This approach is called Euler’s method and looks like:

• Properties:– Simplest numerical method– Bigger steps, bigger errors. Error ~ O(t2).

• Need to take pretty small steps, so not very efficient. Better (more complicated) methods exist, e.g., “Runge-Kutta” and “implicit integration.”

( ) ( ) ( )

( ) ( , )

t t t t t

t t t

x x x

x g x

1i i it x x v

Page 33: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle in a force field• Now consider a particle in a force field f.• In this case, the particle has:

– Mass, m– Acceleration,

• The particle obeys Newton’s law:

• The force field f can in general depend on the position and velocity of the particle as well as time.

• Thus, with some rearrangement, we end up with:

( , , )tm

f x x

x

m m f a x

2

2d ddt dtv

a x vx

Page 34: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

This equation:

is a second order differential equation.

Our solution method, though, worked on first order differential equations.

We can rewrite this as:

where we have added a new variable v to get a pair of coupled first order equations.

Second order equations

( , , )tm

x v

f x vv

( , , )tm

f x v

x

Page 35: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Phase space

• Concatenate x and v to make a 6-vector: position in phase space.

• Taking the time derivative: another 6-vector.

• A vanilla 1st-order differential equation.

x

v

/m

x v

v f

x

v

Page 36: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Differential equation solver

Applying Euler’s method:

( ) ( ) ( )

( ) ( ) ( )

t t t t t

t t t t t

x x x

x x x

Again, performs poorly for large t.

/m

x v

v f

1

1

i i i

ii i

t

tm

x x v

fv v

( ) ( ) ( )

( , , )( ) ( )

t t t t t

tt t t t

m

x x v

f x xv x

And making substitutions:

Writing this as an iteration, we have:

Starting with:

Page 37: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle structure

m

x

v

f

positionvelocityforce accumulatormass

Position in phase space

How do we represent a particle?

Page 38: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Single particle solver interface

m

x

v

f

x

v

/m

v

f

6getDim

derivEval

getState

setState

Page 39: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle systems

particles n time

In general, we have a particle system consisting of n particles to be managed over time:

1 2

1 2

1 2

1 2

n

n

n

nm m m

x x x

v v v

ff f

Page 40: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle system solver interface

particles n time

1 1 2 2

1 21 2

1 2

6

n n

nn

n

n

m m m

x v x v x v

ff fv v v

derivEval

get/setState getDim

For n particles, the solver interface now looks like:

Page 41: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle system diff. eq. solverWe can solve the evolution of a particle system again using the Euler method:

11 1 1

11 1 1 1

1

1

/

/

i i i

i i i

i i in n ni i in n n n

mt

m

x x v

v v f

x x v

v v f

Page 42: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Forces• Each particle can experience a force which sends

it on its merry way.• Where do these forces come from? Some

examples:– Constant (gravity)– Position/time dependent (force fields)– Velocity-dependent (drag)– N-ary (springs)

• How do we compute the net force on a particle?

Page 43: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle systems with forces

particles n time forces

F2 Fnf

nf

1 2

1 2

1 2

1 2

n

n

n

nm m m

x x x

v v v

ff f

• Force objects are black boxes that point to the particles they influence and add in their contributions.

• We can now visualize the particle system with force objects:

F1

Page 44: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Gravity and viscous drag

grav mf G

p->f += p->m * F->G

drag dragkf v

p->f -= F->k * p->v

The force due to gravity is simply:

Often, we want to slow things down with viscous drag:

Page 45: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

A spring is a simple examples of an “N-ary” force.

Recall the equation for the force due to a spring:

We can augment this with damping:

The resulting force equations become:

Note: stiff spring systems can be very unstable under Euler integration. Simple solutions include heavy damping (may not look good), tiny time steps (slow), or better integration (Runge-Kutta is straightforward).

Damped spring

( )springf k x r

[ ( ) ]spring dampf k x r k v

r = rest length 11

1

p

x

v

22

2

p

x

v

Page 46: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

1 2

1 2

1 2

1 2

0 0 0

n

n

n

nm m m

x x x

v v v

ff f

derivEval1. Clear forces

• Loop over particles, zero force accumulators

2. Calculate forces• Sum all forces into accumulators

3. Return derivatives• Loop over particles, return v and f/m

1 2

1 2

1 2

n

n

nm m m

v v v

ff f

Apply forces to particles

Clear force accumulators

1

2

3 Return derivativesto solver

1 2

1 2

1 2

1 2

n

n

n

nm m m

x x x

v v v

ff f

F2 F3 FnfF1

Page 47: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Bouncing off the walls• Handling collisions is a useful add-on for a particle simulator.• For now, we’ll just consider simple point-plane collisions.

A plane is fully specified by any point P on the plane and its normal N.

N

Pv

x

Page 48: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Collision DetectionHow do you decide when you’ve made exact contact with the plane?

N

Pv

x

Page 49: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Normal and tangential velocity

( )N

T N

v N vN

v v v

To compute the collision response, we need to consider the normal and tangential components of a particle’s velocity.

N

P

v

x

Nv v

Tv

Page 50: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Collision Response

before after

T restitution Nk v v v

v’resitution Nk v

Tv

The response to collision is then to immediately replace the current velocity with a new velocity:

The particle will then move according to this velocity in the next timestep.

Nv v

Tv

Page 51: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Collision without contact• In general, we don’t sample moments in time when particles are in exact contact with the surface.

• There are a variety of ways to deal with this problem.• The most expensive is backtracking: determine if a collision must

have occurred, and then roll back the simulation to the moment of contact.

• A simple alternative is to determine if a collision must have occurred in the past, and then pretend that you’re currently in exact contact.

Page 52: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Very simple collision response• How do you decide when you’ve had a collision?

A problem with this approach is that particles will disappear under the surface. We can reduce this problem by essentially offsetting the surface:

Also, the response may not be enough to bring a particle to the other side of a wall In that case, detection should include a velocity check:

N

Pv1

x1

x2

x3v2

v3

Page 53: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

More complicated collision response• Another solution is to modify the update scheme to:

– detect the future time and point of collision

– reflect the particle within the time-step

N

Pv

x

Page 54: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Particle frame of reference• Let’s say we had our robot arm example and we

wanted to launch particles from its tip.

• How would we go about starting the particles from the right place?

• First, we have to look at the coordinate systems in the OpenGL pipeline…

Page 55: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

The OpenGL geometry pipeline

Page 56: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Projection and modelview matrices• Any piece of geometry will get transformed by a

sequence of matrices before drawing:

• p’= Mproject Mview Mmodel p

• The first matrix is OpenGL’s GL_PROJECTION matrix.

• The second two matrices, taken as a product, are maintained on OpenGL’s GL_MODELVIEW stack:

• Mmodelview = Mview Mmodel

Page 57: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Robot arm code, revisited• Recall that the code for the robot arm looked

something like:• glRotatef( theta, 0.0, 1.0, 0.0 );• base(h1);• glTranslatef( 0.0, h1, 0.0 );• glRotatef( phi, 0.0, 0.0, 1.0 );• upper_arm(h2);• glTranslatef( 0.0, h2, 0.0 );• glRotatef( psi, 0.0, 0.0, 1.0 );• lower_arm(h3);

• All of the GL calls here modify the modelview matrix.

• Note that even before these calls are made, the modelview matrix has been modified by the viewing transformation, Mview.

Page 58: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Computing the particle launch point• To find the world coordinate position of the end of the

robot arm, you need to follow a series of steps:• 1. Figure out what Mview is before drawing your model.

2.Draw your model and add one more transformation to the tip of the robot arm.

• glTranslatef( 0.0, h3, 0.0 );

• 3. Compute

• 4. Transform a point at the origin by the resulting matrix.

• Now you’re ready to launch a particle from that last computed point!

Vec3f particleOrigin = particleXform * Vec3f(0,0,0);

Mat4f particleXform = getWorldXform(matCam);

Mat4f matCam = glGetModelViewMatrix();

-1model view modelviewM M M

Page 59: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Types of Animation• Easier to render, 3d model, and mocap, physical

simulation

Page 60: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Timing• Lip sync?

Page 61: CS559: Computer Graphics Lecture 36: Animation Li Zhang Spring 2008 Many slides from James Kuffner’s graphics class at CMU

Character animation• FK?• IK?