#### Archived

This topic is now archived and is closed to further replies.

# Vector to Angles or something please?

This topic is 6045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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

• 39
• 15
• 9
• 23
• 10