• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Math in Graphics rendering / engines

## Recommended Posts

Hi guys, I''ve always struggled with the math side of gfx rendering etc...My coding skills are pretty good, I''ve been doing C++ for around 8 years now and work as a senior software engineer, but have always ''messed'' about with games coding from an early age. To cut a long story short, when I see all the math involved with coding a 3d game it always makes me feel like I''m not good enough to do a 3d game engine as I don''t understand all this math. Is it possible to code a 3d game with not much math knowledge ? Thanks in advance, Steve PS - I do try and learn more math but struggle with it.

##### Share on other sites
quote:
Is it possible to code a 3d game with not much math knowledge ?

No, unless you just build maps for an existing game.

There are a couple of books out there that deal with the "3d mathematics" part pretty good, though.

It IS heave - I did some 3d stuff 15 years ago, and now, cominb back for a hobby, I must say - well - I have a hard time, too.

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

##### Share on other sites
Yes, it is definately possible to make a 3D game with not much more than a bit of trigonometry, a small understanding of what matrices and vectors _represent_ (not necessarily how they work) and finally a decent maths library (e.g. D3DX) written by someone who does understand the maths...

...HOWEVER: you''ll never have a true understanding of what you''re really doing until you understand a little more of the maths. The truly great optimisations come from that knowledge, as does the ability to invent new things. Also there''ll be a moment when most things will "click" when the relationship between say trig and vector products is clear etc.

Realistically about A-level standard is all you need, with a few extra specialist topics relevent to graphics.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Try SOSMath.com.

##### Share on other sites
quote:
Original post by steg
Hi guys,

I''ve always struggled with the math side of gfx rendering etc...My coding skills are pretty good, I''ve been doing C++ for around 8 years now and work as a senior software engineer, but have always ''messed'' about with games coding from an early age. To cut a long story short, when I see all the math involved with coding a 3d game it always makes me feel like I''m not good enough to do a 3d game engine as I don''t understand all this math. Is it possible to code a 3d game with not much math knowledge ?

Steve

PS - I do try and learn more math but struggle with it.

If you''re good enough for C++, then you''re good enough for math!

The math required for 3D games is not the toughest on the planet. Maybe it''s not that you''re not a good mathematician, you just lack the confidence.

Sorry to sound like an auntie. :D

##### Share on other sites
Hm, well - for the pure 3d rendeing part, yes, but for things like collision detection and physics - a LOT of otherwise seldom used math IS a requirement.

It is hard - not impossible, just a different world.

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

##### Share on other sites
Thanks Guys for your comments, I much appreciate them.

I guess a lot of the math can be self taught ? I mean, most of my programming career has been self taught, I did do a degree in computing but we didn''t do too much math and they only taught us C.

Anyway, I''m going to do some math study, back to the begining with it, better to walk b4 running so to speak!

Thanks again,
Steve

##### Share on other sites
Contrary to "popular" belief, you hardly need any math knowledge at all.

Here''s all the major math stuff in my Software Engineering major from OIT, and whether I''ve used the concept in game programming:

Derivatives -- don''t need ''em
Integrals -- don''t need ''em
Vectors -- need them the most, and need to know all the tricks.
Matrices -- just need to know simple things about them.
Differential Equations -- not at ALL.

##### Share on other sites
quote:
Original post by thona
Hm, well - for the pure 3d rendeing part, yes, but for things like collision detection and physics - a LOT of otherwise seldom used math IS a requirement.

It is hard - not impossible, just a different world.

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Alot of things like collision detection and physics you can bluff. For instance I performed successful collision detection only using the Pythagorian Theorem (c^2 = a^2 + b^2) on boundeing spheres. I''m sure in not the only one to find this shortcut, amoung others. Game programming is not just being about a math nut, it''s about find easy and efficient ways of pulling off great effects.

##### Share on other sites
Well, I also have a mental block when it comes down to math, but I am getting there, I guess you just have to bash at it and read as much game math books, resources etc...

It bugs me when people understand the weirdest math stuff, like, how the hell do they understand that etc...

##### Share on other sites
Well, I also have a mental block when it comes down to math, but I am getting there, I guess you just have to bash at it and read as much game math books, resources etc...

It bugs me when people understand the weirdest math stuff, like, how the hell do they understand that etc...

##### Share on other sites
Mathematix : could you please tell us more about that Pythagora shortcut you found for spheres?

Also, there is a lot more to collision detection that spheres. Unfortunately, bullets (rays), players (ellipsoids), frustrums (pyramids), walls (planes), pong 3d paddles (polygons) are also part of it, and it gets harder and harder...

Derivatives / integration : euler''s method is widely used for ''easy'' integration of the laws of movement, but it does indeed have serious limits (bouncing like mad when you hit a wall, or having your friction force turning into an oscillation) and there are much better solutions if you want a decent physics engine. To do that, you gotta learn about differential equations.

And understanding math gives you another point of view over the world... and it''s cool :-D

500x2

ToohrVyk
-------------
Extatica - a free 3d game engine
Available soon!

##### Share on other sites
quote:
Alot of things like collision detection and physics you can bluff.

No. A lot of things can bluff SOMETIMES. This will get a problem once you actually dont want to design your game around the limitations of your math understanding. Been there - tried :-)

Using shortcuts is nice, but once you need something more complicated (for example to integrate projectile flight paths), you pretty much get this shortcome slapped into your face :-(

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

##### Share on other sites
I am not very interested in theoretical maths and physics, but I know I need to understand a lot of it to be able to solve programming problems.

What I started doing back in high-school (I''m doing the last year of my bachelors atm), when I lost motivation in learning something I had to get through, was to try to apply it to gamedev. This has always helped me, not only on the motivation part, but also to _really_ understand the relevance of much of the theory.

If you can''t think of a way to use new theory in games, just try to make a function out of it (assuming its a formula of some sort), make it draw out the result and try changing the parameters. They started doing this at my university some years ago (using MathLab and even flash!) and they could see the results almost imediately.

As a poster said, you really limit yourself by not expanding yourself in maths and physics, and I think it is closely linked with motivation.

Now... how to apply Marketing 101 to gamedev...

Real programmers don''t comment their code, it was hard to write, it should be hard to understand

##### Share on other sites
Wow, lots of replies to my post on this topic ;-)

I''m using tutorials I find on the web to learn more about maths. I''m sticking to topics on vectors (displacement,scaling vectors etc..), matrices (transpose, identity, column matrix''s, homengeneous etc..), transformations etc., I think I''m finally clicking with some of the math I see in some of my graphic books, understanding the math notation the books use is a must, I mistakenly ignored this and got lost in a world of strange letters, knowing how matrix''s, vectors etc are written down in the math sense is essential to understanding any of the math in gfx books. Hey I even now know that if you transpose a matrix twice you get back to the original matrix (whether that be a column or row matrix). Obviously I have a lot to learn but am starting to get the taste of maths, each night when I have some spare time I read more on the topic and understand it.

Thanks again for all your great comments!

Steve

##### Share on other sites
quote:
Original post by ToohrVyk
Mathematix : could you please tell us more about that Pythagora shortcut you found for spheres?

Yeah, sure.

  bool EstablishCollision(translationCoords Spheres[])// Enter Pythagoras to determine if a collision has taken place!{	static bool bAlreadyNotified = false;	double		x_squared, y_squared, z_squared, hypotenuse_xy, hypotenuse_yz, hypotenuse_xz;	// Compute the squares of the differences between the spheres on each of the three axes.	x_squared = pow((double)Spheres[0].xcoord - (double)Spheres[1].xcoord, 2.0f);	y_squared = pow((double)Spheres[0].ycoord - (double)Spheres[1].ycoord, 2.0f);	z_squared = pow((double)Spheres[0].zcoord - (double)Spheres[1].zcoord, 2.0f);	// Compute hypotenuse for each of the three planes in 3D space.	hypotenuse_xy = sqrt((double)x_squared + (double)y_squared);	hypotenuse_yz = sqrt((double)y_squared + (double)z_squared);	hypotenuse_xz = sqrt((double)x_squared + (double)z_squared);	if((hypotenuse_xy <= SPHERE_DIAMETER) && (hypotenuse_yz <= SPHERE_DIAMETER) && (hypotenuse_xz <= SPHERE_DIAMETER))	{		if(!bAlreadyNotified)		// Notify on first instance of current collision.			return bAlreadyNotified = gbCollision = true;		return false;	// Once notified, return false even though collision has been detected.	}	else		return bAlreadyNotified = gbCollision = false;	// No collision occured.}

And it works.

[edited by - mathematix on March 6, 2003 2:32:20 PM]

##### Share on other sites
quote:
Original post by thona
No. A lot of things can bluff SOMETIMES. This will get a problem once you actually dont want to design your game around the limitations of your math understanding. Been there - tried :-)

Using shortcuts is nice, but once you need something more complicated (for example to integrate projectile flight paths), you pretty much get this shortcome slapped into your face :-(

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Too right, Thona. I should have made myself clear.

The point that I was trying to get across was that you should make algorithms as simple as possible.

##### Share on other sites
Exactly because I don''t understand 3d my last 6 months of programming have stayed completely in 2d math. The most I use are (sin, cos & tan), slope of a line (y=mx+b), the degrees and the pythagorean theorem.

- Valles

##### Share on other sites
quote:
Original post by Mathematix
[quote]Original post by ToohrVyk
Mathematix : could you please tell us more about that Pythagora shortcut you found for spheres?

Yeah, sure.

    bool EstablishCollision(translationCoords Spheres[])// Enter Pythagoras to determine if a collision has taken place!{	static bool bAlreadyNotified = false;	double		x_squared, y_squared, z_squared, hypotenuse_xy, hypotenuse_yz, hypotenuse_xz;	// Compute the squares of the differences between the spheres on each of the three axes.	x_squared = pow((double)Spheres[0].xcoord - (double)Spheres[1].xcoord, 2.0f);	y_squared = pow((double)Spheres[0].ycoord - (double)Spheres[1].ycoord, 2.0f);	z_squared = pow((double)Spheres[0].zcoord - (double)Spheres[1].zcoord, 2.0f);	// Compute hypotenuse for each of the three planes in 3D space.	hypotenuse_xy = sqrt((double)x_squared + (double)y_squared);	hypotenuse_yz = sqrt((double)y_squared + (double)z_squared);	hypotenuse_xz = sqrt((double)x_squared + (double)z_squared);	if((hypotenuse_xy <= SPHERE_DIAMETER) && (hypotenuse_yz <= SPHERE_DIAMETER) && (hypotenuse_xz <= SPHERE_DIAMETER))	{		if(!bAlreadyNotified)		// Notify on first instance of current collision.			return bAlreadyNotified = gbCollision = true;		return false;	// Once notified, return false even though collision has been detected.	}	else		return bAlreadyNotified = gbCollision = false;	// No collision occured.}

And it works.

<SPAN CLASS=editedby>[edited by - mathematix on March 6, 2003 2:32:20 PM]</SPAN>

This is a perfect example of how not fully understanding the math principles results in inefficient code. What you''re doing here is a distance check between two spheres. Here''s a shortened version of your code.

    bool EstablishCollision(translationCoords Spheres[])// Enter Pythagoras to determine if a collision has taken place!{	static bool bAlreadyNotified = false;		double		x_squared, y_squared, z_squared;		// Compute the squares of the differences between the spheres on each of the three axes.		x_squared = pow((double)Spheres[0].xcoord - (double)Spheres[1].xcoord, 2.0f);		y_squared = pow((double)Spheres[0].ycoord - (double)Spheres[1].ycoord, 2.0f);		z_squared = pow((double)Spheres[0].zcoord - (double)Spheres[1].zcoord, 2.0f);		// Compute hypotenuse for each of the three planes in 3D space.		if((x_squared + y_squared + z_squared) <= pow(SPHERE_DIAMETER, 2.0f))	{				if(!bAlreadyNotified)		// Notify on first instance of current collision.			return bAlreadyNotified = gbCollision = true;				return false;	// Once notified, return false even though collision has been detected.		}		else				return bAlreadyNotified = gbCollision = false;	// No collision occured.}

Although using doubles and the pow function are inefficient as well and you''re assuming all the spheres are the same size.

##### Share on other sites
--> Graphics Programming and Theory.

##### Share on other sites
grrr!! can''t edit. Anywho change

if((x_squared + y_squared + z_squared) <= pow(SPHERE_DIAMETER, 2.0f))

to

if((x_squared + y_squared + z_squared) <= SPHERE_DIAMETER_SQUARED)

P.S. My last post seemed a bit snooty. I apologize. Just wanted to point out how yes it is possible to program graphics without a lot of math knowledge but understanding the math can make a huge difference.

##### Share on other sites
This may help...

The Tyr project is here.

##### Share on other sites
Don''t worry. If you can handle c++ you surely can handle math, ecpecially vectors and matrices are really not that hard.
And it should not be a super big problem to read yourself. Just try to find some excercises with solutions and calculate them by hand.
You need to know almost no math at all in the beginning of 3d programming. I know quite some math but have used almost nothing so far (I''m just a beginner with openGl).

/Andreas

##### Share on other sites
quote:
Original post by OctDev
This may help...

The Tyr project is here.

I haven''t read this book, but looking at the page excerpts I see the _one_ thing that drives people away from mathematics books:

quote:

page 6. "Now for an important theorem that reveals the ubiquitous utility of the dot product."

Not hard to understand, after looking up like 10 of those words in a dictionary. Why the heck didn''t he just say:

"And now I''ll explain how the dot product of vectors can be used!"

Oh, I see, that wouldn''t make him sound smart enough.

##### Share on other sites
Ronin Magus:

Some of the language used in maths books is important to ensure standard terminology is used, but I agree, that example you posted is terrible.

Personally I like the maths refreshers and appendices in "Realtime Rendering" for getting the important things across without using overly stuffy language.

Another book I''m a fan of (when combined with other books...) is "Mathematics for Computer Graphics Applications"

I think all technical authors should read Jim Blinn''s books ("A trip down the graphics pipeline", "Dirty pixels" and "Notation Notation Notation") to see how complex topics can be presented in a friendly, easy to read way.

4x500

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627654
• Total Posts
2978447

• 10
• 12
• 22
• 13
• 33