Esempio n. 1
0
        /// <summary>
        /// Returns an array of CubicHexCoords that form the straightest path from the given start
        /// to the given end. The hexes in the line are determined by forming a straight line from
        /// start to end and linearly interpolating and rounding each of the interpolated points to
        /// the nearest hex position.
        /// </summary>
        /// <param name="start">The CubicHexCoord representing the first hex in the line.</param>
        /// <param name="end">The CubicHexCoord representing the last hex in the line.</param>
        /// <returns>An array of CubicHexCoords ordered as a line from start to end.</returns>
        public static CubicHexCoord[] Line(CubicHexCoord start, CubicHexCoord end)
        {
            int distance = CubicHexCoord.Distance(start, end);

            CubicHexCoord[] result = new CubicHexCoord[distance + 1];

            for (int i = 0; i <= distance; i++)
            {
                float xLerp = start.x + (end.x - start.x) * 1f / distance * i;
                float yLerp = start.y + (end.y - start.y) * 1f / distance * i;
                float zLerp = start.z + (end.z - start.z) * 1f / distance * i;

                result[i] = new FloatCubic(xLerp, yLerp, zLerp).Round();
            }

            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// Returns the minimum number of grid steps to get from this hex to the given hex.
 /// </summary>
 /// <param name="other">Any CubicHexCoord.</param>
 /// <returns>An integer number of grid steps from this hex to the given hex.</returns>
 public int DistanceTo(CubicHexCoord other)
 {
     return(CubicHexCoord.Distance(this, other));
 }