four five physics simulators for a human body chris hecker definition six, inc. [email protected]

28
Four Five Physics Four Five Physics Simulators for a Human Simulators for a Human Body Body Chris Hecker definition six, inc. [email protected]

Upload: seth-kent

Post on 27-Mar-2015

220 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Five Physics Simulators for Four Five Physics Simulators for a Human Bodya Human Body

Chris Heckerdefinition six, [email protected]

Page 2: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four^H^H^Hive Physics Four^H^H^Hive Physics Simulators for a Human BodySimulators for a Human Body

Chris Heckerdefinition six, [email protected]

Page 3: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

PrerequisitesPrerequisites

• comfortable with math concepts, modeling, and equations

• kinematics vs. dynamics

• familiar with rigid body dynamics

• probably have written a physics simulator for a game, or at least read about it in detail

Page 4: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

TakeawayTakeaway

• pros and cons & subtleties of 4 different simulation techniques– all are useful, but different strengths

• 2 key concepts:– degrees of freedom, configuration space, etc.– stiffness, and why it is important

• all examples are 2D, but generalize directly to 3D

• not going to be detailed tutorial

Page 5: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

A Couple Other Related TalksA Couple Other Related Talks

• David Wu’s talk on mixing kinematics & dynamics

• Saturday, 2:30pm - 3:30pm

• Experimental Gameplay Workshop• Friday, 4:30pm - 6:30pm

Page 6: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Before Physics I Tried...Before Physics I Tried...

• Cyclic Coordinate Descent IK demo– my rock climbing game

• works okay, but problems:– non-physical movement– no closed loops– no clear path to adding muscle controls

Page 7: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Physics “Solutions”Physics “Solutions”

• rigid bodies with constraints• need to simulate enough to make articulated figure

• 1st-order dynamics• f = mv• no inertia/momentum; no force, no movement

• mouse attached by spring or constraint• must be tight control

• hands/feet attached by springs or constraints• must stay locked to the positions

Page 8: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

I Tried Four TechniquesI Tried Four Techniques

• Augmented Coordinates / Explicit Integration• Lagrange Multipliers

• Augmented Coordinates / Implicit Integration• Implicit Springs

• Generalized Coordinates / Explicit Integration• Composite Rigid Body Method

• Generalized Coordinates / Implicit Integration• Implicit Recursive Newton Euler

• demo of all four running at once

Page 9: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Obvious Axes of the TechniquesObvious Axes of the Techniques

• Augmented vs. Generalized Coordinates– ways of representing the degrees-of-freedom

(DOF) of the systems

• Explicit vs. Implicit Integration– ways of stepping those DOFs forward in time

Page 10: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Augmented CoordinatesAugmented Coordinates

• aka. Lagrange Multipliers, constraint methods

• calculate constraint forces and apply them

• simulate each body independently• constraint forces keep bodies together

6DOF - 2DOF = 4DOF

f

Page 11: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Generalized CoordinatesGeneralized Coordinates

• aka. reduced coordinates, embedded methods, recursive methods

• calculate and simulate only the real DOF of the system

• one rigid body and joints

3DOF + 1DOF = 4DOF

Page 12: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Degrees Of Freedom (DOF)Degrees Of Freedom (DOF)

• DOF is a critical concept in all math• find the DOF to understand the system

• “coordinates necessary and sufficient to reach every valid state”

• examples:• point in 2D: 2DOF, point in 3D: 3DOF

• 2D rigid body: 3DOF, 3D rigid body: 6DOF

• point on a line: 1DOF, point on a plane: 2DOF

• simple desk lamp: 3DOF (or 5DOF counting head)

Page 13: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

DOF ContinuedDOF Continued

• systems have DOF, equations on those DOF constrain them

• example, 2D point, on line

• “configuration space” is the space ofthe DOF

• “manifold” is the c-space, usuallyviewed as embedded in theoriginal space

(x,y)

x = 2y

(x,y) = (t,2t)

Page 14: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Augmented vs. Generalized Augmented vs. Generalized Coordinates, RevisitedCoordinates, Revisited

• augmented coordinates: dynamics equations + constraint equations

• general, modular, plug’n’play, breakable

• big (often sparse) linear systems

• simulating useless DOF

• generalized coordinates:dynamics equations

• complicated, custom coded

• small dense nonlinear systems

• no closed loops, no nonholonomic constraints

Page 15: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

StiffnessStiffness

• fast-changing systems are stiff

• the real world is incredibly stiff• “rigid body” is a simplification to avoid stiffness

• most game UIs are incredibly stiff• the mouse is insanely stiff, IK demo

• kinematically animating objects can be arbitrarily stiff

• animating the position with no derivative constraints

Page 16: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Handling StiffnessHandling Stiffness

• You want to handle as much stiffness as you can!

• gives designers control

• can always make things softer, that’s easy

• it’s very hard to handle

• explicit integrator will not handle stiff systems without tiny timestep

• that’s almost a definition of numerical stiffness! :)

Page 17: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Stiffness ExampleStiffness Example

• example: exponential decay

• demo of increasing spring constantdy/dx = -y dy/dx = -10y

Page 18: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Explicit vs. Implicit IntegratorsExplicit vs. Implicit Integrators

• explicit jumps forward to next position• blindly leap based on current information

• implicit jumps back from next position• find a next position that points to current

Page 19: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Simulators In More DetailFour Simulators In More Detail

• Augmented Coordinates / Explicit Integration• Lagrange Multipliers

• Augmented Coordinates / Implicit Integration• Implicit Springs

• Generalized Coordinates / Explicit Integration• Composite Rigid Body Method

• Generalized Coordinates / Implicit Integration• Implicit Recursive Newton Euler• spend a few slides on this technique• best for game humans?

Page 20: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Simulators In More DetailFour Simulators In More Detail Augmented / Explicit Augmented / Explicit

Lagrange MultipliersLagrange Multipliers• form dynamics equations for bodies• form constraint equations• solve for constraint forces• apply forces to bodies• integrate bodies forward in time

• RK explicit integrator

• pros: simple, modular, general• cons: medium sized matrices, drift, nonstiff

• references: Baraff, Shabana, Barzel & Barr, my ponytail articles

Page 21: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Simulators In More DetailFour Simulators In More Detail Augmented / Implicit Augmented / Implicit

Implicit SpringsImplicit Springs

• form dynamics equations• write constraints as stiff springs• use implicit integrator to solve for next state

• Shampine’s ode23s adaptive timestep, or semi-implicit Euler

• pros: simple, modular, general, stiff• cons: inexact, big matrices, needs derivatives

references: Baraff (cloth), Kass, Lander

Page 22: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Simulators In More DetailFour Simulators In More Detail Generalized / Explicit Generalized / Explicit

Composite Rigid Body MethodComposite Rigid Body Method

• form tree structured augmented system• traverse tree computing dynamics on generalized

coordinates incrementally• outward and inward iterations

• integrate state forward• RK

• pros: small matrices, explicit joints• cons: dense, nonstiff, not modular

• references: Featherstone, Mirtich, Balafoutis

Page 23: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Four Simulators In More DetailFour Simulators In More Detail Generalized / Implicit Generalized / Implicit

Implicit Recursive Newton EulerImplicit Recursive Newton Euler

• form generalized coordinate dynamics• differentiate for implicit integrator

• fully implicit Euler

• solve system for new state• pros: small matrices, explicit joints, stiff• cons: dense, not modular, needs derivatives

• references: Wu, Featherstone

Page 24: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Generalized / ImplicitGeneralized / Implicit

Some DerivationSome Derivation• f = fjoints + fext = mv• Forward Dynamics Algorithm

• given joint forces, compute velocities (accelerations)• v = (fjoints + fext)/m

• Inverse Dynamics Algorithm• given velocities (accelerations), compute joint forces• fjoints = mv - fext

• you can use an IDA to check for equilibrium given a velocity

• if fjoints = 0, then the current velocity balances the external forces, or f - mv = 0 (which is just a rewrite of “f = mv”)

Page 25: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Generalized / ImplicitGeneralized / Implicit

Some Derivation (cont.)Some Derivation (cont.)• IDA gives F(q,q’)

• when F(q,q’) = 0, then system is moving correctly• we want F(q1, q1’) = 0, the solution at the new time

• implicit Euler equation: q1 = q0 + h q1’• q1 = q0 + h q1’ ... q1’ = (q1 - q0) / h

• plug’n’chug: F(q0 + h q1’, q1’) = 0• this is a function in q1’, because q0 is known

• we can use a nonlinear equation solver to solve F for q1’, then use this to step forward with implicit Euler

Page 26: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

Problem: Solving F(qProblem: Solving F(q11’) = 0 can be hard!’) = 0 can be hard!(but it’s very well documented)(but it’s very well documented)

• open problem • solve vs. minimize?

Page 27: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

The 5th SimulatorThe 5th Simulator• Current best:

• implicit Euler with F(q’) = 0 Newton solve• lots of wacky subdivision and searching to help find solutions

– want to avoid adaptivity, but can’t in reality

• doesn’t always work, finds no solution, bails

• Idea:• the ode23s adaptive integrator will find the answer, but

slowly• the Newton solve sometimes cannot find the answer, no

matter how slowly because it lacks info• spend time optimizing the ode23s, because at least it has

more information to go on

Page 28: Four Five Physics Simulators for a Human Body Chris Hecker definition six, inc. checker@d6.com

SummarySummary

• simulating an articulated rigid body is hard, and there are a lot of tradeoffs and subtleties

• there is no single perfect algorithm• yet?

• stiffness is very important to handle for most games

• generalized coordinates with implicit integration is the best bet so far for run-time

• maybe augmented explicit (?) for author-time tools

• I’ll put the slides on my page at d6.com