Exemplo n.º 1
0
        public GridBlockCollection GetBlocksAroundLine(Vector3 startPoint, Vector3 endPoint)
        {
            GridBlockCollection gridBlockCollection = new GridBlockCollection(false);

            Vector3 currentPoint     = startPoint;
            Vector3 direction        = Vector3.Normalize(endPoint - startPoint);
            Single  originalDistance = Vector3.Distance(currentPoint, endPoint);

            while (Vector3.Distance(startPoint, currentPoint) < originalDistance)
            {
                GridBlock block = GetBlockByLocation(currentPoint.X, currentPoint.Y);

                if (block != null && !gridBlockCollection.Contains(block))
                {
                    gridBlockCollection.Add(block);
                }

                currentPoint += direction;
            }

            for (Int32 i = gridBlockCollection.Count - 1; i >= 0; i--)
            {
                GridBlock block = gridBlockCollection[i];
                if (block == null)
                {
                    continue;
                }

                if (block.ContainerBox == null)
                {
                    continue;
                }
                if (block.ContainerBox.LineInBox(startPoint, endPoint))
                {
                    continue;
                }

                gridBlockCollection.RemoveAt(i);
            }

            return(gridBlockCollection);
        }