Example #1
0
        /// <summary>
        /// 获取到所属于的块;
        /// </summary>
        public RectCoord GetChunk(CubicHexCoord coord)
        {
            short x = (short)Math.Round(coord.X / (float)width);
            short y = (short)Math.Round(coord.Y / (float)height);

            return(new RectCoord(x, y));
        }
Example #2
0
        CubicHexCoord NorthEastAdge(CubicHexCoord coord)
        {
            int x = coord.X + width / 2;
            int y = coord.Y + height / 2;

            return(new CubicHexCoord((short)x, (short)y));
        }
Example #3
0
        CubicHexCoord SouthwestAdge(CubicHexCoord coord)
        {
            int x = coord.X - width / 2;
            int y = coord.Y - height / 2;

            return(new CubicHexCoord((short)x, (short)y));
        }
Example #4
0
        /// <summary>
        /// 立方体坐标 转换成 像素坐标;
        /// </summary>
        public Vector3 GetPixel(CubicHexCoord hex, float y = 0)
        {
            float x = outerRadius * 1.5f * hex.X;
            float z = (float)(Trigonometric.Cos30 * hex.X + Trigonometric.Tan60 * hex.Y) * outerRadius;

            return(new Vector3(x, y, z));
        }
Example #5
0
        /// <summary>
        /// 获取到块内所有的点;
        /// </summary>
        IEnumerable <RectCoord> ChunkRange(RectCoord chunk)
        {
            CubicHexCoord center    = GetCenter(chunk);
            CubicHexCoord southwest = SouthwestAdge(center);
            CubicHexCoord northeast = NorthEastAdge(center);

            for (var x = southwest.X; x <= northeast.X; x++)
            {
                for (var y = southwest.Y; y <= northeast.Y; y++)
                {
                    yield return(new RectCoord(x, y));
                }
            }
        }