Repost. I got no replies in my original post.

Here is the relevant code:
//
// Find the rotation from v1 to v2
//
D3DXMATRIX Util::RotationFromV1toV2( const D3DXVECTOR3* v1, const D3DXVECTOR3* v2 )
{
// Find the rotation axis
D3DXVECTOR3 vRotAxis;
D3DXVec3Cross( &vRotAxis, v1, v2 );
// Angle of rotation
const float fAngle = (float)acos( D3DXVec3Dot( v1, v2 ) ) * DEG;
// Rotation quaternion
D3DXQUATERNION quat = D3DXQUATERNION( vRotAxis.x, vRotAxis.y, vRotAxis.z, fAngle );
// Rotation matrix
D3DXMATRIX rotMat;
D3DXMatrixRotationQuaternion( &rotMat, &quat );
return rotMat;
}
This does not give me the desired results. Depending on the direction of the vector I want to rotate it to, it will point backwards and/or the result will just be off. If I am rotating to a vector (v2) in the general vicinity of the original vector (that I am rotating from -- v1), it looks pretty damn close but the more v2 is pointing away from v1, the worse my results are.
Any thoughts? This problem has plagued me for a month at least now and none of my friends can figure it out either. This is keeping me from completing my game!
[edited by - beoch on October 16, 2002 11:59:54 PM]