In 3d space where
(1,0,0) - right
(0,1,0) - up
(0,0,1) - forward
0 degree means that vector from two points is (0,0,1)
90 degree means that vector from two points is (-1,0,0)
180 degree means that vector from two points is (0,0,-1)
270 degree means that vector from two points is (1,0,0)
My algorithm for calculation angle between two points is as below (in fact I calculate angle between camera location position and camera look-at position:
float angle = calculateAngle(cam->GetCamPos(), cam->GetCamLook()) - d3d::DEGREE_90;
float calculateAngle(D3DXVECTOR3* baseVec, D3DXVECTOR3* targetVec)
{
D3DXVECTOR2 vDiff;
D3DXVECTOR2 baseVec2(baseVec->x,baseVec->z);
D3DXVECTOR2 targetVec2(targetVec->x,targetVec->z);
D3DXVec2Subtract(&vDiff, &targetVec2, &baseVec2);
D3DXVec2Normalize(&vDiff, &vDiff);
//the angle is calculated from +X axis where the center of coordinate system XZ is baseVec
if(!vDiff.y)
{
if(vDiff.x>0)
return 0;
else
return D3DX_PI;
}
else if( vDiff.y > 0.f )
return acosf(vDiff.x);
else
return (acosf(-vDiff.x) + D3DX_PI);
}
The results is as in the attached image:
[attachment=21083:issue0.JPG]
[attachment=21084:issue1.JPG]
Instead of angle 45-60 I have angle 4 degree, so something is wrong.
My input data GetCamPos and GetCamLook are from View Matrix. Their coordinates are also seen at the attached pictures (camera pos, camera target).
The aim is that when I press "D" ball is kicked straigt forward according to the view.
I suppose that algorithm is OK, however instead GetCamLook I should take another input data, however I don't know which one. Maybe GetCamPos + GetCamLook or something like that.