Top Banner
You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015
42

You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Dec 13, 2015

Download

Documents

Paulina Turner
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

You'll Use Everything:Mathematics in the Gaming Industry

Mu Alpha Theta Initiation

Daniel R. Collins

May 27, 2015

Page 2: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Question

“What will I use this for?” We don't know what you'll do for work! My teachers certainly didn't. 3D game industry invented while I was in school. Consider this a case study.

Page 3: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Title of the Talk

“You'll use everything you've ever learned” Johnny Carson to Steve Martin Tonight Show, 1976 See: Martin, “Born Standing Up” (2008)

Page 4: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

My Time in the Game Industry

Hired after college with a math degree Papyrus Design Group, 1996-1998

PC racing simulations (IndyCar, NASCAR) Genetic Anomalies, 1998-2000

Encrypted virtual collectible card games Both in Boston, MA

Page 5: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

NASCAR Racing 2 (Papyrus, 1996)

Page 6: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Star Trek: ConQuest Online (GA, 2000)

Page 7: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

After My Time in the Game Industry

Pen-and-paper role-playing games (D&D) Campaign, Fight On! magazines Judge, “One Page Dungeon Contest” Self-published rules expansions Blog: “Delta's D&D Hotspot” Contacts in computer game industry

Page 8: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

About the Game Industry

Top-level games cost as much to make as movies Grand Theft Auto V: $140M Star Wars The Old Republic: $200M

Greatest demand on hardware usage Push to limits: CPU, memory, graphics cards, video

refresh FPS, sound, etc.

Page 9: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Skills: Computer Programming

“Close to the metal” Mostly in C/C++ and some Assembly Can't afford overhead from fancier languages No automatic garbage collection as in Java, et. al. Know memory management and be careful of lost

pointers (memory leaks, crashed systems, etc.)

Page 10: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Trigonometry

My first 2D game (age 13) At what angle is the bad guy shooting?

Page 11: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Solving Physics Formulas

Regular need to find and read physics formulas Solve for desired variable (“literal equation”) Enter as program code

Page 12: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Example: Doppler Effect (NASCAR Racing 2)

/* find engine RPMs, relative speeds between mic & source */ v = tmp->longSpeed; v = BETWEEN(- 2 * 250 * MPH, v, 2 * 250 * MPH); pitch = engPitch(abs(v), i); vol = engVol(abs(v), i); dl = trackDist(Dlong, tmp->dlong); dt = tmp->dlat - Dlat; d = magnitude(dl,dt); if(!d) d = 1; Ospeed = muldiv(Speed, dl, d) + muldiv(Latspeed, dt, d); Sspeed = muldiv(v, dl, d) + muldiv(tmp->latspeed, dt, d); pitch = muldiv(pitch, SPEED_OF_SOUND + Ospeed, SPEED_OF_SOUND + Sspeed);

Page 13: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Example: Doppler Effect (NASCAR Racing 2)

Page 14: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Analytic Geometry in RARS

RARS: Robot Auto Racing Simulator Hobby AI-writing competition

Page 15: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Analytic Geometry in RARS

Racetrack geometry given in terms of straight line segments and circular arcs.

Fastest velocity is on the largest circle that can be carried through a corner

So: Granted outside of straight and inside point of curve (apex), solve with the fastest circle through the corner

Page 16: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Analytic Geometry in RARS

Page 17: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Analytic Geometry in RARS

// This function takes 3 control points and solves for a circle through them.// Takes index of apex cp as input; returns center (x,y) and radius.static void cpSolveCircle (int apex, double *x, double *y, double *radius) {// ...

// // Our strategy is to draw two lines (parameterized), bisecting each set // of control points, and find the center at their intersection. // Tpline pline1, pline2;

// set 3 points x1 = cp_data[cpBefore(apex)].x; y1 = cp_data[cpBefore(apex)].y; x2 = cp_data[ apex ].x; y2 = cp_data[ apex ].y; x3 = cp_data[cpAfter (apex)].x; y3 = cp_data[cpAfter (apex)].y;

// compute centers between each pair of points pline1.cx = (x1+x2)/2; pline1.cy = (y1+y2)/2; pline2.cx = (x2+x3)/2; pline2.cy = (y2+y3)/2;

// compute differences (direction vectors) between each pair of points pline1.dx = -(y1-y2); pline1.dy = (x1-x2); pline2.dx = -(y2-y3); pline2.dy = (x2-x3);

// intersect these lines double t1; plinesIntersect(&pline1, &pline2, &t1); plineEvaluate(&pline1, t1, x, y);

// calculate radius: dist from center to 1 point *radius = dist(*x, *y, x1, y1); }

Page 18: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Vectors

Vectors used to represent forces in any kind of 3D game physics engine

Following example from simple 2D RARS

Page 19: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Vectors

Page 20: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Matrices

Matrices are used to represent position, orientation, movement and rotation in space.

For 3D: use 4x4 matrices Additional components used to indicate scaling

(note ellipsoids in following examples: compressed sphere primitives).

Example: “Film” ray-trace render engine written in Pascal (1995-2000).

Page 21: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Matrices

Page 22: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Matrices

Page 23: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Linear Algebra: Matrices

{ SAV-DD.DAT: Sathar Destroyer with planet & sun }

01 0 0 00 1 0 00 0 1 00 0 0 1

BEGIN

{bridge} 0 8.50000023841858E-0001 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 8.50000023841858E-0001 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 8.50000023841858E-0001 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 1.31999998092651E+0001 1.00000000000000E+0000 .767 .437 .110 .767 .767 .437 .110 .767 0.8 0.85 0 0

{bridge 1} 0 3.49999994039536E-0001 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 3.49999994039536E-0001 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 0.00000000000000E+0000 3.49999994039536E-0001 0.00000000000000E+0000 7.50000000000000E-0001 0.00000000000000E+0000 1.31999998092651E+0001 1.00000000000000E+0000 .767 .437 .110 .767 .767 .437 .110 .767 0.8 0.85 0 0

Page 24: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

More Analytic Geometry

In the ray-trace renderer, need to physically simulate/compute each light-ray intersection with primitive objects (spheres, cylinders, cubes, etc.)

This is done recursively to handle reflections, refractions, and shadows.

Following example shows code for checking if a 3D vector intersects with a unit sphere

Page 25: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

More Analytic Geometry

{Intersections on the primitive SPHERE: centered at (0,0,0) with radius 1. Returns t, point of intersection (if less than inbound t); normal, outward normal to the surface (assuming HitSphere and "want_normal") Consult Watt (pp. 163-164) and Hill (pp. 624-627). }

FUNCTION Hit_Sphere(var thisRay: ray; var t: double; want_normal: boolean; var normal: vector4): boolean;VAR a, b, c, determ, determ_root, trial_t: double;BEGINWITH thisRay DO BEGIN

{* default *} Hit_Sphere := FALSE;

{* coefficients for quadratic *} a := dir[1]*dir[1] + dir[2]*dir[2] + dir[3]*dir[3]; b := _2 * (dir[1]*start[1] + dir[2]*start[2] + dir[3]*start[3]); c := start[1]*start[1] + start[2]*start[2] + start[3]*start[3] - _1; determ := b*b – 4*a*c;

{* analyze intersections *} if (determ < AlmostZero) then Exit; determ_root := sqrt(determ);

Page 26: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

More Analytic Geometry

{* smaller "-" t positive: looking in at near wall *} If -(b+determ_root) > AlmostZero then begin trial_t := -(b + determ_root)/(_2*a); if trial_t > t then Exit; {* obscured *} Hit_Sphere := TRUE; t := trial_t; if want_normal then {a unit vector} LoadVec4(start[1]+t*dir[1], start[2]+t*dir[2], start[3]+t*dir[3], normal); End

{* larger "+" t positive: looking out at far wall *} Else if (determ_root-b) > AlmostZero then begin trial_t := (determ_root - b)/(_2*a); if trial_t > t then Exit; {* obscured *} Hit_Sphere := True; t := trial_t; if want_normal then {a unit vector} LoadVec4( -(start[1]+t*dir[1]), -(start[2]+t*dir[2]), -(start[3]+t*dir[3]), normal); End;

END;END;

Page 27: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

More Analytic Geometry

What about a torus shape? Example: Ring on a space station Reduces to a 4th-degree equation (a ray can

intersect the surface up to 4 times) Need code for the general quartic formula

The highest-degree equation for which any closed formula exists (Abel 1824)

Page 28: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

More Analytic Geometry

Page 29: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Game Theory

Surprisingly: never mentioned in workplace I use some concepts for design of tabletop games Example: Design of pieces or options in a strategy

or role-playing game Don't want pieces so undervalued they never get

used in play (wasted design effort) Iterated Elimination of Dominated Strategies (IEDS;

Aumann, 1976)

Page 30: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Game Theory

Simulation for Game Design (Collins, presented at Johns Hopkins, 2014)

Simulate the game in a computer and run each piece against all others thousands of times

If a piece usually loses against all or most other pieces, adjust cost downwards (or vice-versa)

Balance iteratively; hardest part of game design

Page 31: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Statistics

Of course, this procedure (with simulated dice rolls, random terrain, weather, etc.) is only a sampling of the possible play space, not a complete census

So how many trials are needed to be confident in the results (does X really beat Y)?

Answered by formula relating margin of error for a proportion, confidence level, and sample size

Page 32: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Statistics

For 95% confidence, z = 1.96 ≈ 2 For a proportion (0 to 1), max σ = 0.5 Assume desired margin of error E = 1% = 0.01 Then n = 10,000

Page 33: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Book of War (Collins, 2011)

Page 34: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Book of War (Collins, 2011)

Page 35: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Book of War (Collins, 2011)

Page 36: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Back to Computer Science

Once the “basic” units for a game have been established, can cost-balance new additions by a binary search on best-balanced cost

Simulating play against all other units in system 10K times each per cycle

Page 37: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Back to Computer Science

// Binary search for best cost while (highCost - lowCost > 1) { int midCost = (highCost + lowCost)/2; newUnit.setCost(midCost); int midWins = assessGameSeries(newUnit, baseUnits); if (midWins < expectWins) { highCost = midCost; highWins = midWins; } else { lowCost = midCost; lowWins = midWins; } }

Page 38: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Calculus Example

D&D 3rd Ed.: “If you were to draw a circle using the measurements on the grid, with the chosen intersection at the center, then if the majority of a grid square lies within that circle, the square is part of the spell's area.” (DMG p. 69)

In the 3 in. radius circle on the next slide, is the majority of the shaded square in the cicle (in the spell's area)?

Page 39: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Calculus Example

Page 40: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Conclusions

Not exactly a recommendation for the industry! Very long working hours (“crunch time”), very

volatile, hit-driven industry See “EA Spouse” blog posts Also: Limited lifespan of the media works/ systems/

platforms

Page 41: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

Conclusions

Consider the instersection of: (1) What are your talents/joys, and (2) What will help/satisfy people the most.

I bet: You'll use everything you know.

Page 42: You'll Use Everything: Mathematics in the Gaming Industry Mu Alpha Theta Initiation Daniel R. Collins May 27, 2015.

The End

Thank you! Contact:

[email protected] deltasdnd.blogspot.com