示例#1
0
        //Public Methods
        public override void add(T entity)
        {
            if (!HasEntity)
            {
                _entity   = entity;
                HasEntity = true;
            }
            else
            {
                if (!HasChildren)
                {
                    createChildren();
                }

                IHasAABB2D entityRect = (IHasAABB2D)entity;

                for (int i = 0; i < QUADS; i++)
                {
                    if (_children[i].BoundingBox.intersects(entityRect.BoundingBox))
                    {
                        _children[i].add(entity);
                        break;
                    }
                }
            }
        }
示例#2
0
        public override void remove(T entity)
        {
            if (EqualityComparer <T> .Default.Equals(entity, _entity))
            {
                _entity   = default(T);
                HasEntity = false;
                _parent.checkChildren();
                return;
            }

            if (!HasChildren)
            {
                return;
            }

            IHasAABB2D entityRect = (IHasAABB2D)entity;

            for (int i = 0; i < QUADS; i++)
            {
                if (HasChildren && _children[i].BoundingBox.intersects(entityRect.BoundingBox))
                {
                    _children[i].remove(entity);
                }
            }
        }
示例#3
0
        public override List <T> queryArea(AABB2D areaToQuery, List <T> entitiesFound)
        {
            //Check for instersection with entity if one is held in this node
            if (HasEntity)
            {
                IHasAABB2D rectEntity = (IHasAABB2D)_entity;
                if (areaToQuery.intersects(rectEntity.BoundingBox))
                {
                    entitiesFound.Add(_entity);
                }
            }

            //Check child nodes for intersection, and query them if so.
            if (HasChildren)
            {
                for (int i = 0; i < QUADS; i++)
                {
                    if (areaToQuery.intersects(_children[i].BoundingBox))
                    {
                        entitiesFound = _children[i].queryArea(areaToQuery, entitiesFound);
                    }
                }
            }
            return(entitiesFound);
        }
示例#4
0
        public override void remove(T entity)
        {
            IHasAABB2D entityRect = (IHasAABB2D)entity;

            if (entityRect.BoundingBox.intersects(BoundingBox))
            {
                _root.remove(entity);
            }
        }