Added 'GetReciprocalHeading' to position.cpp/h

This commit is contained in:
Arthur Ice 2015-01-18 12:22:37 -08:00
parent 0aefc0453d
commit cc802f2e74
2 changed files with 33 additions and 0 deletions

View File

@ -222,3 +222,33 @@ bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &mini
return xcheck && ycheck;
}
/**
* Gives the heading directly 180 degrees from the
* current heading.
* Takes the EQfloat from the xyz_heading and returns
* an EQFloat.
*/
float GetReciprocalHeading(const xyz_heading& point1) {
return GetReciprocalHeading(point1.m_Heading);
}
/**
* Gives the heading directly 180 degrees from the
* current heading.
* Takes an EQfloat and returns an EQFloat.
*/
float GetReciprocalHeading(const float heading) {
float result = 0;
// Convert to radians
float h = (heading / 256.0f) * 6.283184f;
// Calculate the reciprocal heading in radians
result = h + 3.141592f;
// Convert back to eq heading from radians
result = (result / 6.283184f) * 256.0f;
return result;
}

View File

@ -99,4 +99,7 @@ float Distance(const xyz_heading& point1, const xyz_heading& point2);
float DistanceNoZ(const xyz_heading& point1, const xyz_heading& point2);
float ComparativeDistanceNoZ(const xyz_heading& point1, const xyz_heading& point2);
float GetReciprocalHeading(const xyz_heading& point1);
float GetReciprocalHeading(const float heading);
#endif