Why Physics?
• More interactivity
• Looks cool (explosions)
• More realistic
• More variety and easier animations (rag
doll physics for death animations)
• Better gameplay (space fighter, driving
games)
Game Physics
• What is meant by Physics in games (old)?
– Collision Detection (testing)
• But want the physical effect of hitting an
immovable object.
• Also needed to provide the input (forces) for
physical simulations (equations) of moveable or
deformable objects.
– More intelligent (automated) interpolation
• Particle systems – Artistically defined generation
with Newtonian-based controls.
Game Physics
• What is meant by Physics in
games (new)?
– Fluid dynamics
– Deformable models
– Ragdoll (non-scripted)
articulation
– (More) Accurate simulation
Dead Reckoning
• Given the current state of a single entity,
integrate it in time assuming there are no
other influences.
• The state consists of:
– Position
– Velocity
– Acceleration (optional)
– Angular Momentum (optional)
Collisions
• Collision Detection
– Collision detection is a geometric problem
– Given two moving objects defined in an initial and
final configuration, determine if they intersected at
some point between the two states
• Collision Response
– The response to collisions is the actual physics
problem of determining the unknown forces (or
impulses) of the collision
Collision Detection
• „Collision detection‟ is really a geometric
intersection detection problem
• Main subjects
– Intersection testing (triangles, spheres, lines…)
– Optimization structures (octree, BSP…)
– Pair reduction (reducing N2 object pair testing)
Intersection Testing
• General goals: given two objects with current
and previous orientations specified, determine if,
where, and when the two objects intersect
• Alternative: given two objects with only current
orientations, determine if they intersect
• Sometimes, we need to find all intersections.
Other times, we just want the first one.
Sometimes, we just need to know if the two
objects intersect and don‟t need the actual
intersection data.
Collision Detection
Complicated for two reasons
1. Geometry is typically very complex,
potentially requiring expensive testing
2. Naïve solution is O(n2) time complexity, since
every object can potentially collide with every
other object
Collision Detection
Two basic techniques
1. Overlap testing
• Detects whether a collision has already occurred
2. Intersection testing
• Predicts whether a collision will occur in the future
Overlap Testing
• Facts
– Most common technique used in games
– Exhibits more error than intersection testing
• Concept
– For every simulation step, test every pair of
objects to see if they overlap
– Easy for simple volumes like spheres, harder
for polygonal models
Overlap Testing:
Useful Results
• Useful results of detected collision
– Time collision took place
– Collision normal vector
Overlap Testing:
Collision Time
• Collision time calculated by moving object back
in time until right before collision
– Bisection is an effective technique
A
t0
A
A
t0.25 A A
A
t0.375
t0.4375 t0.40625
t0.5
t1
B B B B B B
Initial Overlap Iteration 1 Iteration 2 Iteration 3 Iteration 4 Iteration 5
Test Forward 1/2 Backward 1/4 Forward 1/8 Forward 1/16 Backward 1/32
Overlap Testing:
Limitations
• Fails with objects that move too fast
– Unlikely to catch time slice during overlap
• Possible solutions
– Design constraint on speed of objects
– Reduce simulation step size
window
t-1 t0 t1 t2
bullet
Intersection Testing
• Predict future collisions
• When predicted:
– Move simulation to time of collision
– Resolve collision
– Simulate remaining time step
Intersection Testing:
Swept Geometry
• Extrude geometry in direction of movement
• Swept sphere turns into a “capsule” shape
t0
t1
Intersection Testing:
Sphere-Sphere Collision
Α Β A B 2 B 2 Α 2 rP rQ 2 A P1 Q1
t 2
, B P2 P1 Q 2 Q1 .
B
Q2
t=1
P1
t=0
P
t
P2
Q
t=1
Q1
t=0
Intersection Testing:
Sphere-Sphere Collision
• Smallest distance ever separating two
spheres:
d A2 2
A B 2
2
B
d rP rQ
2
• If
2
there is a collision
Intersection Testing:
Limitations
• Issue with networked games
– Future predictions rely on exact state of world at
present time
– Due to packet latency, current state not always
coherent
• Assumes constant velocity and zero acceleration
over simulation step
– Has implications for physics model and choice of
integrator
Collision Resolution:
Examples
• Two billiard balls strike
– Calculate ball positions at time of impact
– Impart new velocities on balls
– Play “clinking” sound effect
• Rocket slams into wall
– Rocket disappears
– Explosion spawned and explosion sound effect
– Wall charred and area damage inflicted on nearby
characters
• Character walks through wall
– Magical sound effect triggered
– No trajectories or velocities affected
Dealing with Complexity
Two issues
1. Complex geometry must be simplified
2. Reduce number of object pair tests
Collision Detection Methods
Many different methods
We will focus on two of them:
– Grid method: good for many simple moving
objects of about the same size (e.g., many
moving discs with similar radii)
– Bounding Volume Hierarchy (BVH) method:
good for few moving objects with complex
geometry
Grid Method
d
Subdivide space into a
regular grid cubic of
square bins
Index each object in a
bin
Grid Method
d
Running time is proportional to
number of moving objects
Bounding Volume Hierarchy Method
Enclose objects into bounding volumes (spheres or boxes)
Check the bounding volumes first
Bounding Volume Hierarchy Method
Enclose objects into bounding volumes (spheres or boxes)
Check the bounding volumes first
Decompose an object into two
Bounding Volume Hierarchy Method
Enclose objects into bounding volumes (spheres or boxes)
Check the bounding volumes first
Decompose an object into two
Proceed hierarchically
Bounding Volume Hierarchy Method
Enclose objects into bounding volumes (spheres or boxes)
Check the bounding volumes first
Decompose an object into two
Proceed hierarchically
Bounding Volume Hierarchy Method
• BVH is pre-computed for each object
BVH in 3D
Collision Detection
A A
B C B C
D E F G D E F G
Two objects described by their
precomputed BVHs
Collision Detection
Search tree
AA
pruning
A
A
Collision Detection A
B C
Search tree
AA
D E F G
BB BC CB CC
A
A
Collision Detection A
B C
Search tree
AA
D E F G
BB BC CB CC
pruning
Collision Detection A
B C
Search tree
AA
D E F G
BB BC CB CC
FD FE GD GE
If the pieces contained in G and D G D
overlap collision
Performance
Several thousand collision checks per
second for 2 three-dimensional
objects each described by 500,000
triangles, on a 1-GHz PC
Desirable Properties of
BVs and BVHs
BVs: BVH:
Tightness Separation
Efficient testing Balanced tree
?
Invariance
Desirable Properties of
BVs and BVHs
BVs: BVH:
Tightness Separation
Efficient testing Balanced tree
Invariance
Spheres
Invariant
Efficient to test
But tight?
Axis-Aligned Bounding Box (AABB)
Axis-Aligned Bounding Box (AABB)
Not invariant
Efficient to test
Not tight
Oriented Bounding Box (OBB)
Oriented Bounding Box (OBB)
Invariant
Less efficient to test
Tight
Comparison of BVs
Sphere AABB OBB
Tightness - -- +
Testing + + o
Invariance yes no yes
No type of BV is optimal for all situations
Why a Physics Engine?
• Physics simulation is hard
• Requires very stable integrator
• Articulated bodies especially take difficult
math
• Optimization is important
• Spring systems explode easily
Major Features
• Collision detection
• Newtonian forces and collision response
• Buoyant forces
• Friction
• Articulation and jointed characters (rag
doll)
• Prebuilt objects for simulation
Physics Toolkits
• ODE (Open Dynamics Engine)
• Ageia PhysX
• Newton Game Dynamics
• Havok
• Havok FX
• Tokamak Game Physics
Rigid Body Dynamics
• What is involved in this:
• http://www.youtube.com/watch?v=NM0bY
_IFoes&feature=related
More Complicated?
• What about this one?
• http://www.youtube.com/watch?v=Q7HLW
rldgLQ&feature=related
Ragdoll Physics
• YouTube
• http://www.youtube.com/watch?v=gbuA-
HEbROk
• Demo
• http://www.2dplay.com/ragdoll-physics-
2/ragdoll-physics-2-play.htm
Fluid Dynamics
• Water and other fluids are governed by the
Navier Stokes equations.
– http://gameplanets.blogspot.com/2007/06/phy
sics-simulations.html
• nVidia demo
– http://www.youtube.com/watch?v=wWlaD_2g
sIM&feature=related
Cloth Simulation
• Surface-like objects such as a cape on
your super-hero or a flag.
– http://youtube.com/watch?v=11L97NM2eiU&f
eature=related
Physics – Do we need it?
• Is it worth the cost?
• Why not just fake it?
Real-time Graphics Methods
• Real-time graphics is all about hackery
• It‟s impossible to get a realtime, high-
fidelity global illumination rendering
• The questions you should ask:
– What effects do I want in my game?
– What corners am I willing to cut?
Billboards
• A billboard is a flat object that faces something
– There are lots of different billboarding methods, but we‟ll stick
with the easiest, most used one
• Take a quad and slap a texture on it. Now we want it to
face the camera. How do we do that?
• Bread and butter of older 3d games and still used
extensively today
– Monsters (think Doom)
– Items
– Impostors (LOD)
– Text
– Faked smoke, fire, explosions, particle effects, halos, etc.
– #*$&ing lens flares
• Bad news: Little to no shading
Light Mapping
• We‟d like soft lighting and soft shadows but the fixed function
pipeline won‟t let us have our way. Plus, real lighting is slow once
we involve multiple lights.
• Hmm…
– Most of our world geometry is static
– We can blend multiple textures together in multiple passes
(multitexturing)
– Radiosity is good at diffuse
– Radiosity is view independent
Light Mapping
• Let‟s precompute the global illumination (sans specular)
using radiosity, store it in a light map, and blend that with
the detail texture
– That‟s the gist of it. Implementing it can be tricky.
– Don‟t need to use radiosity either
• Fun Fact: id software used to
have a SGI Origin 2000 (16 x 180mhz,
1.2GB RAM) to crunch maps. They
sold it on ebay in 2000.
• Note: probably should be called dark mapping…
No Light Mapping
Quake 3: Arena nvnews.net
Light Mapping!
Quake 3: Arena nvnews.net
Low-Poly Modeling
• Trying to make effective, complex models that a game engine can handle is
extremely difficult
• For the longest time games were just forced to have blocky looking models
• Thanks to normal mapping, now we can make really low poly models look
incredibly complex
Low-Poly Modeling
• This requires that the artist make a normal
map
• She can draw the normal map manually
• Or create two versions of the model, one
complex and one simplified, and use an
automated tool to generate the normal
map that represents the “differences” of
the two models
Keyframed Animation
• Same idea as keyframes in traditional animation
• A keyframe represents position and orientation at a point
in time
– Break the model into chunks (head, torso, etc.) and each chunk
has vectors/matrices associated with it
– Keyframes specify the values of those matrices at specific points
in time and their geometry
– Interpolate position and rotation (quaternions again) between
those time periods.
– Quake 3 is keyframed and uses ~ 15 keyframes/sec
– Uses a lot of memory because you need to store the geometry at
each keyframe, but keyframing is fast
Skeletal Animation
• The model has a skeleton and the skeleton is animated,
not the model
• Every vertex on the “skin” is connected to a bone so
when the bone moves so does the skin. This is done
with hierarchy and matrix transforms (sound familiar?)
• This involves transforming vertices so we can do this in a
vertex shader (blend registers)
• Skeleton allows for realistic physics simulation on the
model
• Keyframing is almost dead. Doom III, Half-Life 2, and
other new games all use skeletal animation.
• The memory cost of keyframing was so high that Quake
3 was almost changed to skeletal animation at the last
minute
• Related: facial animation
Motion Capture
• Elegant hack
• If you‟ve seen decent human animation in a game, it‟s
mocap. Video games are the biggest market for motion
capture and now the movie industry is getting into it.
• “Motion capture actor” is actually a legitimate profession
now
• Tom Hanks, that guy who did Gollum in LOTR
Note: Former MLB pitcher
John Rocker
Material Libraries
• Technical Directors and Artists at a game company now have the
luxury of creating material libraries – whole sets of shaders and
associated texture maps that can be used to enrich in-game models
• 3D movie production, especially at places like Pixar, always work
with material libraries, allowing people to focus solely on shader
production
• This frees the 3D and 2D artists to focus on art, not technology
Doom III
Halo 2
Black and White 2