public Actor GetOnlyIntersectingObject(Actor actor, Type cls) { RectBox rect = this.GetActorBounds(actor); lock (this.actorQuery) { this.actorQuery.Init(cls, actor); ActorNode node = GetNodeForActor(actor); if (node == null) { return(null); } do { BSPCollisionNode bspNode = node.GetBSPNode(); Actor result = this.GetOnlyObjectDownTree(actor, rect, this.actorQuery, bspNode); if (result != null) { return(result); } result = this.GetOnlyIntersectingUp(rect, this.actorQuery, actor, bspNode.GetParent()); if (result != null) { return(result); } node = node.GetNext(); } while (node != null); return(this.GetOnlyIntersectingDown(rect, this.actorQuery, actor)); } }
private void UpdateObject(Actor o) { ActorNode node = GetNodeForActor(o); if (node != null) { RectBox newBounds = this.GetActorBounds(o); BSPCollisionNode bspNode; if (!this.bspTree.GetArea().Contains(newBounds)) { for (; node != null;) { bspNode = node.GetBSPNode(); node.Remove(); this.CheckRemoveNode(bspNode); node = node.GetNext(); } this.AddObject(o); } else { RectBox bspArea; RectBox result1 = new RectBox(); RectBox result2 = new RectBox(); while (node != null) { bspNode = node.GetBSPNode(); bspArea = bspNode.GetArea(); if (bspArea.Contains(newBounds)) { for (ActorNode rNode2 = GetNodeForActor(o); rNode2 != null; rNode2 = rNode2 .GetNext()) { if (rNode2 != node) { BSPCollisionNode rNode1 = rNode2.GetBSPNode(); rNode2.Remove(); this.CheckRemoveNode(rNode1); } } return; } if (!bspArea.Intersects(newBounds)) { BSPCollisionNode rNode = node.GetBSPNode(); node.Remove(); this.CheckRemoveNode(rNode); } node.ClearMark(); node = node.GetNext(); } node = GetNodeForActor(o); if (node != null) { for (bspNode = node.GetBSPNode(); bspNode != null && !bspNode.GetArea().Contains(newBounds); bspNode = bspNode .GetParent()) { ; } if (bspNode == null) { while (node != null) { bspNode = node.GetBSPNode(); node.Remove(); this.CheckRemoveNode(bspNode); node = node.GetNext(); } this.AddObject(o); return; } } else { bspNode = this.bspTree; } bspArea = bspNode.GetArea(); this.InsertObject(o, newBounds, newBounds, bspArea, bspNode, result1, result2); for (node = GetNodeForActor(o); node != null; node = node .GetNext()) { if (!node.CheckMark()) { bspNode = node.GetBSPNode(); node.Remove(); this.CheckRemoveNode(bspNode); } } } } }