Ejemplo n.º 1
0
 T[] GetCollisionObjectsFromAChild(Vector2 checkPoint, float checkRadius, QuadtreeRadius <T> child)
 {
     if (child._field.PointToFieldDistance(checkPoint) <= _maxRadius + checkRadius)      //这里不光要考虑到检测半径,还要考虑到节点最大半径
     {
         return(child.CheckCollision(checkPoint, checkRadius));
     }
     return(new T[0]);
 }
Ejemplo n.º 2
0
        /*
         *  构造方法增加一个父节点参数,默认值是null。
         *  创建四叉树时不传参数,分割时传当前节点,这样根节点就没有父节点,其他节点都有父节点,向上更新半径就可以进行。
         */
        public QuadtreeRadius(float top, float right, float bottom, float left, int maxLeafNumber, float minSideLength, QuadtreeRadius <T> parent = null)
        {
            _field = new QuadtreeWithRadiusField(top, right, bottom, left);

            _maxLeafsNumber = maxLeafNumber;
            _minSideLength  = minSideLength;

            _parent = parent;

            DrawField();    //绘制节点范围,删除不影响功能
        }
Ejemplo n.º 3
0
        void Split()
        {
            Debug.Log("位置在((" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "))的树梢节点达到分割条件,进行分割");

            float xCenter = (_field.left + _field.right) / 2;
            float yCenter = (_field.bottom + _field.top) / 2;

            _upperRightChild = new QuadtreeRadius <T>(_field.top, _field.right, yCenter, xCenter, _maxLeafsNumber, _minSideLength, this);
            _lowerRightChild = new QuadtreeRadius <T>(yCenter, _field.right, _field.bottom, xCenter, _maxLeafsNumber, _minSideLength, this);
            _lowerLeftChild  = new QuadtreeRadius <T>(yCenter, xCenter, _field.bottom, _field.left, _maxLeafsNumber, _minSideLength, this);
            _upperLeftChild  = new QuadtreeRadius <T>(_field.top, xCenter, yCenter, _field.left, _maxLeafsNumber, _minSideLength, this);

            foreach (QuadtreeLeafRadius <T> leaf in _leafs)      //因为这里向子节点存入所有叶子,最大半径的叶子依然在范围里,不需要对最大半径做特别处理
            {
                SetLeafToChildren(leaf);
            }
            _leafs = null;
        }
 private void Awake()
 {
     _quadtree = new QuadtreeRadius <GameObject>(_top, _right, _bottom, _left, _maxLeafsNumber, _minSideLength);
 }