Mathematics for Game Development: What to Learn (And Why!)
Mathematics comes into play in many areas of game (and especially game-engine) development. This post will highlight what are the most useful areas and why they are important for developers.
Game Development vs Game-Engine Development
Game development and computer graphics are fascinating fields, which have been built historically by people who had to solve complex mathematical problems. Just think: how would you represent a 3D world in a 2D screen? And how would you create shadows, deal with complex shapes, render photorealistic images of moving water, to name a few examples? These are challenging problems which involve a lot of math.
However, in software development, the practice is to reuse existing code. There are existing libraries that allow a modern developer to leverage on a substantial body of existing and hard-earned knowledge.
In particular, game developers usually rely on game engines like Unreal, Unity, Amazon Lumberyard, and not so many others, that handle most of the details of 3D graphics and the physics of animations.
Actually, game engines have become so sophisticated, that the development of game engines has become a separate field to the development of actual games.
Math for using game engines
As a game developer you’ll be mostly relying on this kind of libraries. But, even to just use them, you’ll need to know some math.
Linear Algebra: Positions and Transformations
In a 3D world, the position of an object is described (not surprisingly) using 3 coordinates. A collection of 3 numbers is called a vector in .
In order to transform the position or orientation of objects, you’ll need to understand operations like 3-dimensional rotations and translations, which are handled by matrices and Linear Algebra. In the computer graphics literature, besides matrices, another mathematical object which plays the role of a special kind of matrix is also used frequently: quaternions.
Additionally, when loading a 3D model made by an artist, a lot of the data will be in so-called local-coordinates, but your 3D world will have a different coordinate system. So coordinate transformation comes into play, which is also handled by linear algebra.
Calculus and Numerical Methods: Movement
While Linear algebra is a clearly all-important subject, when we start adding motion to a 3D scene, things like acceleration and speed come into play.
While this might be actually mostly intuitive, knowing some calculus will help with translating ideas into code.
Calculus formulas by their own sake, cannot be translated into code without the help of numerical methods.
Nowadays, most of the numerical heavy-lifting is carried out by the game engines. So unless you want to modify a physics engine, or add a special feature to it, you probably don’t need to know much about this topic. Of course, a basic understanding of when things can go wrong with numerical methods (such as floating-point errors) would be useful.
Optimization and Discrete Mathematics: NPC characters
Another area where math comes into play is in the behavior of non-player-controlled characters.
They often need to interact with their environment in a certain optimal way (i.e. to maximize their gain in some cleverly-defined way). Finding maximums or minimums of variables is handled by optimization.
While you can rely on optimization libraries, some knowledge of optimization and discrete mathematics will be useful at least to pose the problems (i.e. knowing which function should we minimize). This is never a trivial choice, and it can have many implications on the behaviour of characters, and even in the computational tractability of the problem (some optimization problems can’t be solved in a reasonable amount of time, even with modern computers).
Statistics: Game Data Analytics
Another area that arises in game development is game analytics. In a few words, when the data collected from numerous gamers is analyzed in order to gain insights into how could the game be improved to retain existing gamers for longer.
This area is becoming increasingly important, given the rise of the in-game monetization that many companies are putting forth. Game data analytics here aims at maximizing both player satisfaction and revenue.
I’ve written about the math involved in data analytics and data science in this post. To put it in one word: statistics.
Math for game-engine development
Game engine development is a completely different activity. Actually, if you are a game-engine developer, chances are that you will never get to build and entire game yourself, but rather help to improve some specialized graphics routines to meet a particular requirement of AAA game studio which is looking to create some awesome new feature to differentiate themselves from their competition.
This area is, of course, where most of the advanced mathematics comes into play. Whatever was done, say, to render an ocean storm, needs to be done better and more efficiently. So this will imply two things: what kind of algorithms will you be coding, and how?
As for the how part, which we won’t discuss here in detail, let’s just say that it will involve some low-level C++ programming. However, it is not customary to have someone come with a perfectly-specified requirement, who only needs a master C++ programmer with deep knowledge of how graphics card work, tell you what to do. You’ll need to be aware of which graphics algorithms are out there, and that will involve some non-trivial math.
But which math should you pay attention to?
Numerical methods. They underpin important areas in graphics like lightning and fluid animations.
Computational geometry. Deals with handling the ever-increasingly detailed animated character models or objects in a scene.
As game development seeks to simulate a 3D world, many of the mathematical problems in game and game-engine development are closely related to problems that physicists and engineers have studied in relation to the study of our actual world.
Consequently, the mathematics that game (and especially game-engine) developers need to learn is related to some areas in applied mathematics that have already proved useful in physics and engineering.
If you are on the look for online courses in the mathematics of game development, and you are deciding between a DIY approach (based on blog posts or Youtube videos) or paying for an online platform, you might want to check out my guide of when it is worth paying for online courses