### Re: XNA Framework Vector to rotation, ie - point models 'forward' to their direction.

NickMcCrea

There's really no difference between doing it incrementally and absolutely. All you would do is compare to an initial starting vector every time, instead of the last known heading vector.

Let's keep it to the XZ plane as you describe in the example above. So you start off heading right. Your heading vector is (1,0,0). Your model is being translated by a rotation matrix of 0 degrees (i.e., it's not being rotated - your default position).

So you suddenly change velocity to, say, (1,0,1) to fly diagonally up right. If you're only needing to fly in certain directions, you could just store the necessary rotation angles for these flying positions. So for a velocity of (1,0,1), you know to rotate the model 45 degrees. Not flexible, however. Probably too simple for your purposes.

What you need is two velocities to compare and work with. Let's say you were at (1,0,0) and moved suddenly to (1,0,1). You could just find the angle between them however you wanted - dot product of the vectors, trig, whatever.You certainly have enough info to work on. Dot product is easiest, however, there's supported methods for doing it. So, the dot product of two vectors returns the cosine of the angle between them.

You should notice that there's no difference in the result between (1,0,0) dot (1,0,1) and (1,0,0) dot and (1,0,-1). You'll just get back cos 45 in each case. So you need to know which direction you turn in when you apply rotation. If you're always aware of the relative direction of turn of your plane that's not so important, you'll be able to control the plus/minus of the rotation angle yourself as appropriate. But cross product is helpful in certain situations. It returns the vector perpendicular to two others. If you measured the dot product of your NEW heading with the two vectors perpendicular to your ORIGINAL heading, you could compare the two angles you get back. If one is smaller than the other, you've just turned more in that direction, so you know which sign to give the angle.