0% found this document useful (0 votes)
46 views4 pages

(PE) (Lewins) Physical Systems in Computer Games

The document discusses the use of physics in computer games. It describes the main components of computer games, including the data structure, game engine, graphics engine, and audio system. It explains that physics is relevant because computer games simulate physical interactions and movement through rules and equations, similar to physics models of the real world. Examples given of how physics is used include simulating object motion, optics for graphics, and everyday phenomena like burning. Issues like gimbal lock that relate to both engineering and games are also discussed.

Uploaded by

jcb1961
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views4 pages

(PE) (Lewins) Physical Systems in Computer Games

The document discusses the use of physics in computer games. It describes the main components of computer games, including the data structure, game engine, graphics engine, and audio system. It explains that physics is relevant because computer games simulate physical interactions and movement through rules and equations, similar to physics models of the real world. Examples given of how physics is used include simulating object motion, optics for graphics, and everyday phenomena like burning. Issues like gimbal lock that relate to both engineering and games are also discussed.

Uploaded by

jcb1961
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SPECIAL FEATURE: COMPUTER GAMES

www.iop.org/journals/physed

Physical systems in computer


games
Shelagh Lewins
Greencroft Technical Services, Woking, Surrey, UK
E-mail: shelagh [email protected]

Abstract
This paper gives a brief introduction to computer games and the way they
are created. It also discusses the relevance of physics to those creating
computer games and gives examples of real situations where the author has
made use of skills that she learnt as a physicist.

What is a computer game made of? This system is adequate for the purposes of almost
Before discussing the uses of physics in computer all games, and is relatively simple to design and
games, it’s worth considering in broad terms how implement.
computer games work, and the main components Graphics engine. This is the code that
of which they are usually composed. translates the virtual world into an image for the
player. It has to be able to communicate with the
Data structure. This defines the game
game engine and data structure to find out where
world at any moment, in terms of environment
all the game objects are and what they’re doing,
and objects. For example, in a racing game
and then render them to the screen. The image
the environment would be the racetrack and the
must be updated at least 30 times per second to
objects would be all the cars in the race. The game
produce an illusion of smooth movement.
must record where every object is, its physical
A 2D engine generally works by moving
properties such as mass and velocity, and its
sprites around on the screen. For those not familiar
appearance.
with graphics programming, a sprite is a 2D bitmap
Game engine. The game engine’s job is image that can be drawn rapidly. I learned this
to manage the strategies of every object in the during my first month working in games, when one
game, and their interactions with each other. This of the artists told me he was drawing a tree sprite.
will include physical phenomena such as collision I was confused since I thought he was working
detection, route finding, falling under gravity and on a shooting game, not an elvish garden game,
recording damage when injured. and asked him what it looked like, hoping that his
The most commonly used type of game engine answer would clarify matters without me looking
is a State Machine, in which each game object stupid. He told me it looked like a tree. I felt
may be in one of a number of states (e.g. walking, stupid.
running, shooting, dying), and the transitions A 3D engine has to know the position and
between states are managed by a set of rules, such orientation of every object the player should be
as ‘if below 50% health, run away’. Usually, each able to see, and produce a realistic-looking image
object in the game runs its own strategy code every with perspective and lighting.
game tick to decide whether to change state, or Audio system. This determines what sound
what to do based on the state it is currently in. effects should be heard. There will be technical

0031-9120/04/050397+04$30.00 © 2004 IOP Publishing Ltd PHYSICS EDUCATION 39 (5) 397


S Lewins

limitations as to how many different samples can Games and physics can resemble each other
be played at once. Myst and Doom show how closely, as is illustrated by the problem of gimbal
powerful good audio can be in a game. lock. This term means one thing in engineering,
Game data management. This records and another in games programming, but the two
restores the game when the player loads and saves, concepts are very similar.
and also at the beginning of missions. Even Gyroscopic tracking systems work by mount-
pausing a game is not a trivial matter. ing a ‘stable platform’ inside a series of pivoting
Level editor. Many games have an external rings, each of which can rotate independently. As
piece of software that designers use to create maps the vehicle moves, the rings rotate relative to each
for strategy games, shooters and the like. other in order to keep the inner ring at a constant
In addition, the game needs to be able to orientation. By measuring the relative angles of
communicate with the graphics card, audio card, the gimbals, the craft’s computer can work out its
mouse, joystick, keyboard, game controller and own orientation in three dimensions. You would
any other peripherals that may exist.
expect three such gimbals to be sufficient, because
they provide three degrees of freedom of rotation.
Why is physics relevant to a game However, if the inner and outer gimbals become
developer? aligned, then you effectively have one fewer axis
Physics is a model of the world in terms of laws and of rotation. The stable platform will be unable to
equations. Physicists create possible models and remain in its original orientation, and your nav-
then test them to see how well they match reality. igation computer literally loses its bearings. See
A game is an interactive environment that www.hq.nasa.gov/office/pao/History/alsj/gimbals.
gives players a desired experience, such as flying html for an explanation of how gimbal lock af-
a fighter jet, slaying a dragon or building a city. At fected the Apollo 11 spacecraft.
its heart is a set of pre-defined laws by which the In games, gimbal lock refers to a problem that
computer determines what happens in response to occurs if you use Euler angles to rotate objects
the player’s choices. in a 3D game world. In this system, in order to
The one is pretty much the reverse of the other. rotate a vector (such as the direction in which a
Each depends on breaking a concept down into gun is pointing), you break the desired rotation
comprehensible chunks and working out the likely
down into rotations about the x, y and z axes of
consequences of the rules.
your virtual world. However, if at the end of the
The most obvious use of physics in computer
second rotation, your vector ends up lying along
games is to simulate the movement of physical
the global z axis, no amount of rotation about that
objects in terms of position, velocity, acceleration
z axis will affect it. You have effectively lost one
and momentum—for example, a racing game,
of your axes of rotation.
pool simulation or first-person shooter. (This
generally involves using a lot of vectors, and I do An engineer can solve the problem by adding
wish that when I’d been at school someone had a fourth, apparently redundant, gimbal. A game
explained to me that not only were vectors and programmer can use quaternions instead of Euler
matrices elegant mathematical tools, they would angles. The bad news is that quaternions are harder
also be useful in later life.) to understand: the good news is that there are some
Physics has other applications to games. excellent online tutorials.
Optics theory allows the graphics engine to display Scientific training is useful in and of itself,
the game world to the player, by simulating for example when tracking down code errors.
cameras, lights, surface textures and atmospheric Physics depends on hypothesis and experimen-
conditions. A game world may be made more tation, and when bug hunting I perform a similar
convincing by the addition of some familiar, process of identifying and excluding possibilities.
everyday physics such as burning or freezing, or Additionally, experience with performing calcu-
the need for raw materials in order to build cities. lations makes it a lot easier to spot a number
It might be impossible to find your way around that is far bigger or smaller than it ought to be,
in a game until you supply power to the lighting for example noticing that the player is running at
system or find yourself some infrared goggles. 200 m s−1 .

398 PHYSICS EDUCATION September 2004


Physical systems in computer games

Glossary
Tick: the interval of time that elapses before the game engine re-evaluates object strategies. This
does not necessarily match the frame rate, which may vary, while the game tick is usually a fixed
amount of time.
Euler angles: according to Euler’s rotation theorem, any rotation may be described using three
angles. In games these are usually expressed by three rotation matrices, about the x, y and z axes
respectively. The three angles giving the three rotation matrices are called Euler angles.
y
Note that in 3D games it is common to define the x and y axes as z
running along the bottom and edge of the computer screen, and the z
axis as travelling away from the player into the body of the monitor (see
diagram). x
Isometric projection: a form of orthographic projection. It is a method for the visual
representation of three-dimensional objects in two dimensions in which the angles between the
projection of the x, y and z axes are all the
z
same, or 120◦ . Because there is no
perspective distortion, an apparently 3D
image may be constructed, as below, from
120 o 120 o
flat images (see diagram). Games such as
Sim City use a 2D engine to draw an
isometric projection. 120 o
x y
Quaternion: a method of representing 3D rotations as a single rotation around an arbitrary axis. A
quaternion is expressed by a scalar and a three-component vector. It requires four numbers to define
a rotation, rather than the three required by Euler angles, but does not suffer from gimbal lock.
Tutorials may be found by searching the internet for ‘quaternion tutorial’, though do make sure that
the one you use is aimed at 3D programmers rather than at mathematicians, e.g.
www.cprogramming.com/tutorial/3d/quaternions.html
Bug: a mistake in a computer program.
Spline curve: a curve created by interpolation between two or more control points.
Middleware: a software program that handles some or all of the underlying requirements of a
game, such as the 3D engine and audio code, allowing the developer to focus on the game engine.
Several proprietary engines are available, including the Quake and Unreal engines, though they do
tend to be optimized for producing first-person shooters. Numerous commercial games, such as
Half Life, were created using middleware.

Designing physics systems for games necessarily make for a fun game. So physics needs
In practice, it’s neither possible nor desirable to to be adapted for games, to make it easier to write
write a program that simulates physics exactly. the code, to ensure the game runs at a good frame
Firstly, it would be a desperately difficult and rate, and most especially to ensure that it is fun to
lengthy task. Secondly, games must run in real play.
time, and even the fastest machine would grind to For example, there’s no point writing a
a halt if it tried to model the behaviour of every thermodynamic simulation of the formation of
grain of sand on a beach. Thirdly, it wouldn’t raindrops when some slanting white streaks across

September 2004 PHYSICS EDUCATION 399


S Lewins

the screen will give the player just as good an to assume that the frame rate will never fall below
impression of a rainy day. a certain rate and to cap it at (say) 30 frames
per second, but this makes life difficult during
Limitations of digital worlds development, when frame rate can frequently fall
for other reasons that will be sorted out before
In a game, we have to manufacture every single
publication. Game testers and level designers get
thing the player sees. Not only does that mean
very tetchy if the apparent top speed of the car or
that we have to make massive simplifications, but
player varies wildly from version to version.
also all sorts of errors can occur. Usually this
is because the computer has to manage time and
movement in discrete quantities. Game time is The observer is part of the experiment
not continuous. It takes time for the computer Just as an observer changes the behaviour of
to evaluate where everything is now and what’s photons in the classic double-slit experiment, a
happened in the game, and to render the image to game cannot be designed without the player in
send to the screen. mind.
As an example, consider a dynamics system Players will use their imaginations, given the
in which the player experiences a frictional force opportunity, and it’s also worth remembering that
that opposes the force propelling them forwards. people tend to believe what you tell them. In a
The frictional force increases with their speed, thus recent game for Exertris, I asked the artist to create
limiting how fast they can go. Their net forward different graphics for spaceships in a multiplayer
speed is calculated from the difference between game even though the spaceships were identical
the forward force and the opposing frictional in practical terms. Everyone who played the game
force. Unfortunately, under certain circumstances, was convinced that the ships handled differently
say if the frame rate is very low, this difference and became quite excited when they got their
might come out to be negative, moving the player favourite ship. A very cheap device gave the
backwards. The solution is to add a function that players a more interesting experience.
checks for negative values and sets the force to The very team who work on a game can be the
zero if one is detected. people least able to evaluate its difficulty, because
Just turning the physics equation into a line they are extremely familiar with the controls and
of computer code can go horribly wrong. For know every feature of the game intimately. A team
example, your programming language may use left to itself will usually make the game far too
fixed-point numbers, with six digits before the difficult for anybody else to enjoy, because they
decimal place and three after. This can represent naturally tend to balance the game so that it is
numbers up to 999 999.999. If, as part of your interesting for them to play themselves.
calculations, you multiply two numbers that are The only way to test the appeal of your game
greater than 1000 by each other, the result will is to take the scientific approach, and try it out on
be a number that is greater than 999 999.999. potential players. Don’t tell them what to do: just
What happens to this variable will depend on the watch and see what they make of it. This will tell
particular language: it may become negative, or you volumes about how fun your game is, and how
very small, or fail to be recognized as a number at friendly is your user interface.
all: whatever happens, your physics will not work
Received 7 July 2004
correctly. So when writing the computer code PII: S0031-9120(04)82915-0
that represents your physical equations, you must doi:10.1088/0031-9120/39/5/001
always consider the limitations of your variable
Shelagh Lewins took a Foundation
types and the maximum/minimum values that your Course in Graphic Art then read Physics
equations might produce. at Oxford. She has spent almost ten
It’s also worth checking that your algorithm years working on the design of computer
games such as Dungeon Keeper 2, Aliens
doesn’t depend on the frame rate. So for example, versus Predator and Theme Park Inc,
rather than moving the player a fixed distance per and most recently on games for an
game tick, it’s important to find how long the game integrated games console/exercise bike
called Exertris. Shelagh is now a game
tick was and move them the correct distance for the designer on a web-based, persistent
amount of time that has elapsed. It’s also possible world multiplayer game.

400 PHYSICS EDUCATION September 2004

You might also like