diff --git a/zone/position.cpp b/zone/position.cpp index 63c5b034f..38b92c77e 100644 --- a/zone/position.cpp +++ b/zone/position.cpp @@ -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; +} \ No newline at end of file diff --git a/zone/position.h b/zone/position.h index 30f8fcb1c..f422a5247 100644 --- a/zone/position.h +++ b/zone/position.h @@ -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