Maths and programming

Community Forums/General Help/Maths and programming

QuickSilva(Posted 2009) [#1]
I have come to the conclusion that the main thing holding me back when creating games is my poor knowledge of Mathmatics.

Can anyone direct me to a good resource that will help me to understand the basics that I need to know for a 2D game without confusing me even further as most of the sites about Math seem to do.

Are there any recommended books or other resources out there?

What sort of level of Maths would be adequate for me to get a good grasp on things?

Cheers for any help, I feel really stupid now but I was just never really taught these things at School which I regret now. I hope that it`s not to late to learn.

Is Mathmatics really as hard as I am making it out to be?

How many people here have made successful games with limited Math knowledge. Is it even possible?

Jason.


*(Posted 2009) [#2]
I too am crap at math, the max I know is sin and cos to do circles or calculate angles, if you would like I could post me routines to get angles etc?


xlsior(Posted 2009) [#3]
The kind of math you need greatly varies by the kind of game you wish to create -- whether you'll be dealing with directional vectors, pathfinding, A.I., geometry, chance distribution, differential equations, physics, sin/cos for attack patterns or circular movements, etc.

There's a world of difference between writing a game like Pacman and a game like Peggle -- likewise, so is the math involved.

As far as "Is mathematics really as hard as I am making it out to be" is concerned: It depends. Personally I find certain types of math very easy, but have a hard time with things like differential equations and integrals or things like calculating intersections in a 3D space -- luckily you don't need those for most 2D games.
There's also plenty of areas where you don't need to know everything, but just a little bit of knowledge is enough to get you by, with some trial-and-error.


InvisibleKid(Posted 2009) [#4]
quite awhile ago Warpy mentioned something about possibly doing a 'math for games' type tutorial if there was enough interest, but i haven't seen or heard anything about it since. he seems to be busy with his story type game right now, and i don't plan on bugging him.

but i think if someone (doesn't matter who) thats good with this type of math(s) had the time to write up such a tutorial in a way that can best describe to someone who might be new to programming ie. with pleanty of discription/explanation comments for each function/method, and possibly being made a sticky say in this forum, then i think the whole community (new comers or not) could benifit from it.

if i was better at this type of math i'd do it, but sadly i'm not.

i know theres other sources out there, but most that i've seen either don't explain good enough or over complicate it imho.

@ QuickSilva
to answer a couple of your questions.

1. i don't think math is hard (for the most part), its just that some people pick it up and understand it better then others.

2. i'm sure there has been many successful games made with just basic math, but basic math alone may/may not limit certain things you could do. having the knowledge and understanding the use of more advanced maths could/would definately help out though.

just my 0.02 worth


QuickSilva(Posted 2009) [#5]
@ EdzUp(SD) :
Yes please, that would be most helpful :) I find Trig especially hard.

@ KingNothing :
I would love to see a Maths tutorial, hopefully someone can put one together at some point like you say. I`m sure many others here are in the same boat as me.

Jason.


*(Posted 2009) [#6]
Here ya go:
'----------------------------------------------------------------------------------------------------
Function Percentage:Double( MaxValue:Long, CurrentValue:Long )
	Local Per:Double = MaxValue/100
	
	If CurrentValue = MaxValue Return 100
	If Per<=0 Then Return 0
	
	Return Float( CurrentValue /Per )
End Function

'----------------------------------------------------------------------------------------------------
Function IsOdd:Int( value:Long )
	If value =0 Then Return 0
	
	If ( value Mod 2 ) <>0 Then Return 1 Else Return 0
End Function

'----------------------------------------------------------------------------------------------------
Function AngleDistance:Float( CurrentAngle:Float, NewAngle:Float )
	'returns the distance between two angles
	Local temp:Float = NewAngle - CurrentAngle
	
	Return Temp + ( ( Temp < -180.0 ) - ( Temp > 180.0 ) ) * 360.0
End Function

'----------------------------------------------------------------------------------------------------
Function FindAngle:Float( x1:Float, y1:Float, x2:Float, y2:Float )
	'returns the angle To a target
	Local ReturnedAngle:Float = ATan2( x2 -x1, y2 -y1 )
	Return 180-ReturnedAngle
End Function

'----------------------------------------------------------------------------------------------------
Function Distance( X:Float, Y:Float, Z:Float, X2:Float, Y2:Float, Z2:Float )
	Return Sqr( ( x# -x2# ) *( x# -x2# ) +( y# -y2# ) *( y# -y2# ) +( z# -z2# ) *( z# -z2# ) )
End Function


The code is for BlitzMax but it should be easy to convert to Blitz3d/+


Warpy(Posted 2009) [#7]
ok, right, there's clearly a lot of demand for this and my game's going nowhere currently.

My time's at a bit of a premium these days though so would people be willing to donate on paypal or even pay outright for a good series of maths tutorials?


QuickSilva(Posted 2009) [#8]
@ Edzup :
Thanks for the code, most appreciated.

@ Warpy :
I would be more than willing to pay a small amount for an interactive 2D game focused Maths tutorial.

The things that I would like to see would be similar to the sin\cos example that comes with Blitz 3D where sin\cos etc... are visually shown to the user. I find this sort of visual learning much easier (probably because I`m an artistic person.)

Of course, if you could integrate a few graphics in to it would make it a lot more appealing :) Nothing too complex but relevant stuff that needs to be learnt for the average game.

Please do let us know if you decide to do this, maybe you could make a worklog for it?

Jason.


Blitzplotter(Posted 2009) [#9]
@EdzUp, I like your code!


Sauer(Posted 2009) [#10]
http://www.amazon.com/exec/obidos/ASIN/1556229119/

This is the text book we use at school, it covers just about everything you'd ever need to know about 3d mathematics. A lot of the concepts can be applied to 2d as well.


*(Posted 2009) [#11]
QuickSilva, Blitzplotter: Your free to use it any way ya want, just put me in the credits ;)


N(Posted 2009) [#12]
I'd also recommend the book Sauer linked, if only because I still use it after having it for several years.


Ross C(Posted 2009) [#13]
*Adds to amazon wish list*


*(Posted 2009) [#14]
yup me too


Pete Carter(Posted 2009) [#15]
another one almost the same

Good book


Htbaa(Posted 2009) [#16]
I've got this book, but I'm very frustrated with how all the examples are in pseudo-code. I would've preferred it when a real programming language would've been used. Also, the example code is for something called Lingo or whatever, which is some old product from Macromedia which I can't find any trial of anymore.

But nonetheless I did manage to translate some of the examples to actual code. After a reread of the first chapters all became a lot more clearer to me.


Vilu(Posted 2009) [#17]
I too suck at math, yet my game project already contains a lot realistic physics. Things like rotational kinetics and energy transfer on elastic collisions were pretty much unknown to me before I decided to incorporate them into the game.

It's not that you have to have the actual knowledge of how to calculate linear acceleration or how to rotate vectors etc. It's more that you should have a basic understanding of how you can simulate any scenario, movement or event in a mathematical language. Pretty much all you have to know is that you can present physical location as coordinates, directions and velocities as vectors, and have a feel for basic trigonometry. Google can do the rest for you. The equations themselves are relatively easy to find, if you know your problem and that there might be a mathematical solution for it.


Warpy(Posted 2009) [#18]
"I suck at maths" is pretty subjective. For example, I suck at statistics, but my day job is to explain it to undergraduates.

I've been trying to think of a way to start writing these maths articles, but I've failed. Somebody give me a subject they don't understand, and I'll have a go at that first.


Vilu(Posted 2009) [#19]
The problem with all-encompassing math books is that there really is a difference between 2d and 3d maths, although some of the stuff can be applied to both.

In 2d world you can get by using simple trigonometry, but throw in a third dimension and you'll do a lot better if you know how to use quats and matrices.

There's a starter subject for you, Warpy. :)


CS_TBL(Posted 2009) [#20]
That IsOdd is a bit excessive, no? :P

Function IsOdd:Int(a:Int)
	Return a&1
End Function


Or

If a&1
  'is odd
Else
  ' is even
Endif



QuickSilva(Posted 2009) [#21]
@Warpy : Let me have a think about it and I will get back to you shortly.

Jason.


*(Posted 2009) [#22]
CS_TBL yes thats true, but this is the way I got round it :)


InvisibleKid(Posted 2009) [#23]
i just saw THIS LINK
with a directory of free mathematics e-books posted at indie gamer, and figured that i'd post it here for anyone interested. i haven't checked any of the PDF files out yet, but theres alot of links in the directory so i'm sure theres bound to be useful information there.

anyway happy reading and hope it helps out.


Warpy(Posted 2009) [#24]
KingNothing - that looks fascinating to me, thanks! I doubt it'll be very relevant to game-programming though, from a quick look at the titles it all seems like very grown-up maths.


... Actually, this one caught my eye and might be quite useful indeed, as a starter.


QuickSilva(Posted 2009) [#25]
@KingNothing : Looks way over my head but thanks for the link anyway.

Jason.


InvisibleKid(Posted 2009) [#26]
@QuickSilva
ya alot of it is probably over my head and others as well, but none the less there seems to be a lot of information there for anyone who is interested in trying to improve their math skills/knowledge. i definately plan on sifting through it over time, although i haven't yet looked at any because for what ever reason my browser won't display pdf file links properly anymore and realy don't feel like downloading them right now. hell several years ago now, i picked up 'BASIC TECHNICAL MATHETICS WITH CALCULUS' 6th Edition i believe it was from 95 so fairly old now but still interesting. even though skiming through it from time to time i can grasp and understand alot of it in theory but i've never been able to take that and use it for programming because it wasn't described in such a way, granted i've only done brief skimming over some of the formulas from time to time but never realy sat down and tried to drill it into my head.

@Warpy
ya i agree with you that most of that is probably not too relevant to games programming but my post to QuickSilva explains why i still think its good for people to checkout plus in the POST at indie gamer the person mentioned Physics, Geometry so i thought hey cool people would definately be interested in that.

but like i metioned at the top of this thread i'm realy looking for a good book/tutorials for math for games programing. atleast something with the most commonly used and useful functions/methods. all this done in a way thats good for someone just getting into programming because its easy for someone who has been programming for atleast a little while to look at a peice of code dumbed down and understand it. but for someone just starting out and seeing code like EdzUp posted above (although pretty straight forward to most of us here and some pretty decent code btw) could and probably would be very intimidating.

i think something along these lines would be good.
rem
atleast 2-3 lines describing what the following function does ie get distance between 2 objects
maybe 1-2 lines with examples of use ie finding out if a target is in range,
fire missle/bullet from point a to point b, etc..
endrem

Function GetDistance(x1#,y1#,x2#y2#...)
    'discription of what x1#,y1#,etc.. are used for

    insert code here along with discriptive remarks on what this is doing and what that is doing
EndFunction


basicly imho to be most effective across the board for both new comers and people who've been programming for any length of time, i think it needs to be dumbed down and simplyfied with extensive commenting/remarks as much as possible.


Warpy(Posted 2009) [#27]
OK, so how about I start a blog answering people's maths questions, and I keep a wiki alongside to organise the stuff I've already written?


QuickSilva(Posted 2009) [#28]
@KingNothing

Agreed, although I must say that it`s not from lack of trying on my part, I just have real problems with Math.

I recently saw a program about this subject and it said that some people are just naturals at Math whilst others need to be taught in other ways, for example, some people are visual learners and are better with diagrams and so on, others are more hands on and need to actually have a go to get things to sink in.

Sometimes I feel very stupid with regards to programming as I cannot understand simple things that people are trying to show me. It`s very frustrating and something that I am trying to rectify. Being artistic I can visualize what I want to do it`s just converting it into the Math I need.

I`m slowly starting to understand but it takes a lot of effort on my part to grasp things that may seem simple to others here who are good with numbers.

Seeing things dumbed down a little or just explained with the beginner in mind helps a great deal.

Jason.


Ginger Tea(Posted 2009) [#29]
my maths teacher when i was under 10 must have thought we were all destined to work in supermarkets that s/he chose not to teach us long division etc and gave us all calculators
by the time i hit big school the damage had been done and i was hopeless without a calculator in hand, even for simple 2+2=5 sums

yet i heard of a high level maths guy in uni via some random pub banter that can do all those silly symbol things with ease yet to do decimal maths he has to put a £ infront of it and treat it like money or hes lost


InvisibleKid(Posted 2009) [#30]
@Warpy
that sounds like a very interesting idea

@QuickSilva
yep its like i said up top some people just pick stuff like this up easier then others, but you should never feel stupid and the fact that your trying to learn and better your understanding is great and steps in the right direction. i have a bad habit of overcomplicating things, on more then one occasion i've had certain programming problems where i'd fuss over things for several days to weeks because i'm stuborn and like to try to do things myself and i hate bugging people for help. then after i get over my stuborness i'd finaly post for help and someone would post an example thats way more simplified then where i was taking it. but because i can be very thick headed at times and my mind was already in overdrive trying to overcomplicate things it would take anywhere from a little bit to a couple days for me to stop and say hey ok i get it. the point is sometimes the more complicated solution isn't always the best and sometimes the simpler the better and learning is always a good thing just learn at your own pace, don't try to rush it.

@Ginger Tea
in one of my older posts (about a math problem go figure) i had a little rant about how years ago my grade 12 math teacher didn't like me because i had long hair and gave me nothing but grief from day 1 through the whole semester, and ended up failing me just to be a dick. because of that it completely turned me off of math which i used to enjoy and to be honest now if i try to formulate something thats more complex then a certain level of math, it just makes me naucious. owel my fault for letting it bug me i guess.


QuickSilva(Posted 2009) [#31]
@ KingNothing:
Good advice. Thanks for the kind words of encouragement :)

@ Warpy :
Sounds like a great idea, go for it! I will definitely be interested in reading through it. If you need any help with ideas then just ask.

Jason.


Warpy(Posted 2009) [#32]
WarpyCodeMathsBlog


ZJP(Posted 2009) [#33]
Hi,
This one : http://www.amazon.com/Mathematics-Computer-Graphics-John-Vince/dp/1846280346

JP


Blitzplotter(Posted 2010) [#34]
.