public void AddBody(Circle *body) { if (body == null) { return; } if (_childA != null) { _bodyCount++; var child = GetQuadrant(body->pos); child->AddBody(body); } else { if (_bodies == null) { _bodies = QuadTreeFactory.AllocPtrBlock(_maxBodiesPerNode); } CheckDebugInfo($"AddBody{body->Id}"); fixed(QuadTree *thisPtr = &this) { body->ParentNode = thisPtr; body->_debugId = this._debugId; } //CheckDebugInfo(body); _bodies[_bodyCount++] = body; if (_bodyCount >= _maxBodiesPerNode && _curLevel < _maxLevel && _bounds.width > 2) { CheckDebugInfo($"Split{body->Id}"); Split(); } } }
public QuadTree(LRect bounds, int maxBodiesPerNode = 6, int maxLevel = 6) { _bounds = bounds; _maxBodiesPerNode = maxBodiesPerNode; _maxLevel = maxLevel; _childA = null; _childB = null; _childC = null; _childD = null; _curLevel = 0; _parent = null; _bodyCount = 0; _debugId = curDebugId++; _bodies = QuadTreeFactory.AllocPtrBlock(_maxBodiesPerNode); }