1 animation jeff parker, 2013 thanks to prof. okan arikan, ut austin ed angel, unm

93
1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Upload: poppy-miller

Post on 18-Jan-2016

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

1

Animation

Jeff Parker, 2013Thanks to Prof. Okan Arikan, UT Austin

Ed Angel, UNM

Page 2: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

2

Outline

Classical Animation

History

Computer Animation

Kinematics

Hierarchical Models

Why?

How?

Page 3: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

3

Brief History of Animation

Shadow Puppets

Persistence of Vision

Flipbook

Thaumotrope

Phenakistiscope

Zoetrope

Page 4: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

4

Muybridge

Eadweard Muybridge

Settled bet for Leland Stanford on unsupported transit:

Is there a point when all four of a horse's hooves are off the ground?

Page 5: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

5

They do, but not as Stanford imagined

Page 6: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

6

They do, but not as Stanford imagined

Page 7: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

7

Muybridge

Sallie Gardner at a Gallop

Page 8: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

8

Muybridge

The Photographer, Philip Glasshttp://www.youtube.com/watch?v=G5Afodfj4t8

Racetrack CameraUniversity of Penn Archives

Page 9: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

9

Disney’s 12 Principles of Animation1. Squash and stretch

2. Anticipation

3. Staging

4. Straight Ahead Action and Pose to Pose

5. Follow through and overlapping action

6. Slow In and Slow Out

7. Arcs

8. Secondary Action

9. Timing

10.Exaggeration

11.Solid Drawing

12.Appeal

http://www.youtube.com/watch?NR=1&v=xqGL1ZLk3n8

Page 10: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

10

Squash and stretch

Exaggerate deformation for comedic effect.

However, the volume should remain fixed.

Page 11: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

11

Stretch and Squash Example

Bouncing Ballhttp://www.idleworm.com/how/anm/01b/bball.shtml

Page 12: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

12

Slow In and Out

Bouncing Ballhttp://www.siggraph.org/education/materials/HyperGraph/animation/

character_animation/principles/bouncing_ball_example_of_slow_in_out.htm

Page 13: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

13

Anticipation

Direct the audience’s attention to where the action is about to happen

Page 14: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

14

Follow through and overlapping Action

Each action leads to the next

Audience needs to see the resolution

50 seconds in

http://www.youtube.com/watch?v=5V-QsiPiN_k

Page 15: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

15

Secondary Motion

A secondary action caused by the primary action

Increases interest, if it does not detract from primary

Page 16: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

16

Flour Sack

Can we use these simple ideas to inject personality?

Common challenge: animate a half filled flour sack

http://www.youtube.com/watch?v=FbG3UCY-9Xw

Page 17: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

17

Traditional Animation ProcessStoryboard

Sequence of drawings with descriptions

Story-based description

Voice recording

Match animation to draft soundtrack

Final soundtrack with music and sound effects done last

Key frames

Draw key frames as line drawings

Fill in the intermediate images (Inbetweens)

Painting

Paint the drawings

Page 18: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

18

Story Board

Page 19: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

19

Key Frames(Keyframes) – draw key poses in a sequence

Often a way of splitting up work: senior artist draws keyframees

Novice draws the transitions - inbetweening

Page 20: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

20

Putting it all together

Which effects you can recognize in Pixar's Luxo Jr?

Graphical effects

Taditional animation effects

How does Lasseter convey personality? Emotions?

How does he direct your attention?

http://www.youtube.com/watch?v=Hrnz2pg3YPg

Page 21: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

21

Kinematics

Given a description of a system, describe how it moves

Interested in positions of each component, not in the speed

Page 22: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

22

KinematicsKinematics

Considers only motion given the disposition

Dynamics

Considers underlying forces

Compute motion from initial conditions and physics

Easy to do with particles

Page 23: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

23

Particle SystemsThe genesis effect, from the Wrath of Kahn

http://www.youtube.com/watch?v=NM1r37zIBOQ

William T. Reeves, Particle Systems: A Technique for Modeling a Class of Fuzzy Objects, 1983

Page 24: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

24

Sample Point system

We often use differential equations to model behavior

Our particles are corks bobbing in sea currents

Differential equations define a vector field

Our goal is to follow the path of a cork

Page 25: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

25

Evaluating path

The program pointDiffyQ.c

compares two ways to follow paths

Euler method - yellow

Trapezoid method – blue

The point this visualization tries to make is that the additional work for the trapazoid method gives a much more stable solution

Higher order methods, such as Runge-Kutta, are not much more work, but are much more stable

Page 26: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

26

Euler Update

/* dx/dt: how x will change this step */

double xprime(double x, double y)

{

return (cy - y);

}

/* dy/dt: how y will change this step */

double yprime(double x, double y)

{

return (x - cx);

}

/* Use the slope at (x, y) to predict the next step */

/* This is simple, but not very good */

void eulerUpdate(double x, double y, double *newx, double *newy, double deltaT)

{

*newx = x + deltaT*xprime(x, y);

*newy = y + deltaT*yprime(x, y);

}

Page 27: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

27

Trapezoid Update

double xprime(double x, double y);

double yprime(double x, double y);

/* Average slope at (x, y)

* and the slope at the endpoint Euler would predict */

/* This is better than simple Euler */

void trapUpdate(double x, double y, double *newx, double *newy, double deltaT)

{

double approxX = x + deltaT*xprime(x, y);

double approxY = y + deltaT*yprime(x, y);

*newx = x + deltaT*(xprime(x, y) + xprime(approxX, approxY))/2.0;

*newy = y + deltaT*(yprime(x, y) + yprime(approxX, approxY))/2.0;

}

Page 28: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

28

Hierarchical Modeling

System needs to be complex to capture realistic movement

You have over two dozen bones in each foot

We will settle for less

What is focus for figure running?

Core

Foot on the ground

Look at a very small example

Bicep and forearm

Page 29: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Forward Kinematics

This simple system is described by two angles

Position is given by

Length of arms a1 and a2

Angles θ1 and θ2

We can compute O1, O2

This is Forward Kinematics

2

1

a1

a2

O2

O1

O0

x1

x0

x2

y1

y2

y0

Page 30: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Forward Kinematics

O1 = (a1 cosθ1,a1 sinθ1)

O2 = O1 + (a2 cos(θ1 +θ 2),a2 sin(θ1 +θ 2))

(x,y) = (a1 cosθ1 + (a2 cos(θ1 +θ 2), a1 sinθ1 + a2 sin(θ1 +θ 2))

Page 31: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

31

Inverse KinematicsGiven a complex system, figure out how to

make it reach an object

Typically we position a tool

Pen for writing

Soldering Gun

Tongue for eating snowflakes

Description is a vector of joint angles

Or a sequence of such vectors

Jeff Lew

Page 32: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Motion Capture

One way to solve the problem of kinematics

Record motion from instrumented live actor

Tom Hanks in Polar Express

Page 33: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Study examples

http://www.angryanimator.com/word/2010/11/26/tutorial-2-walk-cycle/

http://www.angryanimator.com/tut/pic/002_walkcycle/wlk03.swf

Page 34: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Preston Blair on Gait

Page 35: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Gait is key to character

http://www.youtube.com/watch?v=RgMkD4t9ZmQ

http://www.youtube.com/watch?v=ZisWjdjs-gM

Page 36: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Work Space vs. Configuration Space

Work spaceObject space: usually 3DDimensionality:

R3 for most thingsR2 for our extended linkage example

Configuration spaceThe space of possible object configurations

Often much higher dimension than work spaceDegrees of Freedom

The number of parameters that necessary and sufficient to define position in configuration

Page 37: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Return to our Example

Work space: 2D WasherConfiguration Space: 2D Torus (2π == 0)

Ambiguity in the middle: two ways to reach a positionElbow up or down?

Singularities at the boundaries of Work Space

Page 38: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Puma Robot

Degrees of Freedom?

Base

Shoulder

Elbow

Wrist

Work space

http://www.youtube.com/watch?v=kzddvCo3RNshttp://www.youtube.com/watch v=kEed8DVO21I

Page 39: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Solving Inverse Kinematics

Given end effector position, compute required joint angles

In simple case, analytic solution exists

Use trig, geometry, and algebra to solve

In larger examples, need to use Numerical Methods

Why is the problem hard?

Solutions may not exist

Might not be unique

In our simple case, solution is:

Compute distance from tip to tail

Position second arm for distance,

Rotate first arm to position tip

Page 40: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

2

1

a1

a2

O2

O1

O0

x1

x0

x2

y1

y2

y0

(x,y)

2

22

221

22

22222

211

2

222

21

22

22222

21

22

21

2221

22

21

222122

21

22

21

22

2

22122

21

22

tan2

2

2

cos1

cos1

2tan

accuracygreater for

2cos

)cos(2

aayx

yxaa

aayx

yxaa

aayxaa

aayxaa

aa

aayx

aaaayx

Twin solutions: elbow up or down

Page 41: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Iterative Solutions

Frequently it is not possible to find a closed form One technique is to use the multi-dimensional derivativeThe Jacobian is the derivative relative to each input

Named after K. G. J. JacobiIf y is function of three inputs and one output

33

22

11

321 ),,(

xx

fx

x

fx

x

fy

xxxfy

Page 42: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Compute JacobianIn our case, Jacobian is a square matrix since dimension

of configuration space = dimension of the work space

Not true for 3 segment planar linkage, or the Puma

To move towards a goal, invert the Jacobian and use that as directive on where to start to move

Make small change, recompute the Jacobian, and try again

Page 43: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Jacobian

The Jacobian tells us how the output changes as we change the input

We know current position of the effector, and know where we want it

The difference is Delta Y (Y dot)

We want to find Delta X (X dot) that gets us there

Invert the Jacobian and solve for Delta X

XXJY )(

Page 44: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Invert Jacobian

We can invert non-singular square matrices

There is also a pseudo inverse that can be used if the matrix is not square

Inverting a 2x2 matrix is especially easy

Jacobian is non-singular when we can divide by (ad-bc)

a b

c d

⎝ ⎜

⎠ ⎟

1

(ad −bc)

d −b

−c a

⎝ ⎜

⎠ ⎟

⎝ ⎜

⎠ ⎟=

1

(ad −bc)

ad −bc ab − ab

dc − dc ad −bc

⎝ ⎜

⎠ ⎟=

1 0

0 1

⎝ ⎜

⎠ ⎟

Page 45: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Compute Jacobian

(x, y) = (a1 cosθ1 +(a2 cos(θ1 +θ2 ),a1 sinθ1 + a2 sin(θ1 +θ2 ))

∂x

∂θ1

∂x

∂θ2

∂y

∂θ1

∂y

∂θ2

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟=

a1 sinθ1 + a2 sin(θ1 +θ2 ) a2 sin(θ1 +θ2 )

−a1 cosθ1 − a2 cos(θ1 +θ2 ) −a2 cos(θ1 +θ2 )

⎝ ⎜

⎠ ⎟

Page 46: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

SingularitiesConsider the case when the angles are both 0

Linkage lies on x axis

Assume we wish to move endpoint towards origin

Small changes in either angle move us in y direction

Happens whenever linkage touches rim of workspace:

when θ2 = 0 or π Below, we have used θ2 = 0

Determinate is 0: cannot invert

Solution – Jiggle the linkage and try again

∂x

∂θ1

∂x

∂θ2

∂y

∂θ1

∂y

∂θ2

⎜ ⎜ ⎜ ⎜

⎟ ⎟ ⎟ ⎟=

a1 sinθ1 + a2 sinθ1 a2 sinθ1

−a1 cosθ1 − a2 cosθ1 −a2 cosθ1

⎝ ⎜

⎠ ⎟=

(a1 + a2 )sinθ1 a2 sinθ1

−(a1 + a2 )cosθ1 −a2 cosθ1

⎝ ⎜

⎠ ⎟

Page 47: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

47 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Hierarchical Models

Examine the limitations of linear modeling

Symbols and instances

Introduce hierarchical models

Articulated models

Robots

Introduce Tree and DAG models

Page 48: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

48 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Instance Transformation

Start with a prototype object (a symbol)

Each appearance of the object in the model is an instance

Must scale, orient, position

Defines instance transformation

Page 49: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

49 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Symbol-Instance Table

Can store a model by assigning a number to each symbol and storing the parameters for the instance transformation

Page 50: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

50 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Relationships in Car Model

Symbol-instance table does not show relationships between parts of model

Consider model of carChassis + 4 identical wheelsTwo symbols

Rate of forward motion determined by rotational speed of wheels

Page 51: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

51 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Structure Through Function Calls

car(speed){ chassis() wheel(right_front); wheel(left_front); wheel(right_rear); wheel(left_rear);}

Fails to show relationships wellLook at problem using a graph

Page 52: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

52 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree

Graph in which each node (except the root) has exactly one parent node

May have multiple children

Leaf or terminal node: no children

root node

leaf node

Page 53: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

53 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree Model of Car

Page 54: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

54 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Robot Arm

robot armparts in their own coodinate systems

Page 55: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

55 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Articulated Models

Robot arm is an example of an articulated model

Parts connected at joints

Can specify state of model by

giving all joint angles

Page 56: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

56 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Relationships in Robot Arm

Base rotates independentlySingle angle determines position

Lower arm attached to baseIts position depends on rotation of baseMust also translate relative to base and rotate about

connecting jointUpper arm attached to lower arm

Its position depends on both base and lower armMust translate relative to lower arm and rotate about joint

connecting to lower arm

Page 57: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

57 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Required MatricesRotation of base: Rb

Apply M = Rb to base

Translate lower arm relative to base: Tlu

Rotate lower arm around joint: Rlu

Apply M = Rb Tlu Rlu to lower arm

Translate upper arm relative to upper arm: Tuu

Rotate upper arm around joint: Ruu

Apply M = Rb Tlu Rlu Tuu Ruu to upper arm

Page 58: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

58 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree Model of Robot

Note code shows relationships between parts of model

Can change “look” of parts easily without altering relationships

Simple example of tree model

Want a general node structure for nodes

Page 59: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Angel Examples

59

Page 60: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Robot Arm

// Parameters controlling the size of the Robot's arm

var BASE_HEIGHT = 2.0;

var BASE_WIDTH = 5.0;

var LOWER_ARM_HEIGHT = 5.0;

var LOWER_ARM_WIDTH = 0.5;

var UPPER_ARM_HEIGHT = 5.0;

var UPPER_ARM_WIDTH = 0.5;

// Shader transformation matrices

var modelViewMatrix, projectionMatrix;

// Array of rotation angles (in degrees) for each rotation axis

var Base = 0;

var LowerArm = 1;

var UpperArm = 2;

var theta= [ 0, 0, 0];

var angle = 0;

Page 61: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Read Angles

document.getElementById("slider1").onchange = function()

{

theta[0] = event.srcElement.value;

};

document.getElementById("slider2").onchange = function()

{

theta[1] = event.srcElement.value;

};

document.getElementById("slider3").onchange = function()

{

theta[2] = event.srcElement.value;

};

Page 62: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Base

function base() {

var s = scale4(BASE_WIDTH, BASE_HEIGHT, BASE_WIDTH);

var instanceMatrix =

mult( translate( 0.0, 0.5 * BASE_HEIGHT, 0.0 ), s);

var t = mult(modelViewMatrix, instanceMatrix);

gl.uniformMatrix4fv(modelViewMatrixLoc, false,

flatten(t) );

gl.drawArrays( gl.TRIANGLES, 0, NumVertices );

}

Page 63: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Basefunction base() {

var s = scale4(BASE_WIDTH, BASE_HEIGHT, BASE_WIDTH);

var instanceMatrix =

mult( translate( 0.0, 0.5 * BASE_HEIGHT, 0.0 ), s);

var t = mult(modelViewMatrix, instanceMatrix);

gl.uniformMatrix4fv(modelViewMatrixLoc, false,

flatten(t) );

gl.drawArrays( gl.TRIANGLES, 0, NumVertices );

}

var render = function()

{

gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );

modelViewMatrix = rotate(theta[Base], 0, 1, 0 );

base();

// Rotate takes angle and axis

Page 64: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Lower Arm

function lowerArm() {

var s = scale4(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT,

LOWER_ARM_WIDTH);

var instanceMatrix = mult( translate( 0.0, 0.5 *

LOWER_ARM_HEIGHT, 0.0 ), s);

var t = mult(modelViewMatrix, instanceMatrix);

gl.uniformMatrix4fv( modelViewMatrixLoc, false,

flatten(t) );

gl.drawArrays( gl.TRIANGLES, 0, NumVertices );

}

Page 65: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Lower Armvar render = function() {

gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT );

modelViewMatrix = rotate(theta[Base], 0, 1, 0 );

base();

modelViewMatrix = mult(modelViewMatrix, translate(0.0, BASE_HEIGHT, 0.0));

modelViewMatrix = mult(modelViewMatrix, rotate(theta[LowerArm], 0, 0, 1 ));

lowerArm();

modelViewMatrix = mult(modelViewMatrix, translate(0.0, LOWER_ARM_HEIGHT, 0.0));

modelViewMatrix = mult(modelViewMatrix, rotate(theta[UpperArm], 0, 0, 1) );

upperArm();

requestAnimFrame(render);

}

Page 66: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

66 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Possible Node StructureCode for drawing part orpointer to drawing function

linked list of pointers to children

matrix relating node to parent

Page 67: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

67 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Generalizations

Need to deal with multiple children

How do we represent a more general tree?

How do we traverse such a data structure?

Animation

How to use dynamically?

Can we create and delete nodes during execution?

Page 68: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

68 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Objectives

Build a tree-structured model of a humanoid figure

Examine various traversal strategies

Build a generalized tree-model structure that is independent of the particular model

Page 69: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

69 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Humanoid Figure

Page 70: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

70 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree with Matrices

Page 71: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

71 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Display and Traversal

The position of the figure is determined by 11 joint angles (two for the head and one for each other part)

Display of the tree requires a graph traversal

Visit each node once

Display function at each node that describes the part associated with the node, applying the correct transformation matrix for position and orientation

Page 72: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

72 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Transformation Matrices

There are 10 relevant matrices

M positions and orients entire figure through the torso which is the root node

Mh positions head with respect to torso

Mlua, Mrua, Mlul, Mrul position arms and legs with respect to torso

Mlla, Mrla, Mlll, Mrll position lower parts of limbs with respect to corresponding upper limbs

Page 73: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

73 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Stack-based Traversal

Set model-view matrix to M and draw torso

Set model-view matrix to MMh and draw head

For left-upper arm need MMlua and so on

Rather than recomputing MMlua from scratch or using an inverse matrix, we can use the matrix stack to store M and other matrices as we traverse the tree

Page 74: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

74 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Traversal Code

figure() { glPushMatrix() torso(); glRotate3f(…); head(); glPopMatrix(); glPushMatrix(); glTranslate3f(…); glRotate3f(…); left_upper_arm(); glPopMatrix(); glPushMatrix();

save present model-view matrix

update model-view matrix for head

recover original model-view matrix

save it again

update model-view matrix for left upper arm

recover and save original model-view matrix again

rest of code

Page 75: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

75 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Analysis

The code describes a particular tree and a particular traversal strategy

Can we develop a more general approach?

Note that the sample code does not include state changes, such as changes to colors

May also want to use glPushAttrib and glPopAttrib to protect against unexpected state changes affecting later parts of the code

Page 76: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

76 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

General Tree Data Structure

Need a data structure to represent tree and an algorithm to traverse the tree

We will use a left-child right sibling structure

Uses linked lists

Each node in data structure is two pointers

Left: next node

Right: linked list of children

Page 77: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

77 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Left-Child Right-Sibling Tree

Page 78: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

78 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Sibling Tree

I cannot make sense of Angel's drawingHere is my version of this treeLeft pointer is to first childRight pointer is to siblingNode contents are not shown

Page 79: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

79 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree node Structure

At each node we need to store

Pointer to sibling

Pointer to child

Pointer to a function that draws the object represented by the node

Transformation:

Homogeneous coordinate matrix to multiply on the right of the current model-view matrix

Represents changes going from parent to node

Page 80: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

80 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Tree node Structure

At each node we need to store

Pointer to sibling

Pointer to child

Pointer to a function that draws the object represented by the node

Transformation:

Represents changes going from parent to node

var node = {

transform: transform,

render: render,

sibling: sibling,

child: child,

}

Page 81: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Setupvar torsoId = 0;

var headId = 1;

var head1Id = 1;

var head2Id = 10;

var leftUpperArmId = 2;

var leftLowerArmId = 3;

var rightUpperArmId = 4;

...

var torsoHeight = 5.0;

var torsoWidth = 1.0;

var upperArmHeight = 3.0;

var lowerArmHeight = 2.0;

var upperArmWidth = 0.5;

...

Page 82: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Setup Nodes

var numNodes = 10;

var numAngles = 11;

var angle = 0;

var theta = [0, 0, 0, 0, 0, 0, 180, 0, 180, 0, 0];

var numVertices = 24;

var stack = [];

var figure = [];

for( var i=0; i<numNodes; i++)

figure[i] = createNode(null, null, null, null);

Page 83: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Lower Armvar figure = [];

for( var i=0; i<numNodes; i++)

figure[i] = createNode(null, null, null, null);

...

function createNode(transform, render, sibling, child)

{

var node = {

transform: transform,

render: render,

sibling: sibling,

child: child,

}

return node;

}

Page 84: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Left Upper Arm

function initNodes(Id)

{

var m = mat4();

...

case leftUpperArmId:

m = translate(-(torsoWidth+upperArmWidth), 0.9*torsoHeight, 0.0);

m = mult(m, rotate(theta[leftUpperArmId], 1, 0, 0));

figure[leftUpperArmId] =

createNode( m, leftUpperArm, rightUpperArmId, leftLowerArmId);

break;

Page 85: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Left Upper Arm

function initNodes(Id)

{

var m = mat4();

...

case leftUpperArmId:

m = translate(-(torsoWidth+upperArmWidth), 0.9*torsoHeight, 0.0);

m = mult(m, rotate(theta[leftUpperArmId], 1, 0, 0));

figure[leftUpperArmId] =

createNode( m, leftUpperArm, rightUpperArmId, leftLowerArmId);

break;

// function createNode(transform, render, sibling, child)

Page 86: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Draw Lower Armfunction initNodes(Id)

case leftUpperArmId:

...

figure[leftUpperArmId] =

createNode( m, leftUpperArm, rightUpperArmId, leftLowerArmId);

break;

function leftUpperArm()

{

instanceMatrix = mult(modelViewMatrix, translate(0.0, 0.5 *

upperArmHeight, 0.0) );

instanceMatrix = mult(instanceMatrix, scale4(upperArmWidth,

upperArmHeight, upperArmWidth) );

gl.uniformMatrix4fv(modelViewMatrixLoc, false,

flatten(instanceMatrix));

for(var i =0; i<6; i++) gl.drawArrays(gl.TRIANGLE_FAN, 4*i, 4);

}

Page 87: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Traversefunction traverse(Id) {

if (Id == null)

return;

stack.push(modelViewMatrix);

modelViewMatrix =

mult(modelViewMatrix, figure[Id].transform);

figure[Id].render();

if (figure[Id].child != null)

traverse(figure[Id].child);

modelViewMatrix = stack.pop();

if (figure[Id].sibling != null)

traverse(figure[Id].sibling);

}

Page 88: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

Traversefunction traverse(Id) {

if (Id == null)

return;

// Draw me

stack.push(modelViewMatrix);

modelViewMatrix =

mult(modelViewMatrix, figure[Id].transform);

figure[Id].render();

// Draw any children

if (figure[Id].child != null)

traverse(figure[Id].child);

// Restore state and draw my siblings

modelViewMatrix = stack.pop();

if (figure[Id].sibling != null)

traverse(figure[Id].sibling);

}

Page 89: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

89 Angel: Interactive Computer Graphics 4E © Addison-Wesley

2005

Notes

We must save model-view matrix before multiplying it by node matrix Updated matrix applies to children of node but not to

siblings which contain their own matricesThe traversal program applies to any left-child right-sibling tree

The particular tree is encoded in the definition of the individual nodes

The order of traversal matters because of possible state changes in the functions

Checkout Scene Graphs

Page 90: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

90

KeyframesTo reduce the work of animating, define key frames

Two dimensional array: time vs angle

Each column has all the angles for one pose

Each row holds the angles for a single joint

As time advances, interpolate between key frames

Metadata might include

Time, so poses are not at fixed intervals

Table above – gaps differ

Movement between poses – linear? Slow in, slow out?

T = 0 1.5 2 3

θ1= 45 90 45 90

θ2= 0 15 30 45

θ3= 180 175 200 120

Page 91: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

91

Resources

John Lasseter , Principles of Traditional Animation Applied to 3D Computer Animation

Page 92: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

92

WeblinksThe photographer - Philip Glass

http://www.youtube.com/watch?v=G5Afodfj4t8

12 Principles of Animation

http://www.youtube.com/watch?NR=1&v=xqGL1ZLk3n8

Bouncing Ball

http://www.idleworm.com/how/anm/01b/bball.shtml

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

Follow through and overlapping action

http://www.youtube.com/watch?v=5V-QsiPiN_k

Rick Parent's Animation book

http://www.siggraph.org/education/materials/HyperGraph/animation/rick_parent/Outline.html

Flour Sack

http://www.youtube.com/watch?v=FbG3UCY-9Xw

Luxo Jr

http://www.youtube.com/watch?v=PvCWPZfK8pI

The Genesis effect, from The Wrath of Kahn

http://www.youtube.com/watch?v=NM1r37zIBOQ

Walk Cycle

http://www.angryanimator.com/word/2010/11/26/tutorial-2-walk-cycle/

http://www.angryanimator.com/tut/pic/002_walkcycle/wlk03.swf

Wall-E

http://www.youtube.com/watch?v=RgMkD4t9ZmQ

http://www.youtube.com/watch?v=ZisWjdjs-gM

Puma Robot

http://www.youtube.com/watch?v=aHV5oY7viBM

Page 93: 1 Animation Jeff Parker, 2013 Thanks to Prof. Okan Arikan, UT Austin Ed Angel, UNM

93

SumaryReview steps

Model

Scripting – how the models will move

Inverse Kinematics, Dynamic Modeling

Inbetweening to thread between steps in the script

Rendering

Image processing – post processing for effects

Animation is a huge industry

Computers are widely used

Goal is to remove the tedium, while preserving room for artistry