public static Movement GetMovement(float rotation) { rotation = SharpMathHelper.Loop(0, 360, rotation); const float HalfCoverage = 45; if (TestDirection(rotation, -HalfCoverage, HalfCoverage) || rotation > 360 - HalfCoverage) { // Right return(Movement.Right); } if (TestDirection(rotation, HalfCoverage, HalfCoverage * 3f)) { // Right return(Movement.Down); } if (TestDirection(rotation, HalfCoverage * 3f, HalfCoverage * 5f)) { // Right return(Movement.Left); } if (TestDirection(rotation, HalfCoverage * 5f, HalfCoverage * 7f)) { // Right return(Movement.Top); } return(Movement.None); }
private static bool TestDirection(float rotation, float start, float end) { bool TestDirection() => start < rotation && rotation <= end; if (TestDirection()) { return(true); } if (start < 0) { start = SharpMathHelper.Loop(0, 360, start); } if (end < 0) { end = SharpMathHelper.Loop(0, 360, start); } return(TestDirection()); }