Exemplo n.º 1
0
            /// <summary>
            /// 对房间进行初始化, 即生成房间内节点列表与边界节点列表
            /// </summary>
            /// <param name="map"></param>
            /// <param name="floorType"></param>
            /// <param name="boundryType"></param>
            /// <param name="minDistanceToMapEdge"></param>
            /// <returns></returns>
            public Room Init(Map map, Properties floorType, Properties boundryType, int minDistanceToMapEdge = 1)
            {
                nodes = nodes ?? new List <Node>();
                nodes.Clear();
                VectorInt diagonal = bounds.Diagonal;
                VectorInt pivot    = bounds.pivot;
                int       EndI     = Math.Min(diagonal.x, Math.Max(0, map.LengthX - 1 - minDistanceToMapEdge)),
                          EndJ     = Math.Min(diagonal.y, Math.Max(0, map.LengthY - 1 - minDistanceToMapEdge)),
                          EndK     = Math.Min(diagonal.z, Math.Max(0, map.LengthZ - 1 - minDistanceToMapEdge));

                for (int i = pivot.x; i <= EndI; i++)
                {
                    for (int j = pivot.y; j <= EndJ; j++)
                    {
                        for (int k = pivot.z; k <= EndK; k++)
                        {
                            Node n = map[i, j, k];
                            if (n != null)
                            {
                                n.SetProerties(floorType.Clone(true));
                                nodes.Add(n);
                            }
                        }
                    }
                }
                size         = new VectorInt(EndI - position.x, EndJ - position.y, EndK - position.z);
                bounds       = new FixedBounds2D(position, size);
                boundryNodes = new List <Node>();
                foreach (var point in bounds.boundriesOutside)
                {
                    Node n = map[point.x, point.y, point.z];
                    if (n != null)
                    {
                        n.SetProerties(boundryType);
                        boundryNodes.Add(n);
                    }
                }
                return(this);
            }
Exemplo n.º 2
0
        /// <summary>
        /// 判断另一个边界是否与此有重叠
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public bool IsIntersectWith(FixedBounds2D other)
        {
            bool pivotIn       = IsPointInBounds(other.pivot);
            bool diagonalIn    = IsPointInBounds(other.Diagonal);
            bool bottomRightIn = IsPointInBounds(other.BottomRight);
            bool upLeftlIn     = IsPointInBounds(other.UpLeft);

            if ((bottomRightIn || upLeftlIn || pivotIn || diagonalIn))
            {
                return(true);
            }
            if (!bottomRightIn && !upLeftlIn && !pivotIn && !diagonalIn)
            {
                pivotIn       = other.IsPointInBounds(pivot);
                diagonalIn    = other.IsPointInBounds(Diagonal);
                bottomRightIn = other.IsPointInBounds(BottomRight);
                upLeftlIn     = other.IsPointInBounds(UpLeft);
                if ((bottomRightIn || upLeftlIn || pivotIn || diagonalIn))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 根据位置与尺寸, 构造一个房间, 同时将生成房间的边界信息
 /// </summary>
 /// <param name="position"></param>
 /// <param name="size"></param>
 public Room(VectorInt position, VectorInt size)
 {
     this.position = position;
     this.size     = size;
     bounds        = new FixedBounds2D(position, size);
 }