コード例 #1
0
        public void GetPosInfo(Vector2 size, Vector2 center, ref PositionInQuadTree posInfo)
        {
            posInfo.Reset();

            var depth = GetDepth(size);

            if (depth == 0)
            {
                posInfo.inRoot = true;
                return;
            }
            var gridsize = _gridSizes[depth];

            int row    = Mathf.FloorToInt((center.y - _worldRect.yMin) / gridsize.y);
            int column = Mathf.FloorToInt((center.x - _worldRect.xMin) / gridsize.x);

            int tempRow    = row;
            int tempColumn = column;

            var storeDepth = 0;

            posInfo.storeDepth = depth;
            for (int i = depth - 1; i >= 0; i--)
            {
                int div      = (int)Mathf.Pow(2, i);
                int rowIndex = tempRow / div;
                if (rowIndex > 1)
                {
                    rowIndex = 1;
                }
                int columnIndex = tempColumn / div;
                if (columnIndex > 1)
                {
                    columnIndex = 1;
                }
                tempRow    %= div;
                tempColumn %= div;
                posInfo.posInDepths[storeDepth].rowIndex    = rowIndex;
                posInfo.posInDepths[storeDepth].columnIndex = columnIndex;
                storeDepth++;
            }
        }
コード例 #2
0
 public void InitializePosInQuadTree(QuadTree quadTree)
 {
     _lastPosInQuadTree    = new PositionInQuadTree(quadTree.GetDepth(this.size));
     _currentPosInQuadTree = new PositionInQuadTree(quadTree.GetDepth(this.size));
 }