Search Unity

Essential mathematics for programmers

Discussion in 'General Discussion' started by BIGTIMEMASTER, Nov 9, 2019.

  1. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Imho it's not different, math was born from observing nature, precisely the same curve we use in animation.

    What bother you is the notation, ie the tools iof the trade. You aren't familiar to them, so you can't think through them.

    But since you have assimilated the art skills if knowing the fundamental that drive the tools, you can think through them to get results.

    Look how hard it was to tell that one programmer in that one thread how to enhance is art...

    Also in art we only see what we know, you have to understand underlying abstraction to do stuff that are visually right. Anatomy and composition are key almost mathematical way to make sense of what you see. It's been notorious that people who don't have these abstraction have problems generalizing what they see and fo balanced visual. Just like when in old China studying nude was forbidden and all artist in that era struggled to make character that worked anatomically.

    It might not seems like it, but by observing, you use these abstraction to decompose, manipulate and recompose, just like in math, you think with primitive. Learning these primitive and internalizing them is the only difference.


    Also look for the Pixar course in Khan, it's rather complete and directed toward visual art, which you can generalize anyway, visual and physic overlap a lot in our field.
     
    BIGTIMEMASTER likes this.
  2. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
  3. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    I think this video might be describing well what you are lacking: "geometric intuition/understanding"




    I'm very bad at the calculation side, and some of the math examples posted in this thread so far are just as alien to me as they probably are to you, but I think I've got a pretty good grip on the "geometric intuition" thing, and combined with reading the API reference for math helper functions hidden in Mathf, Vector3, Quaternion and Float classes, I feel like I get by fine without ever really needing to touch the "calculation side" of math, which most math courses and videos likely would be overly focused on. But I have a hunch that the series created by the guy who made the video that I linked above, puts due focus on creating good visualizations for what these math things are all good for. Give it a try!
     
  4. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    @Martin_H this is precisely what I need.

    You're the man!
     
    Martin_H likes this.
  5. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Agree with @Martin_H - 'geometric intuition' is the main thing you need, not much formal maths.

    I've worked on almost every type of game code to a pretty proficient level, there is very little math in most of it. There is a huge amount of geometric thinking, especially when you get into procedural meshes and there is also some really basic trig.

    The two areas that IMO have the most math is detailed camera work and procedural meshes. Camera work generally tops off at basic trig. Procedural mesh gen can scale up to very complex math, but most common uses would generally top off in basic geometry and trig.

    There is a lot of "mathy" stuff: thinking in geometry, keeping track of what coordinate space you're working in (keeping track of relative direction or dealing with coordinate space transforms (local vs world for example)), rotating objects in your head, understanding basic vector ops like cross, dot, etc.

    Most of the complex math, you don't actually do yourself, you look up proper, fast implementations elsewhere. All you need to do is have a clear understanding of the goal so that you google the right thing.

    Geometric intuition is a very big deal, 'math' not so much.
     
    Martin_H likes this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Honestly not much math is required. Make the computer and other math nerds do all the heavy lifting.

    Basic arithmetic is going to be useful. You need to know about add, subtract, multiply, divide, exponents, roots and brackets. Mainly just so that you can know how to type a specific equation into the computer.

    Vector math is going to be essential. Most math in game development involves moving an object around in 3D space. Knowing how to do basic vector operations like addition, subtraction, normalization, length and dot product will all be useful.

    Trig can come in handy. Trig deals with triangles. And many problems in 3D space can be deconstructed into solving multiple 2D triangles.

    Linear algebra is useful, especially if you want to start getting into low level details. Distance between points and planes, vectors normal and tangential to planes, intersections of planes and so on.

    Calculus is almost certainly not needed. Unless you want to write your own fluid dynamics simulation, or do a complex heat diffusion model, its not worth touching. All of the basic calculus you will need for your game has already been solved, and you can look up the equations.

    Stats isn't needed to develop your game, but can be useful if you want to do data analysis on your players behavior once the game is launched.

    Machine learning and neural nets are just gimmicks that won't find application from the average game developer. Feel free to ignore them.

    I think that's everything. I learned math so long ago that its hard to decompose it down to the basics again.
     
    BIGTIMEMASTER likes this.
  7. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    I just watched 3blue1brown intro to neural networks and was like, yeah this has nothing to do with games, lol. At least not any games I'll be making.

    I gone through much of the linear algebra videos and find it easy to get as it relates similar to what you are doing when modeling.
    I think I need to look at trig a bit because I do recall seeing a bit done in tuts that involved triangles.

    I think next step is to visit the cat like coding tutorials in which they focus on building visual representations of the math. That should help make ideas I am getting from 3blue1brown more concrete I think.

    Fun stuff! Kind driving me crazy that I can't get on my computer and try things out.
     
    Martin_H likes this.
  8. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    I sometimes are lazy and setparent to some caluclation and then unparent just to be able to work in local space. I wouldnt do it were perfomance is needed though. Tricks like that can save alot of time

    Code (CSharp):
    1.         private void BegunAttachMagazine(InteractableMagazine magazine)
    2.         {
    3.             if (!firearm.NetworkedFirearm.IsOwner) return;
    4.  
    5.             firearm.MagazineEntryDetector.transform.localRotation = Quaternion.identity;
    6.             magazine.transform.SetParent(firearm.MagazineEntryDetector.transform);
    7.  
    8.             var minDelta = float.MaxValue;
    9.             var targetRotation = Quaternion.identity;
    10.  
    11.             for (int i = 0; i < BulletContainer.Capacity; i++)
    12.             {
    13.                 var rotation = Quaternion.Euler(0, 0, i * bulletAngleDelta);
    14.                 var delta = Quaternion.Angle(magazine.transform.localRotation, rotation);
    15.  
    16.  
    17.                 if (delta < minDelta)
    18.                 {
    19.                     targetRotation = rotation;
    20.                     minDelta = delta;
    21.                 }
    22.             }
    23.  
    24.             magazine.transform.SetParent(null);
    25.             firearm.MagazineEntryDetector.transform.localRotation = targetRotation;
    26.         }
     
  9. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    This book :
    3D Math for Game Development by fletcher dunn

    Tends to be a really good intro to most areas of math and games development related math :)
     
    BIGTIMEMASTER likes this.
  10. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    You probably don't need the math, just the hundreds of sample code and tutorial around the net :D

    The problem is that how and the application are totally separate here, you don't need the math at all either, since now there is a lot of tools. It's best to look at when it used, it's a generic tool, the same algorithm do very different thing.

    Here is the thing, a lot of math can just be black box, you don't need to understand what's in the box, just to apply it. A common one is dot product for artist, you probably don't know how to do it, but you probably know what it does (return 1, 0 or -1 based on difference of angle of two vector) and when to apply it (light calculation mostly).

    I mean the dot product in itself has nothing to do with light, knowing the dot product does not tell you anything about light, you can't look at it and guess "yess that's how I do light", it's agnostic, turns out that neural network ARE dot product too, so it your supermarket ticket! It's just a bunch of mad (multiplication addition), madness sure ensue!

    So the proper way to assess math, is:
    1. what are the use, the application and the problem it solve for me
    2. what it does, what are the input and the output, how to use it
    3. inside the black box, how it work

    Math is mostly important, as 3, when you want to solve unsolved problem, there you have to start from scratch and build up toward 1, which is the stated goal. Just like drawing you will have to get a "geometric" understanding of the problem (3), then figure out what representation and primitive you need (2) then how to obtain such primitive using the fundamental of math (1).
    For example you can see me doing a lot of 1 and 2 there: https://forum.unity.com/threads/inf...e-using-wrapping-grid-tracing-attempt.593233/
    And mostly failing at 3 :p
    But even though I'm kinda failing, I know where and how, and I have to be lucky to find some math guy to help me on the last miles.
     
    koirat, Kiwasi and BIGTIMEMASTER like this.
  11. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Highly debatable, they have been successfully in use before the deep learning craze, and they simplify a lot of specific task. It's like saying 3D is gimmicky and useless to the average developer, which is factually true in the abstract. :p
     
    iamthwee likes this.
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    I think AVERAGE here is a key word. Average Joe is not going use Deep Learning for their project. Unless there will be out of box solution, with drag and drop. Which is not there yet.

    Myself I love NN and I may consider implementing it, if time is right. But I will review the alternatives first too. Weather I am average Joe that different matter.
     
  13. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    2,149
    I'm just gonna throw this out there because I'm not sure if it has been mentioned.

    But before the OP gets deep into this I was wondering. . .

    Isn't this game a bit ambitious. I mean it is literally an open world game right? These are insanely difficult to get right especially with little to no programming experience. Because it is open terrain in all directions the protagonist (dog) can literally go anywhere. Unity's nav mesh ain't gonna cut it for enemy agents, surely you're going to need some advanced AI for the agents.

    What's the story, is the dog gonna just run through the forest, how does the player know where they are going? Is there some sort of path, what are the objectives, trials? With TBHC it was scoped reasonably. You can only move on the tiles right, left /right forwards backwards? This makes considering gameplay and trouble shooting way easier.

    Also, I think you've got into the graphics way too soon, before you even have a viable mechanic and game that you know people think is fun. Don't get me wrong, as an artist it is easy to lean towards this, but without a solid foundation, I'm talking low poly untextured agents and maps it isn't really going anywhere.

    The game certainly has the look and feel of something like https://www.thelongdark.com/ but this project is likely to be shelved sheerly from the scope of it IMHO. I would scope this one down, wayyy down, or is this just as a learning experiment??
     
  14. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    Concerns noted but it's off topic and too lengthy anyway to explain all the reasonings.

    I will say, I am not trying to do the programming. I just need to make a few scripts for a cinematic.demo.
     
    iamthwee likes this.
  15. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,073
    I have started to write some list but it started to grow quickly so I stopped.
    From my perspective/experience game programming is all about Math and Physics.
    Those are going to be your hardest problems.


    My unfinished list...
    Vectors basic operations + cross/dot products (why and when we use them) Atan2 (might be useful)
    vectors projection on vector(normalized and not normalized) projection on plane, vector reflection.
    matrix affine transformations, construction of transformation matrix, matrix multiplication order of multiplication.
    Complex numbers (might come in handy)
    Quaternions, rotations difference slerp lerp etc. order of multiplication for quaternions.
    Transformations from world to local space and reversed, for matrix and quaternions.
    Barycentric coordinates.
    Derivative/integration - especially for physics.

    Discretization!

    etc........
     
    iamthwee likes this.