# Math?

## Recommended Posts

asdfghjkl1    107

What type of math do 3d game developers use on a daily basis?

#### Share this post

##### Share on other sites
lrh9    174

For physics you might need to do some integration (antiderivation). Basic calculus, but nothing to be afraid of.

l0k0    278
Linear Algebra

#### Share this post

##### Share on other sites
cr88192    1570

lots of vector math, followed by working with scalar floating-point math, lots of integer math, some occasional fixed point math or other oddities, matrix operations, possibly quaternions in a few cases, ...

if you know basic Algebra type stuff, and can basically understand with vectors, that is probably most of it.

so, yeah, maybe "Algebra" + "Analytic Geometry".

#### Share this post

##### Share on other sites
TheUnnamable    1129

Apart from that, a useful skill is being able to create formulas for various stuff. I use it to determine how does a light fade with distance, but the same thing can be used to determine splash damage, or you can create a formula to determine how much XP does each character level need to proceed, how much gold do you get given the monster's strength, etc. etc. If you can visualise a few formulas, it'll be fine ( power(x,n) - particularly square root and square, sin, cos, 1/x, I think you will be mostly fine with these ).

Also, linear interpolation, aka. lerp. Nothing fancy ( y=a+(b-a)*x ), but it can be incredibly useful if you know what it does. You can even play around with x and apply additional functions to it. For example, if you want to make it interpolate more smoothly, you can use (1-cos(x*pi))/2, if you want to make it interpolate "suddenly", you can use x^n. Some more complicated methods exist for interpolation, but I personally haven't used them that much.

Edit: The most basic vector math you might want to know is get a vector's length ( sqrt(v1^2 + v2^2 + ... + vn^n), where v's are the vector's coords ), direction ( see atan2 ), pitch ( atan2, but instead of atan2(y,x), you use atan2(z, veclen(x,y)), where z is up/down and y is front/back ), and do all of these backwards: to create a vector from direction, pitch and length:

//dir and pitch must be in radians ( 1 deg = pi/180 rad )
//If you are working in 2D, you might want to negate y to make y+ point downwards on the screen
x=cos(dir)*cos(pitch)*length
y=sin(dir)*cos(pitch)*length
z=sin(pitch)*length


To normalize a vector, you divide all of its components by it its length, and now you can easily represent a direction with it. You can for example add them up and normalize the result to get an average of the directions ( which could be more straightforward than using angles and mapping them, checking for overflows, etc. although I believe this is debatable ). Or you can check if one direction looks away from the other by taking their dot product and checking if it's negative ( when using normalized vectors, their dot product is the cosine of the angle between them ).

A lot of these tricks can be found with a proper understanding of the topics posted above.

Edited by TheUnnamable

#### Share this post

##### Share on other sites
Jeez. That looks complicated :(

#### Share this post

##### Share on other sites
Satharis    2444
If you're using that much math on a daily basis I think you have a code abstraction/reuse problem.

To be honest most of the time a lot of this math is already in library form for you anyway, its just helpful to know it so you can better apply it to situations or on the RARE chance that you need to write some kind of heavy math code.

At the very least though you should understand basic movement and interaction in 3d space, things like coordinates and vectors and basic geometric principles and all that, in terms of schooling its always trig/linear algebra at the least they'll recommend you learn.

#### Share this post

##### Share on other sites
axel1994    702

If you're using that much math on a daily basis I think you have a code abstraction/reuse problem.

To be honest most of the time a lot of this math is already in library form for you anyway, its just helpful to know it so you can better apply it to situations or on the RARE chance that you need to write some kind of heavy math code.

At the very least though you should understand basic movement and interaction in 3d space, things like coordinates and vectors and basic geometric principles and all that, in terms of schooling its always trig/linear algebra at the least they'll recommend you learn.

this depends on where you start from.

If you start from scratch, you'll need more math, than when you are going to use an engine.

Aren't most engine programmers and such (in the actual industry) engineers and computer scientists?

Edited by axel1994

#### Share this post

##### Share on other sites
lightxbulb    1164

What type of math do 3d game developers use on a daily basis?

Actually you may not need to use much math to be honest, it depends on what you're working with - you may have everything you need already in a library, if you elaborate on your question maybe people would be able to give a more precise answer. Otherwise, here are a few examples:

For all the coordinate system changes, movement, rotations etc. - matrices (and really transformation matrices mostly that are square and usually 3x3 or 4x4) - basically the basics of linear algebra - something that would take at most 1 month (for students in 1st year in uni I think). Now you may opt to use quaternions too in some cases. Nothing scary really, even if a person is not so great at math - it's mostly basics and not anything that goes too deep.

It may be useful to know what are polar and spherical coordinates and how to pass between Cartesian and polar/spherical coordinates(add to this barycentric and homogeneous coords if you want, though there's nothing much to learn there), something pretty trivial.

Some analytical geometry won't hurt, it will help you the most imo. It's pretty basic too and you don't really need all the small details, some basic vector math, dot and vector product, plane, ray, sphere equations etc.

These are pretty much all the basics I think you'd need, there's plenty of material on each of these on the net and it's really not that hard and most of the times you'd have most of the math done for you with the help of a library, but it never hurts to have some knowledge of what's happening and if you ever need to do something yourself.

Now if you want to do something harder, like make physical simulations you'd need some basic calculus, you should be able to solve differential equations etc. Here things may get a little more ugly, but it's not something that's as scary as it sounds, and you'll most likely not need to do this.

#### Share this post

##### Share on other sites
Bregma    9201

To be good, you can't know enough math.

Saying a computer programmer, especially a 3D game developer, doesn't really need to know much math is like saying a professional musician doesn't need to know anything about scales or rhythm or harmony or composition; all they need to do is be able to play like the guy in the You-tube video.

You need to know algebra: linear algebra (vectors, matrices, transforms and transformations, convolutions), set theory (groups, rings, orderings), combinatorics (permutations, combinations), graph theory, number theory (basis, generators, PDFs/CDFs/PRNGs, series and sequences). Error minimization when approximating real-valued functions using floating point or fixed-point representation.  Computability theory and algorithmic analysis.  Basic differential and integral calculus of arbitrary dimension is a prerequisite for an understanding of most physics.

If you don't like math, you may just be in the wrong trade.  Now, go and practice your scales.

#### Share this post

##### Share on other sites

Practice your scalars.

Some probability and statistics is good too, especially for AI or simulations.

Differentiation is also useful if you want to stitch together some curves together so they are smooth at the joins.

Also, the more you know the less you probably have to do yourself because you will know how to get the answer from Wolfram Alpha ;)

#### Share this post

##### Share on other sites
lightxbulb    1164
Saying a computer programmer, especially a 3D game developer, doesn't really need to know much math is like saying a professional musician doesn't need to know anything about scales or rhythm or harmony or composition; all they need to do is be able to play like the guy in the You-tube video.

It really depends honestly, you may be a 3d game dev and, with the abundancy of tools and engines nowadays, never have to go further than the basics when it comes to math. As you usually won't need to be a pro at composition if you're just a performer, the same way you don't need to be a professor in maths to be a 3d game dev. Math is merely a tool in game dev, of course it shouldn't get in the way, but nowadays(with all these "user-friendly" tools) you can make a 3d game with math knowledge from 8th grade.

The more math you know the better, but that certainly doesn't mean you can't pass up on math depending on your goals and the tools you use, and usually most of the things you would do have already been done and explained step by step, so even somebody with minimal math knowledge can manage. There's also the case when a guy starts delving deep into maths and learns all kind of things that he'll never ever need to use - remember your uni days, you surely have learned some things that you didn't need for tens of years. I would advise learning what you need now, as to keep a precise goal, rather than make maths your goal(lest you like it of course) - I believe you should look at math as a tool being a game dev.

P.S. Recently I got the chance to see some of the code of a relatively successful game, well I must say most things that had to do with math and didn't rely on library and tool implementations, looked pretty bad and the calculations and derivation of solutions to some of the problems were mostly inaccurate and more random than analytical(it was not the case of complexity/speed compromise) - I do not say that this is good, but the point is that you do not necessarily need to be really good at math to be a 3d game dev.

Edited by lightxbulb

#### Share this post

##### Share on other sites

To be good, you can't know enough math.

Saying a computer programmer, especially a 3D game developer, doesn't really need to know much math is like saying a professional musician doesn't need to know anything about scales or rhythm or harmony or composition; all they need to do is be able to play like the guy in the You-tube video.

You need to know algebra: linear algebra (vectors, matrices, transforms and transformations, convolutions), set theory (groups, rings, orderings), combinatorics (permutations, combinations), graph theory, number theory (basis, generators, PDFs/CDFs/PRNGs, series and sequences). Error minimization when approximating real-valued functions using floating point or fixed-point representation. Computability theory and algorithmic analysis. Basic differential and integral calculus of arbitrary dimension is a prerequisite for an understanding of most physics.

If you don't like math, you may just be in the wrong trade. Now, go and practice your scales.

You make it sound so complex. Doesn't pdf mean portable document format?

#### Share this post

##### Share on other sites
Lactose    11446

You make it sound so complex. Doesn't pdf mean portable document format?

3D graphics and maths can be quite tricky and complex. But most things are, until you learn them.

In this context, PDF probably (heh) means Probability Density Function.

http://en.wikipedia.org/wiki/Probability_density_function

#### Share this post

##### Share on other sites
BitMaster    8651

Considering the context it is far more likely Bregma is referring to [url=http://en.wikipedia.org/wiki/Probability_distribution_function]probability distribution functions[/url], not the file format.

#### Share this post

##### Share on other sites
jHaskell    1856

It really depends honestly, you may be a 3d game dev and, with the abundancy of tools and engines nowadays, never have to go further than the basics when it comes to math. As you usually won't need to be a pro at composition if you're just a performer, the same way you don't need to be a professor in maths to be a 3d game dev. Math is merely a tool in game dev, of course it shouldn't get in the way, but nowadays(with all these "user-friendly" tools) you can make a 3d game with math knowledge from 8th grade.

While there are plenty of libraries that provide all the nitty gritty capabilities for you in an optimized package, if you don't understand WHAT the libraries are doing and HOW they're doing it, you're going to find it extremely difficult to effectively use them.  Sure, you may be able to use them to put together some very basic scenes, but debugging unintended behavior will more than likely degenerate into just trying a bunch of different things to see what works properly, or coming to these forums to get help from those that do understand the underlying maths.  And putting together any reasonably complex behavior is going to require much more than 8th grade math knowledge regardless what libraries you're using.

#### Share this post

##### Share on other sites
lightxbulb    1164
While there are plenty of libraries that provide all the nitty gritty capabilities for you in an optimized package, if you don't understand WHAT the libraries are doing and HOW they're doing it, you're going to find it extremely difficult to effectively use them.

Not understanding what the library you're using does is already ridiculous whether it's math related or whatever, I for one wouldn't imagine a person using a library that he doesn't understand WHAT it actually does. As for not understanding HOW a library/tool does something, while I do not argue that it is useful knowing what's going underneath, it certainly it is not a necessity. Many of the details are abstracted from us as programmers when using a library/tool, whether it's math related or not, and you certainly don't need to know how everything works to be able to use it. And you are not going to find it extremely difficult to use a library/tool effectively without knowing it's whole internal structure lest that library/tool isn't user-friendly at all. There are plenty of examples for this.

Sure, you may be able to use them to put together some very basic scenes, but debugging unintended behavior will more than likely degenerate into just trying a bunch of different things to see what works properly, or coming to these forums to get help from those that do understand the underlying maths.

As I said not necessarily true in most cases, I can give you examples contrary to your statements for every one of them.

And putting together any reasonably complex behavior is going to require much more than 8th grade math knowledge regardless what libraries you're using.

I believe you haven't used libraries/tools of high enough level if you think that way, for example take a "programming language" like BlitzBasic 3D - I believe you'll be able to make even an 8th grader do a lot more than some people with a lot of math knowledge would be able to do wtih C++ + DX/OpenGL and  lot faster at that, it's another matter that the quality won't be the same. Still you have plenty of tools that are even not made for good programmers, you can surely skip a lot of the math at many occasions.

#### Share this post

##### Share on other sites
Could you scare me and list all/most of the needed maths (vectors, matrices, algebra etc.)

#### Share this post

##### Share on other sites
lightxbulb    1164
Could you scare me and list all/most of the needed maths (vectors, matrices, algebra etc.)

Here's what I needed most up till now(basics) when it comes to game dev:

Analytical Geometry:

- vectors: addition, subtraction, dot product, cross product, reflection

- plane equation, ray equation: intersections etc.

- polar coordinates, barycentric coordinates

- homogeneous coordinates

- 2nd order surfaces equations (sphere for example) - didn't really need all the details I once studied

Linear algebra - you really need to know only the basics:

- matrices: addition, subtraction, multiplication, inverse

- determinants

- Gram-Schmidt orthogonalization

Quaternionic analysis:

- quaternions - and rather mostly spatial rotations using quaternions

Can't really think of something that would require anything much harder when it comes to things that you'd stumble upon on a daily basis, however if you decide to delve even deeper let's say rendering equation, brdf, ray-tracing, physical simulations you may need tensors, calculus - usually whenever you see physics you'll need calculus, differential equations etc.

#### Share this post

##### Share on other sites

Linear algebra is also useful for learning about inner product spaces and from them orthogonal basis functions, which is what you use for Fourier transforms and related methods (used in compression) and Spherical Harmonics (used.for global illumination). It's about decomposing complicated functions into linear combinations of simple functions. The idea is that functions can be thought of as vectors given a suitable set of basis functions and from then they can be combined or interpolated in a simple manner. Although the number of elements in the basis is infinite (for complete accuracy) the most important elements are the low frequency components and you can just forget about the higher frequency coefficients and still get a good approximation to the actual function.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now