Ejemplo n.º 1
0
 public void CheckCollsion(CollsionComponent x)
 {
     if (CollsionDetector.OverLapping(Bounds, x.Bounds))
     {
         Add(x);
     }
 }
Ejemplo n.º 2
0
        private void Insert(CollsionComponent pRect)
        {
            if (_nodes[0] != null)
            {
                int i = GetIndex(pRect);

                if (i != -1)
                {
                    _nodes[i].Insert(pRect);

                    return;
                }
            }

            _objects.Add(pRect);

            if (_objects.Count > Settings.QUADTREE_MAX_OBJECTS && _level < Settings.QUADTREE_MAX_LEVELS)
            {
                if (_nodes[0] == null)
                {
                    Split();
                }

                int j = 0;

                while (j < _objects.Count)
                {
                    int index = GetIndex(_objects[j]);

                    if (index != -1)
                    {
                        _nodes[index].Insert(_objects[j]);
                        _objects.RemoveAt(j);
                    }
                    else
                    {
                        j++;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private int GetIndex(CollsionComponent pRect)
        {
            int    index              = -1;
            double verticalMidpoint   = _bounds.X + (_bounds.Width / 2);
            double horizontalMidpoint = _bounds.Y + (_bounds.Height / 2);

            // Object can completely fit within the top quadrants
            bool topQuadrant = (pRect.Bounds.Y < horizontalMidpoint && pRect.Bounds.Y + pRect.Bounds.Height < horizontalMidpoint);

            // Object can completely fit within the bottom quadrants
            bool bottomQuadrant = (pRect.Bounds.Y > horizontalMidpoint);

            // Object can completely fit within the left quadrants
            if (pRect.Bounds.X < verticalMidpoint && pRect.Bounds.X + pRect.Bounds.Width < verticalMidpoint)
            {
                if (topQuadrant)
                {
                    index = 1;
                }
                else if (bottomQuadrant)
                {
                    index = 2;
                }
            }
            // Object can completely fit within the right quadrants
            else if (pRect.Bounds.X > verticalMidpoint)
            {
                if (topQuadrant)
                {
                    index = 0;
                }
                else if (bottomQuadrant)
                {
                    index = 3;
                }
            }
            return(index);
        }
Ejemplo n.º 4
0
 private List <CollsionComponent> Retrieve(CollsionComponent pRect)
 {
     return(Retrieve(new HashSet <CollsionComponent>(), pRect));
 }
Ejemplo n.º 5
0
        private List <CollsionComponent> Retrieve(HashSet <CollsionComponent> returnedObjs, CollsionComponent obj)
        {
            if (_nodes[0] != null)
            {
                var index = GetIndex(obj);
                if (index != -1)
                {
                    _nodes[index].Retrieve(returnedObjs, obj);
                }
                else
                {
                    for (int i = 0; i < _nodes.Length; i++)
                    {
                        _nodes[i].Retrieve(returnedObjs, obj);
                    }
                }
            }

            foreach (CollsionComponent i in _objects)
            {
                returnedObjs.Add(i);
            }

            return(returnedObjs.ToList());
        }
 protected override void Add(CollsionComponent x)
 {
     base.Add(x);
 }
Ejemplo n.º 7
0
 protected virtual void Add(CollsionComponent x)
 {
     ColliedObjects.Add(x);
 }