示例#1
0
文件: World.cs 项目: MaxEden/Humper
        public Hit Hit(Rect origin, Rect destination, IEnumerable <Box> ignoring = null)
        {
            var boxes = StaticPool.GetHashSet <Box>();
            var wrap  = Rect.Union(origin, destination);

            _broadPhase.QueryBoxes(wrap, boxes);

            if (ignoring != null)
            {
                boxes.ExceptWith(ignoring);
            }

            Hit nearest = new Hit();

            foreach (var other in boxes)
            {
                var hit = Humper.Hit.Resolve(origin, destination, other);

                if (hit.IsHit && (!nearest.IsHit || hit.IsNearest(nearest, origin.Position)))
                {
                    nearest = hit;
                }
            }

            StaticPool.Return(boxes);
            return(nearest);
        }