evolution of games

59
Mathematics in Videogames By: (alphabetical order ) Angela Ren Christine Lee Faizan Khalid Michelle Wong Minna Lee

Upload: dinesh

Post on 13-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

Mathematics in Videogames By: (alphabetical order ) Angela Ren Christine Lee Faizan Khalid Michelle Wong Minna Lee. Evolution of Games. Wolfenstein, one of the earliest FPS (first person shooter) games. Evolution of Games Cont. Doom, the next breakthrough in graphics. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Evolution of Games

Mathematics in VideogamesBy:

(alphabetical order )Angela Ren

Christine LeeFaizan Khalid

Michelle Wong Minna Lee

Page 2: Evolution of Games

Evolution of Games

Wolfenstein, one of the earliest FPS (first person shooter) games

Page 3: Evolution of Games

Evolution of Games Cont.

Doom, the next breakthrough in graphics

Page 4: Evolution of Games

Evolution of Games Cont.

Quake, this was a huge leap in the quality of graphics in computer games

Page 5: Evolution of Games

Evolution of Games Cont.

Quake III, one of the newest FPS games around with more detailed images

Page 6: Evolution of Games

Numbers

• Integers

• Fixed point numbers

• Floating point numbers

• Discreteness

Spatial discreteness

Temporal discreteness

Page 7: Evolution of Games

Integers

• Integers can be stored exactly in binary and have efficient methods for addition and subtraction, as well as slightly less efficient methods of multiplication and division.

• When used in computers, integers have upper and lower limits. This limit is important when operating certain operations as overflow can occur.

• Integers have been favored for storing variables used in video games because operations on them were much faster than on other types of numbers.

Page 8: Evolution of Games

Fixed Point Numbers

• Efficient way of dividing an integer by a scale factor:

when the scaling factor is a power of two the division can be easily performed by using binary shifts, when number is stored in this manner, it is called a fixed point number, the integer represents a number with both integer and fractional parts, separated by a binary point.

Page 9: Evolution of Games

Floating Point Numbers:Fixed Ranges

• The main disadvantage of fixed point numbers is that they lack precision over a large range: they cannot hold very large or very small numbers.

• Solution: floating point numbers– Two parts: 1. A signed exponent (the range shift)

» 2. Signed mantissa (raw value)

*turn a floating number into a fixed point number by shifting the mantissa by and number of bits specified in the exponent.

Page 10: Evolution of Games

Discreteness

• Discreteness-values in computer games often have integer values. – Time is not continuous (split up into frames

of 1/60th of a second)– Character positions are not continuous (they

are displayed on pixel boundaries)

*This can be very useful as an approximation to a smooth universe.*

Page 11: Evolution of Games

Spatial Discreteness:Aligning objects to grid boundaries

• On nearly all video games, characters must be placed on integral pixel boundaries.

• The use of fixed point (or floating point) numbers for game objects means the objects are held with greater precision than is shown on the screen.

Page 12: Evolution of Games

Temporal Discreteness:Game Frames

• The concept of games frames is fundamental to traditional games programming.

• Most games are based on the ticking of a clock which happens a fixed number of times per second. Every time this clock signal is processed, the game executes one cycle of thought. Operations that may have been taught to calculate all at once have to be done one step at a time.

Page 13: Evolution of Games

Temporal Discreteness:Game Frames

• The game frame is not the same as the display frame.

• The game is run in a separate “thread” from the display code, so it should be immune to the display code being bogged down by too many objects or a scene being too complex.

• The shared variables that are written by the game code and read by the display code should be double buffered to prevent synchronization problems.

Page 14: Evolution of Games

Shading

• Flat Shading

• Gouraud Shading

• Phong Shading

• Quadratic Shading

Page 15: Evolution of Games

Flat Shading andGouraud Shading

• Flat shading simply assigns a single color to a polygon. It is very simple and fast, but makes the object look very artificial.

• Colors are assigned to each vertex, then they are blended across the face of the polygon. Since each vertex is typically associated with at least three distinct polygons, this makes the object look natural.

Page 16: Evolution of Games

                                                                                          

For example…

Page 17: Evolution of Games

Phong Shading

• Introduced by Phong, is the appropriate shading method to go with his illumination model.

• Triangles are shaded by linearly interpolating the surface model the surface normal and re-revaluating the illumination equation at each pixel.

• Phong shading is superior to other methods but it is computationally demanding and very expensive.

Page 18: Evolution of Games

Quadratic Shading

• A quadratic can express the shading maximums and minimums that appear within a triangle’s interior.

• Can approximate light distribution better than Gouraud shading.

• Can be constrained to enforce continuity across triangle edges, but this increases computation because the quadratic has more degrees of freedom (6) so it needs more constraints.

Page 19: Evolution of Games

Geometry, Vectors and Transformations

• In order to understand how FPS games work, geometry, vectors and transformations are required.

• Geometry: is the study of shapes of various sort.

• Vectors: mathematical way of representing a point.

• Transformations: moves a point (or an object, or even an entire world) from one place to another.

Page 20: Evolution of Games

Geometry

• Simple shapes: a point and a line ― a straight line.

• Complex shapes: a plane ― a flat sheet, like a piece of paper or a wall and a solid ― a cube or a sphere.

Simple geometric figures

Page 21: Evolution of Games

Vectors

• A vector is 3 numbers: usually x, y, z for three different directions to get one point.

• For example, when x=3, y=1, z=5 this point can be found by using the 3-Dimensional (x, y, z) coordinate plane.

Picture of a vector and directions

Page 22: Evolution of Games

Transformation

• Transformation, moving the object across a plane, is also called Translation

• Another type of transformation is called Rotation

Translations and rotations

Page 23: Evolution of Games

3D Graphics• The basic idea of 3D graphics is to turn a

mathematical description of a world into a picture of what that world would look like to someone inside the world.

• The mathematical description could be in the form of a list, for instance: there is a box with center (2,4,7) and sides of length 3, the color of the box is a bluish grey. To turn this into a picture, we also need to describe where the person is and what direction they are looking, for instance: there is a person at (10,10,10) looking directly at the center of the box. From this we can construct what the world would look like to that person.

Page 24: Evolution of Games

3d Graphics cont.•What I just described above is similar to what the computer is doing (50 times a second!) every time you run around shooting hideous monsters in Quake, although the details are slightly different.

•In computer games (at the moment) the description of the world is just a list of triangles and colors. The newest computer games are using more complicated descriptions of the world, using curved surfaces, however in the end it always reduces to triangles. For instance, a box can be made using triangles as illustrated below:

Page 25: Evolution of Games

3d Images

Page 26: Evolution of Games

Cartesian Coordinates• In 3-D games, we use x, y, and z axes to

graph coordinates in a game.• X-coordinate is the horizontal value• Y-coordinate is the vertical value• Z-coordinate is the depth value

Page 27: Evolution of Games

Polar Coordinates• Polar coordinates are

good for figuring out the velocities of objects in 2-D games (sports games, etc)

• A person can be running in a particular direction and then change angle by a certain amount each game frame, while maintaining the same speed.

Page 28: Evolution of Games

Quaternions• Quaternions: noun: Any

number of the form a + bi + cj + dk where a, b, c, and d are real numbers, ij = k, i2 = j2 = -1, and ij = -ji.

• Quaternions are used to process rotations in three dimensions.

Page 29: Evolution of Games

Matrices

• Matrices are used to change your point of view in the videogame.

• Objects and characters in a game are positioned with coordinates:

(x, y, z).

Page 30: Evolution of Games

To get your coordinates to transform, multiply by a matrix:

• Rotate around x-axis:

• Scale to size:

• Translation:

Page 31: Evolution of Games

Vectors

Vector Products:• Vector products determine an

object’s seen surface and hidden surface. This is done by a process that uses both vector products.

• Various lighting scenarios, ambient light, parallel light and point source light are used to give the game a touch of realism.

Page 32: Evolution of Games

Hidden Surfaces

• We need to cover the set of points that define the object with a convex polygon mesh.

• By taking cross products of two defined edge vectors, we generate a “normal” vector to the plane of the polygon

Page 33: Evolution of Games

Hidden Surfaces

• Because the normal will point out from the object’s surface, this allows us determine which section is visible and hidden to the object.

• Another way to determine the hidden surfaces is when the dot product of the vector observer, V2, and the normal, n, is positive.

Page 34: Evolution of Games

Light

• A brightness of a certain part of an object is dependent on the component of reflected light reaching the observer.

Page 35: Evolution of Games

Light cont.

• N is a unit normal R = 2(N•L )N – L

• Component for reflected light (O•R)O

• O is a unit vector in the direction of the observer.

• Scaling factors on the length of this vector is used to generate the desired effect.

Page 36: Evolution of Games

Inertia•Newton’s first law states that unless there is an obstacle or another force on an object’s path, it will move in a straight line (inertia)

•In order to apply this knowledge, we need to make sure that we keep in track of the object’s velocity, and this should be added to the object’s position each game frame

•We should change the velocity to handle various forces that act upon the object, not simply change the object's position.

Page 37: Evolution of Games

Gravity•Gravity is a force that pushes two things together

•The force of gravity is defined by:

•G is the universal gravitation constant, m1 is the mass of the first object and m2 is the mass of the second object, and r is the distance between them

•The effect of gravity on earth’s surface is of constant acceleration at which point you can use F=mg, where m is the mass of an object and g is 9.8 N/m2

Page 38: Evolution of Games

Gravity cont.•So to make objects fall, add an acceleration constant to their y velocity every game frame. Then add the y velocity to the y position.

•You can change the acceleration constant to change the feel of the game world. When the constant is low, the game has a lunar landscape feel, and the jumps seem to go in slow motion. But when the constant is high, the jump is way faster and the person seems to run faster as well.

Page 39: Evolution of Games

Bouncing•When an object in the game hits the background or another object, it is called a collision. There are two types of collision: inelastic and elastic (use of physics)

•When an object hits a horizantal background, it bounces up. This is done by multiplying the y velocity vector by a negative number bween 0 to –1.

•This number is related to the coefficient of the level of “bounciness”

•The higher the number is, or the closer it is to 0, the less bouncy it is.

Page 40: Evolution of Games

Bouncing Cont.•Similar to the horizontal backgrounds discussed earlier, same rules apply for vertical backgrounds.

•With vertical backgrounds, you do the same but instead you multiply by the x velocity vector.

•Other backgrounds, excluding horizantal and vertical, includes the use of geometry

•If an objects hits a diagonal, or any non vertical or non horizantal background, then you measure the angle.

•But as the measure of the angle changes, the speed does as well.

Page 41: Evolution of Games

Friction

In the real world, once you stop pushing things they generally slow down and stop.

Page 42: Evolution of Games

Friction You can simulate friction by multiplying an object's velocity by a constant value between 0.0 and 1.0 each frame.

This value should be only slightly less than 1.0, since the lower it is the faster the

object will slow down.

Experimenting with different values to see which numbers look right in your game

Page 43: Evolution of Games

Jumping: User should be able to control how high their game character jumps by holding down a button.

: Game designer control gravity.

: THIS GOES AGAINST THE LAWS OF PHYSICS!!!!

Page 44: Evolution of Games

Newton's Differences: Simplifying the physics maths 

A object fired into the air under gravity will basically follow the path of a parabola

(ax2 + bx + c )

Take differences of the results of this function, and they form a more simple pattern.

Page 45: Evolution of Games

Newton's Differences: Simplifying the physics maths 

Figure five

x

x2

D x2

D D x2

D D D x2

0

0

1

 

 

1

1

3

2

0

2

4

5

2

0

3

9

7

2

0

4

16

9

2

0

5

25

11

2

 

6

36

 

 

 

Repeating that step yields a constant number. This is the acceleration of the object!

Take differences of the results of this function.

Velocity Acceleration

Page 46: Evolution of Games

Calculus:The proof behind the simplifications

These differences are in fact the special case of differentiation

Call distance X and time t

Velocity=dX/dt

Acceleration=dV/dt

Page 47: Evolution of Games

Figure five

t

t2

D t2

D D t2

D D D t2

0

0

1

 

 

1

1

3

2

0

2

4

5

2

0

3

9

7

2

0

4

16

9

2

0

5

25

11

2

 

6

36

 

 

 

Calculus:The proof behind the simplifications

dX/dt = 2t

0

2

4

6

8

10

dX/dt = 2

2

2

2

2

2

Velocity Acceleration

Page 48: Evolution of Games

Intelligent Motion

The deterministic algorithms for enemy movement used in most games:

•Chase •Evade •Pattern •Response •Random choice.

Page 49: Evolution of Games

Intelligent Motion Deterministic algorithms are simple AI techniques

Use a set of variables as the input and then use some simple rules to drive game objects based on these inputs.

Page 50: Evolution of Games

Perceived Smoothness: Removing jerkiness 

For motion to be smooth, it should be continuous to the greatest extent.

• Position - if this changes suddenly, the object appears to jump.

• Velocity - sudden changes of velocity seem very line based.

• Acceleration - changes of acceleration are not so noticeable in a game.

Page 51: Evolution of Games

Chase Algorithm

For example, when an enemy is programmed to follow player

If the player is to the left of the enemy, move enemy left. If it is to the right, move right.

Eugene Jarvis’ Defender

Page 52: Evolution of Games

const int xstart = 12, xcentre = 0, xvel = 2;  int frame, xpos;  

for (frame = 0, xpos = xstart;; plot(frame++, xpos))  {  

if (xpos < xcentre)  

xpos += xvel;  

else if (xpos > xcentre)  

xpos -= xvel;  }

Simple Chase Algorithm

Page 53: Evolution of Games

Chase Algorithm (with acceleration)

const int xstart = 12, xcentre = 0, xacc = 1;  int frame, xpos, xvel;  for (frame = 0, xpos = xstart, xvel = 0;; plot(frame++, xpos))  {  

if (xpos < xcentre)  

xvel += xacc;  

else if (xpos > xcentre) 

 xvel -= xacc; 

 xpos += xvel; 

 }

Page 54: Evolution of Games

Chase Algorithm (with acceleration)

xpos

time

Page 55: Evolution of Games

Some Calculus •If we call distance x and time t, we can calculate velocity

v as dx/dt and acceleration a as dv/dt.

•If an object starts at position x, and has a velocity v which doesn't change, then after t seconds, the position of the object is xt=x+v×t.

•Example: a fighter throws a grenade from a high cliff. his position is (100,150,150) and he throws a rock with velocity (5,2,0). Where is the rock after 10 seconds? To work this out, we use the formula above: xt=x+v×t. In this case (after 10 seconds) the rock is at (100,150,150)+(5,2,0)×10=(100,150,150)+(50,20,0)=(150,170,150).

Page 56: Evolution of Games

Simulation Games• How is all this stuff actually used in computer

games? Here's a simple example:

• Every time you fire a bullet from your plane in your favorite flight simulator, the computer has to work out its position using calculations. The computer has to do these calculations 50 times a second for every bullet in the sky, and on top of that it has to do much harder calculations for the planes as well

• It is much more complicated, because in the real world, there are things like wind and friction because of the air.

Page 57: Evolution of Games

Simulation Games cont. •Here is how you might include wind in the calculations. Suppose the wind causes the bullet to have an additional acceleration of w, and the wind is blowing at a constant rate (the wind speed isn't changing).

•Now we have the acceleration on the bullet is g+w. Friction in the air is much more complicated though, because the amount of friction depends on the speed of the bullet.

•In fact, the friction causes an additional acceleration of -kv, where k is some positive number and v is the velocity. So now the acceleration is g+w-kv

•In other words, the acceleration is changing as well as the velocity!

Page 58: Evolution of Games

Works CitedCMP Media. “Mathematics in Videogames.” July 2001. 18 May 2006

<http://www.gamasutra.com/features/19970601/muller_01.htm>Goodman, Dan. “The Use of Mathematics in Computer Games.” May

2000. 18 May 2006 <http://nrich.maths.org/mathsf/journalf/may00/art3/index.html>

Wilkins, Kevin. “Mathematics for Computer Games Technology.” 18 May 2006 <http://www.math.uoc.gr/~ictm2/Proceedings/pap458.pdf>

Vlasic, Daniel. "Fake Phong Shading." 17 May 2002. MIT. 18 May 2006 <http://groups.csail.mit.edu/graphics/pubs/thesis_drdaniel.pdf#search='shadingcolorvideo%20games'>.

Page 59: Evolution of Games