Title: Dr' Claude C' Chibelushi
1Fac. of Comp., Eng. Tech. Staffordshire
University
Programming Physics Engines for Games
Introduction
Dr. Claude C. Chibelushi
2Outline
- Introduction
- Dynamics / Behaviour Modelling Examples
- Software Architecture
- Basic Physics Concepts
- Newtons Laws of Motion
- Summary
3Introduction
- Many computer / video games, and virtual reality
(VR) applications require - illusion of realism (believability)
- available techniques
- cover variety of fields
- graphics, audio, physics, artificial intelligence
(AI), haptics, - evolve rapidly
- advances in computing power hence room for
better physics-based and AI-based simulation
4Introduction
- Simulation of real-world physics or intelligence
enriches game or VR content - physics and AI models enable believable rendering
of movement and behaviour - e.g. simulation of mechanical equipment (tanks,
airplanes, ), simulation of football tactics - believable virtual world enhances player / user
immersion
5Introduction
- Motion / behaviour simulation
- often uses approximate models of reality
- within budgetary and technological constraints
- development costs and deadlines
- hardware platforms processor, memory, I/O
graphics pipeline - hence programming believable virtual worlds often
requires - simplifications, optimisations, tricks
- believable is often not equivalent to perfectly
realistic
6Dynamics / Behaviour Modelling Examples
- Car racing game, flight simulator
- Continuous update of car / aircraft position
- based on current acceleration, speed, load, state
of road surface (icy, wet / dry, gravel, ...),
air viscosity, ... - requires physics models
7Dynamics / Behaviour Modelling Examples
- Tennis game
- Estimate ball trajectory for given conditions
- strike power, racket orientation, wind speed and
direction, ... - requires physics models
8Dynamics / Behaviour Modelling Examples
- Virtual table tennis
- Possible scenarios computer as one or both
players - ball trajectory calculation
- requires physics models
- simulation of sound for ball bounce / hit /
flight - requires physics models
- strategy for defence / offence by computer
- requires AI models for virtual player
- etc ...
9Software Architecture
- Simulation of interactive animated virtual world
is woven around continuous loop - main loop steps
- read user input
- perform some flow-control logic
- update state of virtual world (graphics entities
and associated audio) - output graphics, audio, vibrations, ...
- loop time determines frame rate
10Software Architecture
- Simplified simulation loop
- initialisation()
- repeat
-
- input()
- updateObjectState()
- graphicsAndSound()
- frameRateSync()
-
- cleanup()
Handle input events read game pad, mouse,
Apply object behaviour / motion control using
model based on AI, physics,
Apply graphics visibility determination, detail
mapping, Output 3D sound
May need to delay,
11Software Architecture
- Typical components of game or VR program
- input event-handling unit
- flow-control logic unit
- dynamic / behaviour unit (physics / AI)
- world data unit
- output units
- graphics unit, audio unit,
12Software Architecture
- Block-diagram of typical game or VR program
13Basic Physics Concepts
Mechanics
14Basic Physics Concepts
- Mechanics
- Study of motion of matter, and of forces that
cause the motion - based on concepts of matter, time, space, force,
and energy - many sub-fields e.g.
- statics study of bodies at rest
- dynamics study of bodies in motion
- forces that cause motion explicitly taken into
account? - no kinematics
- yes kinetics
15Basic Physics Concepts
- Body models
- Particle model suitable for
- body of negligible dimensions relative to motion
path - body whose dimensions are not relevant to problem
- i.e. no, or unimportant, angular motion
- e.g. car, airplane, rocket can be modelled as
single particle (concentrated at centre of mass)
16Basic Physics Concepts
- Body models
- Rigid body model suitable for
- solid body with negligible or no deformation,
regardless of external force(s) acting on it - Deformable body model suitable for
- continuous solid or fluid, which can deform under
action of external force(s)
17Basic Physics Concepts
- Classical mechanics (a.k.a "Newtonian mechanics")
- based on Newtons laws of motion
- three laws which address why / how objects move
- suitable for
- motion that is not too fast (speed much less than
speed of light) - size that is not too small (diameter much greater
than atom)
18Basic Physics Concepts
- Some important dynamics properties
- Position location relative to frame of reference
(origin of coordinate system) at any instant - displacement change in position during some time
interval - Velocity rate of change of position
- speed magnitude of velocity
- distance travelled divided by corresponding
duration - Acceleration rate of change of velocity
19Basic Physics Concepts
Some important dynamics properties
flight path
time t2 pos. s2 vel. v2 acc. a2
time t1 pos. s1 vel. v1 acc. a1
20Basic Physics Concepts
- Some important dynamics properties
- Average velocity or acceleration during time
interval ?t t2 t1 - for displacement ?s s2 s1
- average velocity v ?s / ?t
- what if path is not straight?
- for velocity change ?v v2 v1
- average acceleration a ?v / ?t
- Instantaneous velocity or acceleration
- velocity or acceleration at specific instant
- i.e. rate of change measured over extremely small
time interval
21Basic Physics Concepts
- Some important dynamics properties
- Force that which causes acceleration
- Broad categories
- contact forces
- e.g. collision, friction
- field forces (action at distance)
- e.g. force due to gravity field (gravitational
attraction), magnetic field
22Basic Physics Concepts
- Some important dynamics properties
Examples of contact forces
23Newtons Laws of Motion
- Law 1 (also called law of inertia)
- Body subjected to no net external force remains
at rest, or moves at constant velocity (in a
straight line) - no force hence no acceleration
- No net external force
- either v 0
- or v is constant
24Newtons Laws of Motion
- Law 2
- Acceleration of object is proportional to net
force acting on it - constant of proportionality is object mass
- Fnet SF m a
25Newtons Laws of Motion
- Law 3
- For every action there is an equal and opposite
reaction - action-reaction force pair FA,B - FB,A
Truck collision
26Newtons Laws of Motion
Free-body diagrams show all forces acting on
given free body (or group of bodies)
27Suggested Reading
- L. Bishop, D. Eberly, T. Whitted, M. Finch, M.
Shantz, Designing a PC Game Engine, IEEE Computer
Graphics and Applications, Vol. 18, No. 1, pp.
46-53, 1998. - Relevant parts of Ch. 1 2, D.M. Bourg, Physics
for Game Developers, OReilly Associates, 2002.
28Summary
- Believable simulation of real-world motion /
behaviour often based on - AI or physics-based rendering to produce
immersive virtual world - Most game / VR applications revolve around
continuous simulation loop - Typical game or VR program has units for
- input event-handling, flow control logic,
dynamics / behaviour, output to user
29Summary
- Mechanics study of motion and of forces that
cause the motion - many sub-fields kinematics, kinetics, ...
- Some important dynamics properties
- position / displacement, speed / velocity,
acceleration, force - Newtons laws of motion
- three laws about why / how objects move