Mar 15, 2013 at 6:22pm Mar 15, 2013 at 6:22pm UTC
I need to get a cannon to schoot on my target.
It is a 3d game.
I need to get 2 angles between the x,y and z of the cannon, and the target.
I can calculate 1 of the angles:
1 2 3 4 5 6
float getAngle2 (float x1,float y1,float z1,float x2,float y2,float z2)
{
float dist=sqrt(pow(x1 - x2,2) + pow(y1 - y2,2) + pow(z1 - z2,2));
float dist2=sqrt(pow(x1 - x2,2) + pow(z1 - z2,2));
return acos(dist2/dist)*180/3.1415926;
}
That's the angle on the y-plane.
But now I need to get the angles of the x-z plane.
Does anyone know how to do that?
Thanks in advance.
Last edited on Mar 15, 2013 at 6:26pm Mar 15, 2013 at 6:26pm UTC
Mar 16, 2013 at 12:48am Mar 16, 2013 at 12:48am UTC
It looks like your are getting the angle on xz-plane, try using asin
Mar 16, 2013 at 1:33am Mar 16, 2013 at 1:33am UTC
v_j w_j = |v| |w| cos \theta
> I need to get 2 angles between the x,y and z of the cannon, and the target.
¿2 angles?
Mar 16, 2013 at 9:24am Mar 16, 2013 at 9:24am UTC
Three not aligned points define a plane.
The angle between the vectors is in that plane.
As I see in your drawing, you want to compute the angle of the projections.
So simply project your vector.
w_j = v_j - v_k n_k n_j where `n_j' is the normal of the plane.