Exemplo n.º 1
0
        /// <summary>
        /// Given a starting and destination hex direction, returns a multiplier you can
        /// apply to a radian velocity to rotate in the shortest direction to your target.
        /// </summary>
        /// <param name="from">The direction you are starting from</param>
        /// <param name="to">The direction you are heading to</param>
        /// <returns>-1.0f if clockwise is the shortest rotation to reach to, 1.0f otherwise.
        /// One of these is chosen randomly if from and to are opposites (e.g., north and
        /// south)</returns>
        public static float ShortestRotationDirection(HexDirection from, HexDirection to)
        {
            const float clockwise     = -1.0f;
            const float anticlockwise = 1.0f;

            var clockwiseDist = (from.Ordinal() - to.Ordinal()).Mod(6);

            if (clockwiseDist < 3)
            {
                return(clockwise);
            }
            else if (clockwiseDist == 3)
            {
                return((_rng.Next(2) == 0) ? clockwise : anticlockwise);
            }
            else
            {
                return(anticlockwise);
            }
        }