27

I'd like to get an idea what kind of math is typically necessary for 3D game engine programming? Any specific math (such as vector geometry) or calculation algorithms (such as fast fourier transforms), or is this all abstracted away with DirectX/OpenGL so that highly complex math isn't really necessary any more?

Alex
  • 75,813
  • 86
  • 255
  • 348
  • 4
    3D graphics programming requires a decent understanding of linear algebra. [Vector math tutorial for 3D Computer Graphics](http://chortle.ccsu.edu/vectorlessons/vectorindex.html) is by far the best resource for learning vectors and matrices. It is also interactive in that at the end of each section there's a test question to verify and seal the understanding of that topic. – legends2k Oct 26 '13 at 05:17
  • This question should be moved to one of the other Stack Exchange sites, such as Game Development or Math. (Not sure if that is right, as this question includes programming) – Andreas is moving to Codidact Aug 27 '17 at 14:19

4 Answers4

22

Linear Algebra! Lots of lots of Linear Algebra!

Here are just classes and example situations where you need them

  • Vector - position, velocity, normals
  • Matrix - transformations
  • Quaternion - rotations (great for bone animations)
  • Ray - projectile collision detection
  • Plane - projectile collision detection
  • Frustum - render culling
  • Sphere - render culling, fast collision test
  • Axis-Align Bounding Box - culling, collision tests, spacial partitioning
  • Oriented Bounding Box - collision tests
  • Convex Hull - collision, spacial partitioning
  • etc.

You should start with Vector and Matrix as they will be used everywhere in the engine (graphics, physics, AI, etc.)

Aleks
  • 1,177
  • 10
  • 21
21

Matrices, trig, geometry mostly and a bit of linear algebra

Take a look here http://www.essentialmath.com/

Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • 6
    And vectors, lots of vectors! – Marius Aug 24 '09 at 04:08
  • In fact, you can get rid of vectors, and there are certain important advantages to it. Tensors are nicer to work with. – ima Aug 24 '09 at 06:01
  • 7
    Vectors ARE first order tensors - there's no "getting rid" of them in favor of tensors. – duffymo Aug 24 '09 at 09:40
  • I left out vectors because it's a little confusing between c++ vectors (which are matrices) and physics vectors and geometry vectors – Martin Beckett Aug 24 '09 at 18:19
  • 1
    There is getting rid of matrices and vectors in favor of more abstract tensors and operators. Most importantly, it allows to define operations invariantly under basic transformations. When you throw in some physics to 3D engine, it greatly simplifies thin – ima Aug 25 '09 at 13:52
  • How precise does the trig need to be? I'm planning to do it with C, and C trig functions aren't really exact. [Hope I can find some libraries, I really don't want to make my own trig functions]. – Shambhav Feb 25 '21 at 14:25
6

For the most part linear algebra and computational geometry; Quaternions are used extensively and numerical analysis is necessary if you are working on a physics engine.

How much you'd use the stuff on a daily basis depends on what you are doing. If you are a graphics programmer, and therefore building the 3D graphics engine itself, then you would likely be implementing or maintaining implementations of class libraries and functions that actually do the math, so it would be relatively important to know the gory details. If you are using the library as client or working on another part of the game engine (AI, audio, UI, camera, etc.) then you will need to understand the math conceptually but you can certainly get away with not knowing how to implement a matrix inverse on a whiteboard off the top of your head.

Graphics APIs do not eliminate the need for someone to know this math; they are limited to drawing, so all the scene management and world simulation needs to be implemented outside the graphics API. Of course, there are middleware options there too but many studios roll their own systems.

There are a fair number of resources targeted at this market. For example, on Amazon there are books like 3D Math Primer For Graphics and Game Development, and there's probably a lot of stuff online too.

2

Complex math comes in to play, but most important is an understanding of the concepts behind such math and often not the math itself. So long as you understand how it all comes together, there are often helper methods for many of the calculations you will need. Of course that depends largely on the development platform you are using as well.

Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156
  • Do you have a suggestion for where to learn the concepts and how they apply to game programming. Most of the material I find jumps into teaching /how/ to do the math and not /when/ you should use it. – TheGeoff Dec 04 '12 at 03:56
  • @TheGeoff: 3D graphics programming requires a decent understanding of linear algebra. [Vector math tutorial for 3D Computer Graphics](http://chortle.ccsu.edu/vectorlessons/vectorindex.html) is by far the best resource for learning vectors and matrices. It is also interactive in that at the end of each section there's a test question to verify and seal the understanding of that topic. – legends2k Oct 26 '13 at 05:19