Vector to Angles or something please?

Started by
0 comments, last by Cyelince 22 years, 5 months ago
I''ve had this problem for some time now... When you have a 3D vector(normalized)...say D3DXVECTOR3 or something...and you want to convert the angle to yaw, pitch, and roll. So that you can make a 3D object "look" at another object or point in 3D space...How do you do that? Cyelince
Advertisement
void GetAngles( fVect V,float &fPan, float &fPitch )
{
float dx, dy, dz;
dx = (float)V[0];
dy = (float)V[1];
dz = (float)V[2];
if(dz > 0.0001f)
{
fPan = (float) -atan(dx/dz);
dz /= cos((float)fPan);
fPitch = (float) atan(dy/dz);
} else if(dz < -EPSILON)
{
fPan = (float) (__PI-atan(dx/dz));
dz /= cos((float)fPan-__PI);
fPitch = (float) -atan(dy/dz);
} else
{
fPan = 0.0f;
fPitch = (float)-__PI/2.0f;
}
}

try this fVect is an array of 3 floats

This topic is closed to new replies.

Advertisement