There seems to be a general lack of trig know-how on this thread..
I wrote this function for an aimbot known as 'ViperG' in a file that's dated june 24th, 2001
I've commented it and adjusted it a bit. You might need to swap some things, but this should help you understand the jist of what you're trying to accomplish..
[source lang="cpp"]
#define RAD2DEG (180 / 3.141592654)
void VectorAngles( float *vector, float *angles )
{
float tmp, yaw, pitch;
if (!vector[0] && !vector[1]) // no horizontal length
{
if (vector[2] > 0) // straight up
pitch = 90;
else
pitch = -90; // straight down
yaw = 0; // can't discern a heading with xy of zero
}
else
{
yaw = (atan2(vector[1], vector[0]) * RAD2DEG);
if (yaw < 0) // set yaw between 0-360
yaw += 360;
// get horizontal length of vector
tmp = sqrt (vector[0]*vector[0] + vector[1]*vector[1]);
// use horizontal length and vector[z] to get pitch
pitch = (atan2(vector[2], tmp) * RAD2DEG);
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
[/source]
To use this function you'd do
[source lang="cpp"]
...
float vector[3], angles[3];
// set your vector here
VectorAngles(vector, angles);
// angles now contains yaw/pitch euler interpretation of vector..
...
[/source]
Let me know if you have any further questions..