The rotation matrix between two vectors can be found by taking the dot product, taking the arc cosine of that value, determining the cross product of the 2 vectors you are comparing, then finally creating the matrix using the angle and cross vector.
public static Matrix GetRotationMatrix(this Vector3 source, Vector3 target)
float dot = Vector3.Dot(source, target);
float angle = (float)Math.Acos(dot);
Vector3 cross = Vector3.Cross(source, target);
Matrix rotation = Matrix.CreateFromAxisAngle(cross, angle);
Posted in XNA.
– July 7, 2011