Tutorial Tuesday is going to be a (hopefully) weekly thing where I write a tutorial. On Tuesday.
All drawings were made in Microsoft Paint and are crappy.
This week is how to rotate one vector around another, one of the first problems I solved when working on 3D graphics and physics. I'm sure there's plenty of information out there on how to do this by some nerd using matrices, but I'm going to explain my process for solving it just using vectors.
First let's start with 2D, so we want to rotate the black vector a certain amount (rotation angle), to the orange vector.
Instead we'll use the tangent method. First we calculate the tangent (the green vector) of the black vector, which is simple in 2D the tangent X is negative Y, and tangent Y is X.
Now that we have the original vector and its tangent, calculating the new vector is pretty simple. It's the original vector times the cosine of the rotation angle plus the tangent vector times the sine.
Onto 3D, we have a black vector that we want to rotate around the blue vector, which is pointing straight up because that was the easiest to draw, but could be pointing any direction.
That's it for this week, if you liked or didn't like this tutorial consider supporting me by buying my album of games and leaving a giant developer tip. Tune in next week when I might write another of these things about something.