Archived

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

Cyelince

Vector to Angles or something please?

Recommended Posts

Cyelince    122
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 this post


Link to post
Share on other sites
v71    100
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

Share this post


Link to post
Share on other sites