Hi all,
my ? is.is there a better way to calculate vector angles
than the code below?if u have a better way i would realy like to know.any help would be appreciated.take a look below.
void VectorAngles( const float *forward, float *angles )
{
float tmp, yaw, pitch;
if (forward[1] == 0 && forward[0] == 0)
{
yaw = 0;
if (forward[2] > 0)
pitch = 90.0;
else
pitch = 270.0;
}
else
{
yaw = (float)(atan2f(forward[1], forward[0]) * 180.0 / M_PI);
if (yaw < 0) yaw += 360.0;
tmp = (float)sqrt (forward[0]*forward[0] + forward[1]*forward[1]);
pitch = (float)(atan2f(forward[2], tmp) * 180 / M_PI);
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
my ? is.is there a better way to calculate vector angles
than the code below?if u have a better way i would realy like to know.any help would be appreciated.take a look below.
void VectorAngles( const float *forward, float *angles )
{
float tmp, yaw, pitch;
if (forward[1] == 0 && forward[0] == 0)
{
yaw = 0;
if (forward[2] > 0)
pitch = 90.0;
else
pitch = 270.0;
}
else
{
yaw = (float)(atan2f(forward[1], forward[0]) * 180.0 / M_PI);
if (yaw < 0) yaw += 360.0;
tmp = (float)sqrt (forward[0]*forward[0] + forward[1]*forward[1]);
pitch = (float)(atan2f(forward[2], tmp) * 180 / M_PI);
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}