Advertisement

How math is used in game development?

Started by July 13, 2019 07:16 AM
15 comments, last by SiliconByte101 5 years, 4 months ago

Though I already have the knowledge on the fundamentals of  programming languages. Now, I wanted to know how could I apply this skill on developing games. Could you please give me some example that uses math, so that I could somehow understand how it is useful.

All examples use some "math" somewhere.

Do you mean puzzle games ? (like e.g. "2048") More game than math :-)

Or something more complex ? More math than game ...

Or something in between ? Some more specifications are welcome ...

Advertisement
1 hour ago, Zeus James said:

Though I already have the knowledge on the fundamentals of  programming languages. Now, I wanted to know how could I apply this skill on developing games. Could you please give me some example that uses math, so that I could somehow understand how it is useful.

Math is typically use everywhere in games. In fact games tend to be more math intensive than many other applications.  You have your basic matrix operations for graphics, You have quaternions  which are often used in character animation.  You have all sorts of procedural generation algorithms that use math, like the famous Perlin and simplex noise algorithms.  You have game physics, including collision. The list goes on......

And not only in 3D, other branches are used too. For 2D, I have an isometric world that I need to render, so where is tile (tx,ty) of the map at the screen? The reverse problem, user clicks at pixel (px, py) at the screen, which tile is that?

Other areas are path planning, how to get from current (cx,cy) to destination (dx, dy)? How to get there with minimal risk of enemy fire? How to walk to catch a moving target? In which direction to fire to hit a moving target?

Random numbers are used often too, I have 25% chance of hitting, so how strong must the opponent be to have a fair chance at killing the end-boss?

Scaling things is also math. I have men fishing, how much food is a fish such that I can sustain a group of 5 colonists with 2 men fishing? Increasing difficulty, food needs go up by 20%, how many men do I need then? By these calculations you can get a good idea of the challenges faced by the player before hand.

 

Rendering is pure math because an image is a 2D array of pixels and each pixel is a vector of channels (red, green, blue, alpha). 3D rendering is done by transforming the vertices in models from model space to screen coordinates while skipping things that are outside of the screen, clipping triangles that are too big and rasterizing the triangles that are visible into pixels. A pixel shader program can then define a math function taking the linearly interpolated and perspective corrected vertex data from the triangle and return a color for the pixel on the screen.

All programming is math.  A computer program is an algorithm.  An algorithm is a mathematical concept.  Compiled programs are just huge integers, all input is a set of integers, and all output is a set of integers and the computer is just a piece of hardware that performs a basic mathematical ?:{ℤ , ℤn}→{ℤm} mapping the program/input space into the output space.  A digital electronic computer is a manifestation of a single mathematical function in the integer domain.

Did you have a more specific branch of mathematics in mind so we can discuss a limited subset?

Stephen M. Webb
Professional Free Software Developer

Advertisement
15 hours ago, Bregma said:

Compiled programs are just huge integers

That's what I've been doing wrong! All of my compiled programs are long strings. One question though, how do you load the huge integer into memory to execute? This changes EVERYTHING!

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

You should be able to use Python, it has support for arbitrary precision integers.

 

EDIT: It may involve some math to get it to execute though.

Hmhm, it executes ... or not.

Mine usuallly not on the first try ... ?

6 hours ago, fleabay said:

how do you load the huge integer into memory to execute?

Ah, the von Neumann equation.  I have 16 GB of memory in my main dev machine.  It holds a single integer with 128 billion binary digits. The CPU and associated silicon implements a transformation function (which, if originally built using VMRL, could also be described by a single large integer and interpreted by a second siliconized function, so it is figuratively turtles all the way down). Once the function has calculated its output, the integer in memory is replaced by another.  The von Neumann equation is simply mi+1 = f(mi). It was a keen mathematical insight, but even as far back as Babbage and Lovelace, all computing was math. All of it.

Of course, you don't have to study this or know any math to make the magic lights change.  Every island has a different batch of cargo and its own cult to go with it.

Speaking of the turtles, the turtle on the bottom of the stack is the successor function. At some point, someone flipped the first on-switch on the first computer.  Fiat lux.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement