Physically Based Animation and Modeling CSE 3541 Matt Boggus.

32
Physically Based Animation and Modeling CSE 3541 Matt Boggus

Transcript of Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Page 1: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Physically Based Animation and Modeling

CSE 3541Matt Boggus

Page 2: 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

Page 3: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Mass and Momentum

vp m

• Associate a mass with an object. We assume that the mass is constant

• Define a vector quantity called momentum (p), which is the product of mass and velocity

mm '

Page 4: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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

txx

v

vv

a

'

'

0

vpp m'

Page 5: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Newton’s Second Law

• Newton’s Second Law says:

• 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)

ap

f mdt

d

Page 6: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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

• Every action has an equal and opposite reaction– Do we really want this for games and animation?

BAAB ff

Page 7: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Integration

Given acceleration, compute velocity & position by integrating over time

2

2

1'

'

/

atvtpp

tavv

mfa

maf

Page 8: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Physics review, equations for:Zero accelerationConstant acceleration

tvv

xx

tavv

mfa

maf

2

)'('

'

/

vave

v

m fa

a

v’

txx

00

0

0

v

vv

a

Constant accelerationNo acceleration

Page 9: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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 ]

Page 10: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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 [ ∑vectors scalar: m ]

endv = v + a * dt [vectors: endv, v, a scalar: dt]

x = x + [vectors: x, endv, v scalars: 2, dt]

v = endv [vectors: endv, v]

Page 11: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Comparison of methods

See spreadsheet example

Page 12: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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

Page 13: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Lots of small particles - local rules of behaviorCreate ‘emergent’ elementCommon rules for particle motion:

Do collide with the environmentDo not collide with other particles

Common rules for particle rendering:Do not cast shadows on other particlesMight cast shadows on environmentDo not reflect light - usually emit it

Particle Systems

Page 14: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Particle Example

source Particle’s birth: constrained and time with initial color and shading (also randomized)

Particle’s demise, based on constrained and randomized life span

Collides with environment but not other particles

Particle’s midlife with modified color and shading

Page 15: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Particle system implementation

Update Steps1. for each particle

1. if dead, reallocate and assign new attributes2. animate particle, modify attributes

2. render particles

Use constrained randomization to keep control of the simulation while adding interest to the visuals

Page 16: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Constrained randomization

particleX = x + random(-1,1)particleY = y + random(-1,1)

particleX = xparticleY = y

Page 17: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Particle (partial example in C#)class Particle {

Vector3 position; // Updates frame to frameVector3 velocity; // Updates frame to frameVector3 force; // Reset and recomputed each frameGameObject 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…

};

Page 18: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Particle emitter (partial example in C#)

using System.Collections.Generic;using System.Collections;

class ParticleEmitter {ArrayList Particles = new ArrayList();

public:void Update(deltaTime);

};

Page 19: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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();

}}

Page 20: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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));}

Page 21: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Deleting GameObjects

GameObject myParticle;

// …create, animate, etc. …

Destroy(myParticle); Note: this affects the associated GameObject; it does not delete the variable myParticle

Page 22: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Lab3

• Implement a particle system where each particle is a GameObject

• Restrictions– No RigidBodies– No Colliders– Minimal credit if you use these for lab3

Page 23: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Forces – gravity

221

d

mGmF

2

2

22

/8.9 smm

Fa

d

mGmF

radiusearth

earth

Page 24: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Forces

Nstst fkf Static friction

Nkk fkf Kinetic friction

rK

nvKf

vis

visvis

6 Viscosity

for small objectsNo turbulence

For sphere

Page 25: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

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:

• 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

evf acdaero

2

2

1 v

ve

Page 26: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Forces – spring-damper

)( restcurrents LLkF

springdrestcurrents VkLLkF )(

Hooke’s Law

Page 27: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Damping example

Animation from http://www.acs.psu.edu/drussell/Demos/SHO/damp.html

Page 28: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Spring-mass-damper system

f -f

Page 29: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Springs

• At rest length l, the force f is zero

• Points are located at r1 and r2

[scalar displacement]

[direction of displacement]

21

21

21

rr

rr

rr

e

lx

xef

Page 30: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Spring-mass system

V1

V2

V3

E12

E23E31

Example – Jello cube http://www.youtube.com/watch?v=b_8ci0ZW4vI

Page 31: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Spring mesh – properties for cloth

Each edge is a spring-damper

Angular springs connect every other mass point

Each vertex is a point mass

Global forces: gravity, wind

Diagonal springs for rigidity

Example http://www.youtube.com/watch?v=ib1vmRDs8Vw

Page 32: Physically Based Animation and Modeling CSE 3541 Matt Boggus.

Virtual springs – soft constraints