## Monday, June 20, 2011

### Trigonometry and Why I'm Glad I Learned that Stuff

If you ever decide to go into games and more specifically programming or designing them, you should know that math is a pretty big part of what goes on there.  Specifically trig and linear algebra and how to move between them.  Vector seems to come up a lot, as do angles and all your favourite trig functions: sin cos and tan.

When I added my exhaust particles, I had to write a fair bit of math to get them behaving properly.  Check out what's required to make one particle:

((std::vector *) g->debris)->push_back(new Exhaust(X + width*cos(roll_*M_PI/180.0)- height*sin(yaw_*M_PI/180.0), Y - width*sin(roll_*M_PI/180.0) - height*sin(pitch_*M_PI/180.0), Z+.02, 0.02,-height*sin(yaw_*M_PI/180.0)/2 ,-height*sin(pitch_*M_PI/180.0)/2,-0.005,g,"spark.png", 30));

Sin and cos and a firm understanding of radians vs degrees are used pretty heavily in order to make them both appear in the right place and then move in the right direction.

It call comes together to make this:
 Math at Work!

-Liam