public void Update() { QuadTree quadTree = CreateQuadTree(Bounds); _quadTreeDataCollection.Clear(); foreach (ICollisionActor collisionActor in _collisionActors) { var quadTreeData = new QuadTreeData(collisionActor.GetCollider(), collisionActor); _quadTreeDataCollection.Add(quadTreeData); quadTree.Insert(quadTreeData); } var queryResult = new List <QuadTreeData>(); for (var i = 0; i < _quadTreeDataCollection.Count; i++) { QuadTreeData quadTreeData = _quadTreeDataCollection[i]; quadTree.Query(quadTreeData.Collider, queryResult); for (var index = 0; index < queryResult.Count; index++) { QuadTreeData other = queryResult[index]; if (other.Equals(quadTreeData)) { continue; } Vector2 penetrationVector = quadTreeData.Collider.CalculatePenetrationVector(other.Collider); quadTreeData.CollisionActor.HandleCollision(new Collision { Penetration = penetrationVector, Other = other.CollisionActor }); } queryResult.Clear(); } for (var index = 0; index < _activeQuadTrees.Count; index++) { QuadTree activeQuadTree = _activeQuadTrees[index]; _inactiveQuadTrees.Push(new WeakReference <QuadTree>(activeQuadTree)); } _activeQuadTrees.Clear(); }
public bool Equals(QuadTreeData quadTree) { return(CollisionActor == quadTree.CollisionActor); }