From b3ac1001c9fbcc711e3c56b7900b1945cb96f24c Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Tue, 6 Mar 2018 23:01:25 -0500 Subject: [PATCH] Add a FixHeading function This is similar to what the client is doing Should be used when adding 2 headings together (or an EQ angle to a heading) --- common/misc_functions.cpp | 18 ++++++++++++++++++ common/misc_functions.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/common/misc_functions.cpp b/common/misc_functions.cpp index aaa20f3d4..e31da211f 100644 --- a/common/misc_functions.cpp +++ b/common/misc_functions.cpp @@ -242,6 +242,24 @@ int FloatToEQSpeedRun(float d) return static_cast(d * 40.0f); } +float FixHeading(float in) +{ + int i = 0; + if (in >= 512.0f) { + do { + in -= 512.0f; + } while (in >= 512.0f && i++ <= 5); + } + i = 0; + if (in < 0.0f) { + do { + in += 512.0f; + } while (in < 0.0f && i++ <= 5); + } + + return in; +} + /* Heading of 0 points in the pure positive Y direction diff --git a/common/misc_functions.h b/common/misc_functions.h index 9ecb08378..8214c7df0 100644 --- a/common/misc_functions.h +++ b/common/misc_functions.h @@ -66,6 +66,9 @@ int FloatToEQ10(float d); float EQSpeedRunToFloat(int d); int FloatToEQSpeedRun(float d); +// brings heading back into EQ angles range +float FixHeading(float in); + uint32 SwapBits21and22(uint32 mask); uint32 Catch22(uint32 mask);