예제 #1
0
        public void AddObject(ViewableObject viewable)
        {
            if (!viewable.IsInsideRectangle(this.quadBounds))
            {
                return;
            }
            if (this.viewableObjects.ContainsKey(viewable.Name))
            {
                return;
            }

            this.viewableObjects.Add(viewable.Name, viewable);

            viewable.QuadTreeNodes.Add(this);
            if (this.northeastNode != null && viewable.IsInsideRectangle(this.northeastNode.Bounds))
            {
                this.northeastNode.AddObject(viewable);
            }

            if (this.northwestNode != null && viewable.IsInsideRectangle(this.northwestNode.Bounds))
            {
                this.northwestNode.AddObject(viewable);
            }

            if (this.southeastNode != null && viewable.IsInsideRectangle(this.southeastNode.Bounds))
            {
                this.southeastNode.AddObject(viewable);
            }

            if (this.southwestNode != null && viewable.IsInsideRectangle(this.southwestNode.Bounds))
            {
                this.southwestNode.AddObject(viewable);
            }
        }
예제 #2
0
        public void Update(ViewableObject viewableObject)
        {
            bool _needReset = false;

            foreach (QuadTreeNode node in viewableObject.QuadTreeNodes)
            {
                if (!viewableObject.IsInsideRectangle(node.Bounds))
                {
                    //there's at least 1 object that's no longer in
                    //the view.  Need a reset.
                    _needReset = true;
                    break;
                }
            }

            if (_needReset)
            {
                BaseNode.RemoveObject(viewableObject);
                BaseNode.AddObject(viewableObject);
            }
        }