Math in Graphics rendering / engines

Started by
23 comments, last by steg 21 years, 1 month ago
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...
Advertisement
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!
Click here to learn more
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)
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
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
Real programmers don't comment their code, it was hard to write, it should be hard to understand
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

If it isn't working, take a bath, have a think and try again...

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]
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.

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
quote:Original post by Mathematix
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.
--> Graphics Programming and Theory.

This topic is closed to new replies.

Advertisement