Example #1
0
 private void InsertObject(Actor actor, RectBox actorBounds, RectBox bounds,
                           RectBox area, BSPCollisionNode node, RectBox result1,
                           RectBox result2)
 {
     if (!node.ContainsActor(actor))
     {
         if (!node.IsEmpty() &&
             (area.width > actorBounds.width || area.height > actorBounds.height))
         {
             RectBox leftArea       = node.GetLeftArea();
             RectBox rightArea      = node.GetRightArea();
             RectBox leftIntersects = RectBox.GetIntersection(leftArea,
                                                              bounds, result1);
             RectBox rightIntersects = RectBox.GetIntersection(rightArea,
                                                               bounds, result2);
             BSPCollisionNode newRight;
             if (leftIntersects != null)
             {
                 if (node.GetLeft() == null)
                 {
                     newRight = this.CreateNewNode(leftArea);
                     newRight.AddActor(actor);
                     node.SetChild(0, newRight);
                 }
                 else
                 {
                     this.InsertObject(actor, actorBounds, leftIntersects,
                                       leftArea, node.GetLeft(), result1, result2);
                 }
             }
             if (rightIntersects != null)
             {
                 if (node.GetRight() == null)
                 {
                     newRight = this.CreateNewNode(rightArea);
                     newRight.AddActor(actor);
                     node.SetChild(1, newRight);
                 }
                 else
                 {
                     this.InsertObject(actor, actorBounds, rightIntersects,
                                       rightArea, node.GetRight(), result1, result2);
                 }
             }
         }
         else
         {
             node.AddActor(actor);
         }
     }
 }