I've been learning trigonometry and I know it's used a lot in complex game programming for angles and other math, and for writing shaders. I'd love to hear where and how anyone here has used it in their projects, it would give me some ideas on how I will use it in my games, and also it would be really interesting to hear, and also it would be neat to see how people figure out more complicated mechanics with math (or easy, trig can solve simple stuff too of course). =) Feel free to throw some hard math at me, I understand sine, cosine, tangent, as well as there reciprocals and of course basic angle math like alternate inverse angles and stuff. Even if I don't understand all of it, I'd like to hear it.
When have you used Trigonometry in your projects?
- Edited
I wanted to give bullets a maximum range after which they would "die", and I wanted it to be a fixed percentage of the distance to the point at which its path would intersect the non-square viewport.
I started out by drawing triangles and using trigonometry to compute the unknown triangle parts.
But then I realized that what I really needed to know was the time it would take the bullet to reach the viewport boundary. I wrote the four d = v * t equations for the +x, -x, +y and -y axes, and then only needed simple algebra to get the answer I needed.
That probably doesn't count as using trigonometry. :wink:
I've had to use trigonometry a lot for IK related programming. The law of cosigns, the Pythagorean theorem (indirectly though atan2
), and too many angle comparisons :lol:
Outside of IK, most of the uses I've had for trigonometry is computing an angle from a 2D point on the unit circle using atan2
and comparing the angle difference between two vectors (3d or 2d) using dot
. I've also used cos
and sin
, with time as an input, to make an oscillating animation.