fliXNA_xbox.FlxQuadTree.addObject C# (CSharp) Method

addObject() protected method

protected addObject ( ) : void
return void
        protected void addObject()
        {
            //If this quad (not its children) lies entirely inside this object, add it here
            if(!_canSubdivide || ((_leftEdge >= _objectLeftEdge) && (_rightEdge <= _objectRightEdge) && (_topEdge >= _objectTopEdge) && (_bottomEdge <= _objectBottomEdge)))
            {
                addToList();
                return;
            }

            //See if the selected object fits completely inside any of the quadrants
            if((_objectLeftEdge > _leftEdge) && (_objectRightEdge < _midpointX))
            {
                if((_objectTopEdge > _topEdge) && (_objectBottomEdge < _midpointY))
                {
                    if(_northWestTree == null)
                        _northWestTree = new FlxQuadTree(_leftEdge,_topEdge,_halfWidth,_halfHeight,this);
                    _northWestTree.addObject();
                    return;
                }
                if((_objectTopEdge > _midpointY) && (_objectBottomEdge < _bottomEdge))
                {
                    if(_southWestTree == null)
                        _southWestTree = new FlxQuadTree(_leftEdge,_midpointY,_halfWidth,_halfHeight,this);
                    _southWestTree.addObject();
                    return;
                }
            }
            if((_objectLeftEdge > _midpointX) && (_objectRightEdge < _rightEdge))
            {
                if((_objectTopEdge > _topEdge) && (_objectBottomEdge < _midpointY))
                {
                    if(_northEastTree == null)
                        _northEastTree = new FlxQuadTree(_midpointX,_topEdge,_halfWidth,_halfHeight,this);
                    _northEastTree.addObject();
                    return;
                }
                if((_objectTopEdge > _midpointY) && (_objectBottomEdge < _bottomEdge))
                {
                    if(_southEastTree == null)
                        _southEastTree = new FlxQuadTree(_midpointX,_midpointY,_halfWidth,_halfHeight,this);
                    _southEastTree.addObject();
                    return;
                }
            }

            //If it wasn't completely contained we have to check out the partial overlaps
            if((_objectRightEdge > _leftEdge) && (_objectLeftEdge < _midpointX) && (_objectBottomEdge > _topEdge) && (_objectTopEdge < _midpointY))
            {
                if(_northWestTree == null)
                    _northWestTree = new FlxQuadTree(_leftEdge,_topEdge,_halfWidth,_halfHeight,this);
                _northWestTree.addObject();
            }
            if((_objectRightEdge > _midpointX) && (_objectLeftEdge < _rightEdge) && (_objectBottomEdge > _topEdge) && (_objectTopEdge < _midpointY))
            {
                if(_northEastTree == null)
                    _northEastTree = new FlxQuadTree(_midpointX,_topEdge,_halfWidth,_halfHeight,this);
                _northEastTree.addObject();
            }
            if((_objectRightEdge > _midpointX) && (_objectLeftEdge < _rightEdge) && (_objectBottomEdge > _midpointY) && (_objectTopEdge < _bottomEdge))
            {
                if(_southEastTree == null)
                    _southEastTree = new FlxQuadTree(_midpointX,_midpointY,_halfWidth,_halfHeight,this);
                _southEastTree.addObject();
            }
            if((_objectRightEdge > _leftEdge) && (_objectLeftEdge < _midpointX) && (_objectBottomEdge > _midpointY) && (_objectTopEdge < _bottomEdge))
            {
                if(_southWestTree == null)
                    _southWestTree = new FlxQuadTree(_leftEdge,_midpointY,_halfWidth,_halfHeight,this);
                _southWestTree.addObject();
            }
        }

Usage Example

Exemplo n.º 1
0
        protected void addObject()
        {
            //If this quad (not its children) lies entirely inside this object, add it here
            if (!_canSubdivide || ((_leftEdge >= _objectLeftEdge) && (_rightEdge <= _objectRightEdge) && (_topEdge >= _objectTopEdge) && (_bottomEdge <= _objectBottomEdge)))
            {
                addToList();
                return;
            }

            //See if the selected object fits completely inside any of the quadrants
            if ((_objectLeftEdge > _leftEdge) && (_objectRightEdge < _midpointX))
            {
                if ((_objectTopEdge > _topEdge) && (_objectBottomEdge < _midpointY))
                {
                    if (_northWestTree == null)
                    {
                        _northWestTree = new FlxQuadTree(_leftEdge, _topEdge, _halfWidth, _halfHeight, this);
                    }
                    _northWestTree.addObject();
                    return;
                }
                if ((_objectTopEdge > _midpointY) && (_objectBottomEdge < _bottomEdge))
                {
                    if (_southWestTree == null)
                    {
                        _southWestTree = new FlxQuadTree(_leftEdge, _midpointY, _halfWidth, _halfHeight, this);
                    }
                    _southWestTree.addObject();
                    return;
                }
            }
            if ((_objectLeftEdge > _midpointX) && (_objectRightEdge < _rightEdge))
            {
                if ((_objectTopEdge > _topEdge) && (_objectBottomEdge < _midpointY))
                {
                    if (_northEastTree == null)
                    {
                        _northEastTree = new FlxQuadTree(_midpointX, _topEdge, _halfWidth, _halfHeight, this);
                    }
                    _northEastTree.addObject();
                    return;
                }
                if ((_objectTopEdge > _midpointY) && (_objectBottomEdge < _bottomEdge))
                {
                    if (_southEastTree == null)
                    {
                        _southEastTree = new FlxQuadTree(_midpointX, _midpointY, _halfWidth, _halfHeight, this);
                    }
                    _southEastTree.addObject();
                    return;
                }
            }

            //If it wasn't completely contained we have to check out the partial overlaps
            if ((_objectRightEdge > _leftEdge) && (_objectLeftEdge < _midpointX) && (_objectBottomEdge > _topEdge) && (_objectTopEdge < _midpointY))
            {
                if (_northWestTree == null)
                {
                    _northWestTree = new FlxQuadTree(_leftEdge, _topEdge, _halfWidth, _halfHeight, this);
                }
                _northWestTree.addObject();
            }
            if ((_objectRightEdge > _midpointX) && (_objectLeftEdge < _rightEdge) && (_objectBottomEdge > _topEdge) && (_objectTopEdge < _midpointY))
            {
                if (_northEastTree == null)
                {
                    _northEastTree = new FlxQuadTree(_midpointX, _topEdge, _halfWidth, _halfHeight, this);
                }
                _northEastTree.addObject();
            }
            if ((_objectRightEdge > _midpointX) && (_objectLeftEdge < _rightEdge) && (_objectBottomEdge > _midpointY) && (_objectTopEdge < _bottomEdge))
            {
                if (_southEastTree == null)
                {
                    _southEastTree = new FlxQuadTree(_midpointX, _midpointY, _halfWidth, _halfHeight, this);
                }
                _southEastTree.addObject();
            }
            if ((_objectRightEdge > _leftEdge) && (_objectLeftEdge < _midpointX) && (_objectBottomEdge > _midpointY) && (_objectTopEdge < _bottomEdge))
            {
                if (_southWestTree == null)
                {
                    _southWestTree = new FlxQuadTree(_leftEdge, _midpointY, _halfWidth, _halfHeight, this);
                }
                _southWestTree.addObject();
            }
        }