You are very much correct in your thinking that you shouldn't be using trigonometric functions where you don't absolutely need them. Particularly in cases where your calculation is using both a trigonometric method and its inverse (noting, as you do, that Matrix.CreateRotation*
uses sin
and cos
internally).
However, you need more than a single vector to accomplish what you are trying to do!
What Outlaw Lemur and Tiago Costa were pointing out in comments is that you don't get a rotation just by specifying a single vector. You need to specify that vector relative to another vector. Traditionally people just choose a fixed vector representing "up" - in XNA: Vector3.Up
.
So if you passed Vector3.Up
to your rotation method, you would expect to get no rotation at all.
But, even then, this is not enough to fully specify a rotation. If you picture the above system in your head, imagine you have an "up" axis that you are rotating into a new position. But you're still free to rotate around that new "up" axis. You need another vector to select a specific rotation around that axis.
For this, people typically choose "forward" or "right" or "left" (and Vector3
has these static properties as well, for XNA's right-handed coordinate system).
So with an "up" and a "forward" vector, you have fully defined the rotation of an object.
Now, the original question was: does XNA have a built-in method for creating such a rotation matrix? Yes it does. It also lets you simultaneously specify a translation. It's:
Matrix.CreateWorld(Vector3 position,
Vector3 forward,
Vector3 up);
(MSDN)
(And there's also CreateLookAt
, which does a similar thing for cameras.)