Physically Based Animation and Modeling CSE 35415541 Matt
Physically Based Animation and Modeling CSE 3541/5541 Matt Boggus
Overview • Newton’s three laws of physics • Formulas for updating kinematic values • Particle Systems • Common forces in physically based animation
Summary of Newton’s laws • Forces relate to acceleration – F = ma – With acceleration, integrate to update velocity and position • Clients will specify object masses and forces acting on the objects in the scene
Integration Given acceleration, compute velocity & position by integrating over time
Physics review, equations for: Zero acceleration Constant acceleration No acceleration Constant acceleration a 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)
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 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 vary “new” particles
Constrained randomization example 1 particle. X = x particle. Y = y particle. X = x + random(-1, 1) particle. Y = y + random(-1, 1)
Constrained randomization example 2 particle. X = x + random(-1, 1) particle. Y = y + random(-1, 1) if (sqrt( (particle. X-x)2 + (particle. Y-y)2 ) ) > 1, re-randomize
Particle (partial example) class Particle { Vector 3 velocity; Vector 3 force; Game. Object particle; // updates frame to frame // reset and recomputed each frame // updates frame to frame // holds position and mesh // other fields for mass, currentlife, maxlife, etc. public: void Update(float delta. Time); // numeric integration to // update velocity and position void Apply. Force(Vector 3 f) { force = force + f; } void Reset. Force() { force = Vector 3. zero; } // other methods for collision response, life increment, etc. };
Particle emitter (partial example) using System. Collections. Generic; using System. Collections; class Particle. Emitter : Mono. Behaviour { IList <Particle> Particles = new List<Particle>(); // construct particle objects in Start(); // move and collision test particles in Update(); };
Particle Emitter Update() only showing physics movement code Update(float delta. Time) { foreach (Particle p in Particles) { // sum up all forces acting on p // includes “always-on” forces like gravity // may include “one-shot” forces from events like collisions } foreach (Particle p in Particles){ p. Update(delta. Time); p. Reset. Force(); } }
Creating Game. Objects (reminder) for(int i = 0; i < number. Of. Asteroids; i++){ Game. Object a. Sphere = Game. Object. Create. Primitive(Primitive. Type. Sphere); a. Sphere. transform. parent = transform; a. Sphere. name = "sphere" + i. To. String(); a. Sphere. transform. position = new Vector 3(Random. Range(-10. 0 f, 10. 0 f), Random. Range(-10. 0 f, 10. 0 f)); a. Sphere. transform. local. Scale = new Vector 3(Random. Range(0. 0 f, 1. 0 f), Random. Range(0. 0 f, 1. 0 f)); }
Deleting Game. Objects (reminder) Game. Object my. Particle; // …create, animate, etc. … Destroy(my. Particle); Note: this affects the associated Game. Object; it does not delete the variable my. Particle
Lab 3 • Implement a particle system where each particle is a Game. Object – For added challenge, have each particle be a vertex in one deformable mesh • Restrictions – No Rigid. Bodies – No Colliders – Minimal credit if you use these for lab 3
Computing forces for games and animations • Types – Independent of other values • Gravity on earth – Dependent on current object properties • velocity – drag • position – spring force – Dependent on other objects • Penalty method collision response • Gravity in space
Forces – gravity
“Opposing” Forces Static friction Kinetic friction Viscosity for small objects No turbulence For sphere
“Opposing” Forces – made simple Force = -1 * velocity * scale typically, 0 < scale < 1
Forces – spring-damper Hooke’s Law
Damping example Animation from http: //www. acs. psu. edu/drussell/Demos/SHO/damp. html
Spring-mass-damper system f -f
Spring-mass-damper system • At rest length l, the force f is zero • Two objects are located at r 1 and r 2 [scalar displacement] [direction of displacement]
Spring-mass system V 3 E 23 E 31 V 1 E 12 V 2 Example – Jello cube http: //www. youtube. com/watch? v=b_8 ci 0 ZW 4 v. I
Penalty method Spring force as collision response
ADDITIONAL SLIDES
Mass and Momentum • 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
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
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)
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?
“Opposing” Forces – can be complex • 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
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
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=ib 1 vm. RDs 8 Vw
Cloth simulation – springs, integration, and stability • Cloth Sim with Euler Integrator https: //www. youtube. com/watch? v=fm. Pqv. Qg 8 MKo • Animation begins using Verlet integration • Animation ends using Euler integration
- Slides: 38