Make CRelAngle use [0,2pi] range

This commit is contained in:
Jack Andersen 2018-12-15 20:31:17 -10:00
parent 4352f0d4a9
commit e6265e3c81
1 changed files with 6 additions and 5 deletions

View File

@ -12,11 +12,12 @@ struct CRelAngle {
float angle = 0.f; float angle = 0.f;
static float MakeRelativeAngle(float angle) { static float MakeRelativeAngle(float angle) {
float absAngle = std::fabs(angle); if (angle == 2.f * M_PIF)
if (absAngle == 2.f * M_PIF) return 2.f * M_PIF;
return std::copysign(absAngle, angle); float ret = angle - std::trunc(angle / (2.f * M_PIF)) * (2.f * M_PIF);
float ret = absAngle - std::floor(absAngle / (2.f * M_PIF)) * (2.f * M_PIF); if (ret < 0.f)
return std::copysign(ret, angle); ret += 2.f * M_PIF;
return ret;
} }
CRelAngle() = default; CRelAngle() = default;