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)
This commit is contained in:
Michael Cook (mackal) 2018-03-06 23:01:25 -05:00
parent e5e779c064
commit b3ac1001c9
2 changed files with 21 additions and 0 deletions

View File

@ -242,6 +242,24 @@ int FloatToEQSpeedRun(float d)
return static_cast<int>(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

View File

@ -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);