Recommended Posts

Right now I''m calculating vector angles using dot product, like this:
vRL=D3DXVec3Length(&vR);
vSunL=D3DXVec3Length(&vSun);
fDot= D3DXVec3Dot(&vSun,&vR)/(vSunL*vRL);
fAngle=float(acos(fDot));
Is there a more efficent, faster or easier way...

Share this post

Link to post

Share on other sites

I don''t know of a faster way to get the angle between two vectors, but maybe somebody else does.

As to your other question, I''m not completely clear on what you''re trying to do, but you''re right that just getting the angle to your goal vector will not give you enough information to orient your ship properly.

As to what you should do, it depends on how your ship and its orientation are being represented, i.e. with a quaternion, a matrix, Euler angles, etc. One thing that might be useful to you is that even though the angle will be the same whether the goal vector is on your left or right, the cross product of the current direction vector and the goal vector will not, that is, the cross product will point in opposite directions depending on whether the goal vector is on your left or right.

Again, to tell you how to make use of this, we''d probably need to know more about your simulation.