Hey guys, I'm playing with DirectX and I am trying to make a ship fly from nav point to nav point. Which seems to work from the origin to any point I place, the ship flies to it. But if I start the ship at some point other than 0,0,0 my ship behaves like it's being flown by a drunken pilot.
Basically I am trying to calculate the angle between the ships direction vector, and the nav point to decide how many radians to turn the ship on that plane. Can any of you guys spot why the acos function doesn't return a 90 degree angle?
Knowing that vDirX is (1,0), vNavX is (0,0) and vDirY is (0, 0) and vNavY is (0,0):
D3DXVec2Normalize(&vNavX,&vNavX);
D3DXVec2Normalize(&vNavY,&vNavY);
float anglex = acos( ((vNavX.y * vDirX.y)+(vNavX.x * vDirX.x)) / (D3DXVec2Length(&vNavX) * D3DXVec2Length(&vDirX)) );
float angley = acos( ((vNavY.y * vDirY.y)+(vNavY.x * vDirY.x)) / (D3DXVec2Length(&vNavY) * D3DXVec2Length(&vDirY)) );
Why is acos returning me -1.#IND000 for both angles?
Thanks a lot guys if you can help me....
Basically I am trying to calculate the angle between the ships direction vector, and the nav point to decide how many radians to turn the ship on that plane. Can any of you guys spot why the acos function doesn't return a 90 degree angle?
Knowing that vDirX is (1,0), vNavX is (0,0) and vDirY is (0, 0) and vNavY is (0,0):
D3DXVec2Normalize(&vNavX,&vNavX);
D3DXVec2Normalize(&vNavY,&vNavY);
float anglex = acos( ((vNavX.y * vDirX.y)+(vNavX.x * vDirX.x)) / (D3DXVec2Length(&vNavX) * D3DXVec2Length(&vDirX)) );
float angley = acos( ((vNavY.y * vDirY.y)+(vNavY.x * vDirY.x)) / (D3DXVec2Length(&vNavY) * D3DXVec2Length(&vDirY)) );
Why is acos returning me -1.#IND000 for both angles?
Thanks a lot guys if you can help me....