91
The Physics That Brought Cel Damage to Life: A Case Study David Wu, Director of Technology, Pseudo Interactive Inc. GDC 2002

The Physics That Brought Cel Damage to Life: A Case Study

Embed Size (px)

DESCRIPTION

The Physics That Brought Cel Damage to Life: A Case Study. David Wu, Director of Technology, Pseudo Interactive Inc. GDC 2002. Introduction. When I first starting programming Game Physics I had certain beliefs: If I am not careful people will steal my great ideas Programming is a battle - PowerPoint PPT Presentation

Citation preview

Page 1: The Physics That Brought Cel Damage to Life:  A Case Study

The Physics That BroughtCel Damage to Life: A Case Study

David Wu, Director of Technology, Pseudo Interactive Inc.

GDC 2002

Page 2: The Physics That Brought Cel Damage to Life:  A Case Study

Introduction

When I first starting programming Game Physics I had certain beliefs:

• If I am not careful people will steal my great ideas

• Programming is a battle• Developer Vs Developer• Whomever has the best physics

code wins

Page 3: The Physics That Brought Cel Damage to Life:  A Case Study

Introduction (cont)

Since then I have learned: My great ideas are not that great Programming is a battle

Developer Vs Physics Physics usually wins

Page 4: The Physics That Brought Cel Damage to Life:  A Case Study

Introduction (cont)

Without furtur ado - the goals of this lecture:

To Share with you our not so great ideas

To help build the numerical arsenal of programmers around the world in hopes that one day we will win.

Page 5: The Physics That Brought Cel Damage to Life:  A Case Study

Motivation

Together we will move mountains…We will conserve momentum!We will make great Games!We will show the world that physics can be fun!And if all goes well - our integrators will not explode!

Page 6: The Physics That Brought Cel Damage to Life:  A Case Study

Motivation (cont)

Are you motivated yet?

Page 7: The Physics That Brought Cel Damage to Life:  A Case Study

Motivation (cont)

Now go and motivate your producer

- Convince her that Physics will make a better game

- You will Sell More units

- Programmers will think that you are cool

Page 8: The Physics That Brought Cel Damage to Life:  A Case Study

P.I.T.A

“Pseudo Interactive Technology Arsenal”Programmers like to name their enginesNo one else cares. That doesn’t stop us.

Page 9: The Physics That Brought Cel Damage to Life:  A Case Study

The PITA Pipeline

-Collect Input-Collision Detection-Logic and AI-Integration-Render+Network Output-Rinse, Lather and repeat

Easy as PI

Page 10: The Physics That Brought Cel Damage to Life:  A Case Study

The PITA Pipeline

Their are two key opponents that you must defeat to build a successful physics system.Once you have them nailed, you’ve won 96% of the battle.These opponents are: Numerical Integration Degrees of Freedom

This battle is the focus of my lecture

Page 11: The Physics That Brought Cel Damage to Life:  A Case Study

DOFIts all about “DOF”

aka “Degrees of Freedom”

Game entities are described in terms of their DOFThe Rendering Engine draws DOF wraped in tri-stripsThe Network system sends DOF to your friends and enemys.The Integrator changes the DOF over timeThe Collision detection system determines incompatible DOFAI attempt to control DOFDOF make the world go aroundDOF make your game fun!

Page 12: The Physics That Brought Cel Damage to Life:  A Case Study

DOF Example

Sheep

Page 13: The Physics That Brought Cel Damage to Life:  A Case Study

DOF Example

Constraint Model

6 DOF Rigid bodies joined by constraints

24 DOF -9 DOF in

Constraints

-3DOF

-3DOF

-3DOF

6DOF

6DOF

6DOF6DOF

Page 14: The Physics That Brought Cel Damage to Life:  A Case Study

DOF Example

Independent coordinatesEach part described by a minimal DOF representation

i.e. Euler Angles

15 DOFNo Contstraints

3DOF

3DOF

3DOF

6DOF

Page 15: The Physics That Brought Cel Damage to Life:  A Case Study

DOF Example

Natural Cartesian Coordinates DOF are described by N points in

space connected by constraints Mostly –1 DOF rod constraints 39 DOF -24 DOF of contstraints No Angular anything

q0

q0’q1

q1’

Page 16: The Physics That Brought Cel Damage to Life:  A Case Study

Numerical Integration

The main weapon in pita’s numerical arsenal

With a good integrator you can accomplish anything.

Implicit Euler is like a Nuclear Missile: sloppy sometimes overkill robust effective handles everything

that you throw at it

Page 17: The Physics That Brought Cel Damage to Life:  A Case Study

The Process:

1. All DOF are collected into a global state vector Q and its derivative Q’

Q is positiion Q’ is velocity

2. All external influences are collected as potentials forces, springs, constraints, contacts give rise to a force vector F

3. Boom! the integrator does it’s stuff

4. You are left with new Q and Q’ vectors. Qt1, Qt1’

ConstraintsForcesContactsPotentialsActuatorsQt0

Qt0’

BOOM!(integration)

Qt1

Qt1’

Page 18: The Physics That Brought Cel Damage to Life:  A Case Study

The Pita Paradigm

To formulate the problem of dynamics simulation in such a way that it might be solved in real time. pita requires that a few Axioms be accepted on Faith alone.

These axioms serve as the foundation for the Implicit Euler Integration Scheme.

Page 19: The Physics That Brought Cel Damage to Life:  A Case Study

Axiom #2

Time is Discrete The sampling resolution is 30hz

i.e. t0,t1,t2 are instances in time each instance is separated by 1/30 seconds

Europeans are a little slower, at 25hz

Page 20: The Physics That Brought Cel Damage to Life:  A Case Study

Axiom #3:Acceleration occurs during short impulses Like a Dirac Delta Function. You have you state vector at time t0: Qt0, Qt0’ Bang Q’’ occurs, Q’ jumps by Q’’*dt;

Q’ is then constant throughout the time step Q is piecewise linear Qt1’ = Qt0’ + Q’’*dt

Qt1 = Qt0 + Qt0’*dt + Q’’*dt2

Not Qt1 = Qt0 + Qt0’*dt + ½*Q’’*dt2

Page 21: The Physics That Brought Cel Damage to Life:  A Case Study

Axiom #4

The Acceleration at time t0 satisfies Newton’s second law at time t1

Ft1 = Mt1*Q’’

Mt1*Q’’ – Ft1 = 0 like F=MA but better

Page 22: The Physics That Brought Cel Damage to Life:  A Case Study

The Equations of Motion

We can think of the implicit Euler equations as constraint equations acting on our DOF.

At first you might think: Constraint Equations? Those are the bad guys right?

Constraint Equations are like mercenaries, sometimes you have to fight them, sometimes you can use them to eliminate your opponents.

In our case we will use them against our foes, we will use them to eliminate some redundant DOF, namely acceleration (Q’’)

Page 23: The Physics That Brought Cel Damage to Life:  A Case Study

The Equations of Motion

The equations of motion then become: Mt1*Qt1’ – Mt0*Qt0’ – Ft1*dt = 0

Looks like conservation of momentum: MVt1 = MVt0 + integral(F)dt

Now that we’ve eliminated acceleration and we know that Qt1 = Qt0 + Qt1’*dt

we can focus our efforts on computing Qt1’

the velocities at the next time step

Page 24: The Physics That Brought Cel Damage to Life:  A Case Study

The Sheep

Now we are ready to model the dynamics of the Sheep.

We will use natural cartesian coordinates.

Q is a vector of 13 3d points q0,q1,q2 .. q11 36 DOF

Q’ is a vector of 13 3d velocities q0’,q1’,q2’ .. q11’

q0

q0’q1

q1’

Page 25: The Physics That Brought Cel Damage to Life:  A Case Study

The Plan of attack

Guess what Qt1’ might be Determine what Qt1 would be for this Qt1’:

Qt1 = Qt0 + Q’t0*dt Each point of the Sheep is moved using

its candidate velocity Compute the inverse dynamics term:

Mt1*Qt1’- Mt0*Qt0’ Compute the sheep’s new momentum

and subtract its previous momentum

Page 26: The Physics That Brought Cel Damage to Life:  A Case Study

The Plan of attack (cont)

Compute the external forces resulting from this new state vector, Ft1

Loop through the Rods holding the Sheep together, compute their forces

Apply gravity Apply contacts and other forces Determine the error, or Residual:

R(Qt1) = Mt1*Qt1’- Mt0*Qt0’ – Ft1*dt If R(Qt1) == 0

Qt1’ is valid for this time step we are done!

If not, take another guess for Qt1’ and try again.

Page 27: The Physics That Brought Cel Damage to Life:  A Case Study

Will it Work?

You might be thinking: “This plan sounds a little Dodgy”

or “I am not convinced that the Tinker Toy

Sheep model is an accurate representation of a real two legged sheep”

I claim that this method is theoretically sound and will produce correct Dynamics for a system governed by the previously stated Axioms.

Page 28: The Physics That Brought Cel Damage to Life:  A Case Study

Three Key Concepts: Kinematics

Steps Qt0 to Qt1

Defines the relationship between Q and the Sheep Inertia

Defines the relationship between forces and accelerations Integrate w.r.t. time and you have the relationship

between momemtum and impulses Potentials

Potentials are anything that might give rise to external forces

Gravity, constraints, collisions, contacts, actuators, etc. All potentials must be able to determine their force vector

for a given Sheep Configuration at a given time.

Page 29: The Physics That Brought Cel Damage to Life:  A Case Study

The DOF Interface This framework is

general in that it can handle any selection of DOF

In Cel Damage we use a number of different DOF representations, the only code required by each is Kinematics, Inertia and Potentials.

Interface IDof-Kinematics-Inertia-Potentials

Particles

Rigid Bodies

Articulated Figures

Finite Elements

Page 30: The Physics That Brought Cel Damage to Life:  A Case Study

Kinematics: Kinematics relates the Sheep’s

DOF to it’s body. For any selection of DOF there are unique Kinematic equations relating any point on the Sheep to some function of the DOF

The sheep has 4 Rigid parts head body, leg0, leg1

Each part has four points embedded in it, which describe its DOF

The points uniquely define position, orientation, velocity and angular velocity of each part.

q0

q0’q1

q1’

Page 31: The Physics That Brought Cel Damage to Life:  A Case Study

Kinematics: The Center of Mass of the head is at a position

defined by a linear combination of the points q0,q1,q2,q3; C = 0.4*q0 + 0.1*q1 + 0.2*q2+ 0.3*q3

Similarly, the velocity of the head’s center of mass is: V = 0.4*q0’ + 0.1*q1’ + 0.2*q2’ + 0.3*q3’ The numbers (0.4, 0.1, 0.2,0.3) are the barycentric

coordinates of the head’s center of mass. This transform can be referred to as the Jacobian J:

[0.4 0 0 0.1 0 0 0.2 0 0 0.3 0 0 ] [ 0 0.4 0 0 0.1 0 0 0.2 0 0 0.3 0 ] [ 0 0 0.4 0 0 0.1 0 0 0.2 0 0 0.3 ] Vhead = J*Q’

Page 32: The Physics That Brought Cel Damage to Life:  A Case Study

Kinematics:

This transform can be referred to as the Jacobian J: [0.4 0 0 0.1 0 0 0.2 0 0 0.3 0

0 ] [ 0 0.4 0 0 0.1 0 0 0.2 0 0 0.3

0 ] [ 0 0 0.4 0 0 0.1 0 0 0.2 0 0 0.3

] And the velocity mapping is:

Vhead = J*Q’

Page 33: The Physics That Brought Cel Damage to Life:  A Case Study

Inertia

The Inertia of the Sheep is a 36x36 sparse tensor “M”.

The tensor of Inertia can be derived by analytic integration within the volume of the sheep.

Conceptually, At each point in the sheep you take the infinitesimal bit of volume, multiply it by the Sheep’s density at that point in space, and project it onto the DOF that move the point, weighted by a Jacobian.

J*m*Jt

Page 34: The Physics That Brought Cel Damage to Life:  A Case Study

Inertia

You can think of this as scattering little bits of mass across the Sheep’s DOF, or spray painting the Tensor M.

Computation of the Inertia Tensor may take a fair bit of processing, but the Inertia Tensor for this selection of DOF is constant. The alternative DOF representations of the Sheep mentioned earlier vary with the state vector Q and must be updated or recomputed whenever Q changes.

Page 35: The Physics That Brought Cel Damage to Life:  A Case Study

Constraints

Each rod constraint maintains a fixed distance between two points:

|q1 – q0| - L = 0 We approximate this using a very stiff linear

springs. Its potential energy is: ½ k*(|q1 – q0| - L)^2 K is very large. Doing a little differentiation we get the Force

Applied: f0 = (q1-q0)/|q1-q0| *k* (L - |q1-q0| ) f1 is –f0 This is a non-linear function dependant on (Q)

Page 36: The Physics That Brought Cel Damage to Life:  A Case Study

Constraints

If someone asks you what you are doing, don’t admit that you are using penalty methods.

Tell them that it’s Quadratic Programming – you are using an interior point method.

While she ponders this claim, switch topics. Talk about just how much designers enjoy

over-determined systems, and how Lagrange Multipliers perform in these situations.

Page 37: The Physics That Brought Cel Damage to Life:  A Case Study

Solving:

As it turns out, random guessing is not the fastest way to find a valid Q t1’.

More sophisticated techniques such as the Conjugate Gradient Method or Newton’s Method are usually a better choice.

If we do a little hand waving we can repose our Qt1’ guessing as a Mathematical Optimization problem. The Mathematical Optimization people have come up with all sorts of neat ways to minimize scalar functions, we will exploit their research to help fight the battle.

Page 38: The Physics That Brought Cel Damage to Life:  A Case Study

Solving:

The Residual R(Qt1’) is Disguised to look like a Scalar function: ½ R(Qt1’)t* R(Qt1’)

This function is minimized when it’s gradient is 0 Mt1*Qt1’- Mt0*Qt0’ – Ft1*dt ==0

We can trick the optimizer into finding a valid Qt1’ for which R(Qt1’) == 0

The solution to the forward dynamics equations!

Page 39: The Physics That Brought Cel Damage to Life:  A Case Study

Jacobi Iterations:

The essential concept is to “divide and conquer”.

We know how to solve one point in isolation, so we just ignore the system coupling and solve each point independently.

Here is our Jacobi plan to take on the sheep: Split up Squadron #0 takes on the first point of the rear leg Squadron #1 takes on the second point of the body Squadron #2 takes on the first point of the head etc.

Page 40: The Physics That Brought Cel Damage to Life:  A Case Study

Jacobi Iterations:

Many people start with Jacobi iteration, even if they don’t know what Jacobi iteration is.

It is intuitive and often faster than random Guessing

Jacobi is a nice way to prototype systems, it is easy to implement, it parallelizes well, and it requires little memory for high DOF systems.

From a practical standpoint Jacobi iterations are a good way to pre-condition your system for the Conjugate Gradient Method, but not suitable as a general solver for real-time dynamic simulation in most games.

Page 41: The Physics That Brought Cel Damage to Life:  A Case Study

Gauss Seidel

A variant on Jacobi iterations, adds some communication between squadrons. Squad #0 tells Squad #1 it’s results.

Sometimes This helps to prevent some of the ping-

pong stale mates seen with Jacobi Iteration.

Page 42: The Physics That Brought Cel Damage to Life:  A Case Study

Successive Over Relaxation

If you are dead set on using a Jacobi or Gauss Seidel you should look into the literature on SOR

SOR is a variant that is finicky but effective for certain problems

Page 43: The Physics That Brought Cel Damage to Life:  A Case Study

Steepest Descent

A problem with the Jacobi method is that when you solve one batch of DOF, other DOF become unsolved. I.e.

While you attempt to eliminate the residual for p1’s DOF p0 re-spawns.

First you eliminate the residual for p0 Steepest Descent is like Jacobi iteration without

the divide and conquer part. We attack all of the DOF at once. To find a better Q’ we pick a search direction: S,

and walk in this direction until we reach the point where the residual is minimal.

Page 44: The Physics That Brought Cel Damage to Life:  A Case Study

Steepest Descent To find a better Q’ we pick a search direction:

S, and walk in this direction until we reach the point where the residual is minimal.

find the scalar ‘p’ that minimizes:

R(Q’ + p*S)t*R(Q’ + p*S) for the search direction Sp is the distance along S that you walk.

Page 45: The Physics That Brought Cel Damage to Life:  A Case Study

Steepest Descent

Using this strategy we can keep tabs on all DOF at once hopefully, no one will respawn when we are not

watching. The search direction that we choose is

simply the residual: R(Qt1’) = Mt1*Qt1’ – Mt0*Qt0’ - Ft1

The following example illustrates the choice we have made for the residual:

The sheep’s ear is being pulled with a force (1, 0, 0), but is momentum has changed by (0,1,0), we will search in a direction that should move the momentum towards 1,0,0, namely (1,-1,0) which is the residual.

Page 46: The Physics That Brought Cel Damage to Life:  A Case Study

Steepest Descent

The following example illustrates the choice we have made for the residual: The sheep’s ear is being pulled with

a force (1, 0, 0) its momentum has changed by

(0,1,0) we will search in a direction that

should move the momentum towards 1,0,0

namely (1,-1,0) which is the residual.

Page 47: The Physics That Brought Cel Damage to Life:  A Case Study

The Conjugate Gradient Method

The conjugate Gradient method uses information from previous search directions to help guide the selection of future search directions

The second search direction is chosen such that it does not step on the toes of the first search

Page 48: The Physics That Brought Cel Damage to Life:  A Case Study

The Conjugate Gradient Method

If your system is quadratic, the sequence of residuals resulting from each step are mutually conjugate with respect to the Hessian of the quadratic

In practice the equations of motion resemble quadratics near the solution

This is the method that I used for Cel Damage Xbox

Page 49: The Physics That Brought Cel Damage to Life:  A Case Study

Newton’s Method

If the system resembles a quadratic, why not just pick a search direction that will solve the quadratic in one step?

This is the rationale behind newtons method

Page 50: The Physics That Brought Cel Damage to Life:  A Case Study

Newton’s Method

We can approximate the residual: R(Qt1’) = Mt1*Qt0’ – Mt1*Qt1’- Ft1

With a first order power series: R(Qt1’) ~= R(Qt0’) + d/dQ’R(Qt0’)*(Qt1’ – Qt0’)

This is a linear system that can be solved using standard techniques (LDL, LU, Gaussian elimination, etc) to find Q’t1.

We can then use Qt1’ – Qt0’ as our search direction.

The matrix d/dQ’R(Qt0’) is called the Hessian.

Page 51: The Physics That Brought Cel Damage to Life:  A Case Study

The Hessian

If the dynamics of our Sheep were linear, the Hessian would be constant and we could eliminate the Residual in just one step, as shown in the previous diagram.

Due to our crafty selection of DOF, the sheep’s dynamics are almost linear. The Sheep’s Inertia Matrix is constant, but the rod constraints are somewhat non-linear.

The Hessian for the Sheep takes the form: M + d/dQ’F*dt

Page 52: The Physics That Brought Cel Damage to Life:  A Case Study

The Hessian

You might think of the Hessian as the systems Inertia

The rods connecting the sheeps DOF make each DOF “heavier”

If the Sheep were in contact to the world, the resulting contact would add terms to the hessian, making the sheep apear very heavy to a force trying to push it downward

Page 53: The Physics That Brought Cel Damage to Life:  A Case Study

The Hessian

If you are smart you can derive the Hessian analytically using your intrinsic analytic calculus arsenal. Chris Hecker does this.

If you are not smart like me, or your derivations tend to produce equations that are non deterministic you should investigate Automatic Differentiation If you are new to Automatic Differentiation I would

recommend that you look at ADOL-C, it’s page is here:

http://www.math.tu-dresden.de/wir/project/adolc/index.html

Page 54: The Physics That Brought Cel Damage to Life:  A Case Study

Discrete Newton

In practice, people have difficulty building the Hessian. This is such a common problem that people have come up with a family of variants on Newton’s method that do not require explicit derivation of the Hessian, known as Discrete Newton Methods.

These methods employ finite differences to approximate the Hessian.

Despite their many short-comings, the Discrete Newton methods are often used to solve real world problems, their popularity stems from the fact that they are easy to implement.

Page 55: The Physics That Brought Cel Damage to Life:  A Case Study

Quasi Newton (QN)

Yet another way to approximate the full Newton Method without the Hessian, Quasi Newton Methods operate in a manner similar to the Conjugate Gradient Method. QN builds an approximation of the Hessian (or the inverse Hessian) as it searches.

Page 56: The Physics That Brought Cel Damage to Life:  A Case Study

Truncated Newton

In addition to all of those derivatives, Newton’s method requires that you store the Hessian

O(N2) space you factor it

O(N3) time If you have many DOF, this can be a real problem. The strategy employed by the Truncated Newton

methods is to “almost but not quite” create and factor the Hessian, and then use the resulting approximate solution as your the search vector.

This is the methods that I used for Cel Damage GameCube.

Page 57: The Physics That Brought Cel Damage to Life:  A Case Study

The Cel Damage Solver

1. Given the current guess (Q’) Use Automatic Differentiation to compute a procedural

representation of the hessian This linearalize the system’s dynamics at the state

defined by the kinematics at the system at the guess Q’

2. I use the Linear Predconditioned Conjuigate Gradient Method to “almost” solve the resulting system the total number of iterations is caped to 6 + 2*sqrt(N)

constants derived via an add hoc empirically based heuristic

3. This solution is handed off to the Newton Solver who performs a non-linear line search through the DOF in an effort to minimize the Residual.

Page 58: The Physics That Brought Cel Damage to Life:  A Case Study

Which Method is Best?

Through the development of Cel Damage I tried each of these techniques.

The most efficient method for the problems encountered in Cartoon Vehicular Combat games turned out to be the Truncated Newton Method.

Truncated Newton may not be the best solution for your game, but this little bit of empirical evidence might help to save you time when you implement your solver.

Page 59: The Physics That Brought Cel Damage to Life:  A Case Study

Elasticity

Elastic potential energy is represented using the constitutive law of a Saint-Venant-Kirchho materialE(F) = ½(tr(D))2 + µtr(D2)Where F is the deformation

gradient and µ are Lame constants D = ½(FtF-1)

Page 60: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection

So many Algorithms, so little time.Collision detection is usually broken up into two parts: Coarse Grain “Pruning” or “Culling” Fine Grain intersection detection

For Coarse Grain we use K-Dops(1)

For Fine Grain collision detection we use G.J.K. (2) (Gilbert-Johnson-Keerthi)

Page 61: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Representation

PITA represents physical entities as convex hulls whose verts are embedded in DOFConvex Hulls are spatially grouped together and wraped in KDOP’s (K-Dimensional Discrete Oriented Polytopes)KDOPS are wraped in yet more Kdops to form binary trees.

One KDOP tree for dynamic hulls One KDOP tree for static Hulls One KDOP tree for Hulls whose DOF are sleeping

Page 62: The Physics That Brought Cel Damage to Life:  A Case Study

KDOP’s

Leaves of a Kdop Tree

Page 63: The Physics That Brought Cel Damage to Life:  A Case Study

KDOP’s

The KDOP trees are used coarse grain collision detection pruning.The Majority of the O(N^2) possible contacts are eliminated during first pass pruning.KDOP trees are somewhere in between Axis Aligned Bounding Box trees and Oriented Bounding Box Trees

Page 64: The Physics That Brought Cel Damage to Life:  A Case Study

Why KDOP’s?

A tigher fit than AABB treesLess computation than OBB TreesFaster to Update than OBB TreesHandles non-linear transformation as elegantly as AABB treesRobust across a wide diversity of data setsEfficient and Easy to implement on current console HardwareThey look kind of neat

Page 65: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection: GJK

• For Fine Grain collision detection we use G.J.K. (2) (Gilbert-Johnson-Keerthi)

• The GJK algorithm uses the concept of the Minkowski-sum to define the distance between two bodies A and B .

• The Minkowski-sum is defined as: • A-B={x-y:x is an element of Body A,y

is an element of Body B}

Page 66: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection: GJK

• If the origin (0,0,0) lies inside the Minkowski-sum,then the two bodies are intersecting.

• The algorithm tests if a simplex (consisting of up to 4 points of the Minkowski-sum) contains the origin in its convex hull.

• If not, then it calculates the smallest subset (<=3 points) of the simplex, which contains the closest point to the origin in its convex hull.

Page 67: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection: GJK

The algorithm repeats this process and iteratively searches the Minkowski-sum for the closest simplex to the originThe resulting simplex specifies a separating plane between the two convex hulls. If the origin is witihin the Minkowski-sum, the objects are intersecting and all bets are off.

Page 68: The Physics That Brought Cel Damage to Life:  A Case Study

Simplex Example

Page 69: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection

The surfaces of Convex hulls are spherically extruded Points become spheres Edges become cylinders Faces are still faces (see previous slide)

This provides the following benefits: Allows for the modelling of smooth objects like

spheres and car wheels Provides a C1 continuous surface Improves the convergence of GJK Improves stability and scores you a few points of

good karma.

Page 70: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection

GJK does not efficiently handle intersecting hulls Spherical extrusion prevents objects from

intersecting as the contact constraint maintains a distance between the hulls the sum of the objects extrusion radiai

In normal circumstances objects do not inter penetrate. Designers are not content with “normal

circumstances” Designers like to break physics engines. Most designers are evil.

Page 71: The Physics That Brought Cel Damage to Life:  A Case Study

Collision Detection Output

When contacts or collisions are detected, potentials are created to enforce the contact constraint and impart friction forces.These potentials are kicked off to the integrator to be processed later.Intuitively you might think of these potentials as non-linear springs that push objects apart.

Page 72: The Physics That Brought Cel Damage to Life:  A Case Study

implementation synopsis Each contact is classified as either a collision or a resting contactIf (relative velocity*normal > [insert magic threshold] )

collision else

resting contactTwo linear potentials are created. One acts along normal to repel objects, the other acts on the tangent plane to represent friction.nonlinear force along contact normal is approximated by a piecewise cubic splineFriction cone is approximated by a piecewise cubic patch

Page 73: The Physics That Brought Cel Damage to Life:  A Case Study

Applying all this to a game

How do we apply this “real world” physics to a game world?Example: Tornado Design Art Code Development

Page 74: The Physics That Brought Cel Damage to Life:  A Case Study

Design

Travel around levelPick up objects and swirl them aroundSpin and warpAppear and disappearSpawn particles

Example: Tornado

Page 75: The Physics That Brought Cel Damage to Life:  A Case Study

Art: Concept ArtExample: Tornado

Page 76: The Physics That Brought Cel Damage to Life:  A Case Study

Art: ModelExample: Tornado

Page 77: The Physics That Brought Cel Damage to Life:  A Case Study

Code

Collision RepresentationMotion: PD ControllerFFDSpecial FXOptimizations

Example: Tornado

Page 78: The Physics That Brought Cel Damage to Life:  A Case Study

Code: Collision Rep

todo

Example: Tornado

Page 79: The Physics That Brought Cel Damage to Life:  A Case Study

Code: PD Controller

Proportional Derivative (PD) controller’s are commonly used and trivial to implementRationale Generally more robust than other techniques such as

Hermite splines Intuitive and simple interface Can produces physically viable accelerations with

smooth ease-in/ease-out properties Given a desired position and velocity, they provide

you with an acceleration to apply in order to reach that position and velocity.

The trajectory taken may be specified by frequency and damping settings.

Example: Tornado

Page 80: The Physics That Brought Cel Damage to Life:  A Case Study

Code: PD Controller

F=(Ct – C)Ks + (Vt – V)Kd

Used extensively in game

Used for controlling Tornado’s path around level.Used to pull objects and swirl them

Example: Tornado

Page 81: The Physics That Brought Cel Damage to Life:  A Case Study

Code: PD Controller (cont’d)

E.g. I would like the Tornado to reach it’s target in 0.5 sec (frequency = 2.0) following a smooth ease-in/ease-out trajectory (critically damped, damp ratio = 1.0)

Or, reach it’s target in 5 sec (frequency = 0.2) with a slight overshoot (under damped, damp ratio = 0.5)

Example: Tornado

Page 82: The Physics That Brought Cel Damage to Life:  A Case Study

Code: PD Controller (cont’d)

Velocity Potential First order PD Controller: F = (Vt –

V)Kd

Example: Tornado

Page 83: The Physics That Brought Cel Damage to Life:  A Case Study

Code: FFD

Free Form Deformation Can bend, twist, stretch, scale

Procedural or key-framed

Example: Tornado

Page 84: The Physics That Brought Cel Damage to Life:  A Case Study

Code: FX

Dust ParticlesSwirling motion

Example: Tornado

Page 85: The Physics That Brought Cel Damage to Life:  A Case Study

Code: Optimizations

Cld rep: Spheres instead of hullsDOFs: 3 lin, 0 angProcess certain behaviors sporatically Fx Collision sensors

Example: Tornado

Page 86: The Physics That Brought Cel Damage to Life:  A Case Study

Code: LoopTornado::Step(){

UpdateForces();UpdateWarp();UpdateVictims();if( IsStep1() )

UpdateFX();}Tornado::CollisionProc(){

if( IsGround() )TurnOnFX();

elseTurnOffFX();

if( IsValidVictim() )AddVictim();

CancelCollision();}

Example: Tornado

Page 87: The Physics That Brought Cel Damage to Life:  A Case Study

Development

Placing it into the game.

Example: Tornado

Page 88: The Physics That Brought Cel Damage to Life:  A Case Study
Page 89: The Physics That Brought Cel Damage to Life:  A Case Study

References

Petros Faloutsos, Michiel van de Panne, Demetri Terzopoulos, "Dynamic Free-Form Deformations for Animation Synthesis". Published in IEEE Transactions on Visualization and Computer Graphics vol. 3 No 3. July-September 1997.Yan Zhuang. Real-time Simulation of Physically-Realistic Global Deformations. Department of Electrical Engineering and Computer Science, UC Berkeley, Fall 2000.Mathieu Desbrun, Peter Schröder, Al Barr, Interactive Animation of Structured Deformable Objects, Proceedings of Graphics Interface '99.Simulation of Non-penetrating Elastic Bodies Using Distance Fields G. Hirota, S. Fisher and M. C. Lin. Technical Report, University of North Carolina at Chapel Hill, NC, April 2000.

Page 90: The Physics That Brought Cel Damage to Life:  A Case Study

References (cont)

D. L. James and D. K. Pai, ``ArtDefo, Accurate Real Time Deformable Objects,'' in Computer Graphics (SIGGRAPH 99 Conference Proceedings), 1999D. Baraff and A. Witkin. Large Steps in Cloth Simulation. Computer Graphics Proceedings, Annual Conference Series: 43-54, 1998 D. Terzopoulos, J. Platt, A. Barr, K. Fleischer, "Elastically deformable models," Computer Graphics, 21(4), 1987, 205-214, Proc. ACM SIGGRAPH'87 Conference, Anaheim, CA, July, 1987Jonathan Richard Shewchuk, An Introduction to the Conjugate Gradient Method Without the Agonizing Pain, August 1994.

http://www-2.cs.cmu.edu/~jrs/jrspapers.html

Page 91: The Physics That Brought Cel Damage to Life:  A Case Study

Thank you!

For information about us: Please visit:

www.pseudointeractive.com

For information about Cel Damage:

Please visit: www.celdamage.ea.com