Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
 public Actor GetOnlyIntersectingUp(RectBox r,
                                    CollisionQuery query, Actor actor, BSPCollisionNode start)
 {
     for (; start != null && !start.GetArea().Contains(r);)
     {
         Actor res = this.CheckForOnlyCollision(actor, start, query);
         if (res != null)
         {
             return(res);
         }
         start = start.GetParent();
     }
     return(null);
 }
Ejemplo n.º 3
0
        private BSPCollisionNode CheckRemoveNode(BSPCollisionNode node)
        {
            int idx = 0;

            for (; idx < MAX_SIZE;)
            {
                if (node != null && node.IsEmpty())
                {
                    BSPCollisionNode parent = node.GetParent();
                    int side = (parent != null) ? parent.GetChildSide(node) : 3;
                    BSPCollisionNode left  = node.GetLeft();
                    BSPCollisionNode right = node.GetRight();
                    if (left == null)
                    {
                        if (parent != null)
                        {
                            if (right != null)
                            {
                                right.SetArea(node.GetArea());
                            }
                            parent.SetChild(side, right);
                        }
                        else
                        {
                            this.bspTree = right;
                            if (right != null)
                            {
                                right.SetParent((BSPCollisionNode)null);
                            }
                        }
                        node.SetChild(1, (BSPCollisionNode)null);
                        ReturnNode(node);
                        node = parent;
                        continue;
                    }

                    if (right == null)
                    {
                        if (parent != null)
                        {
                            if (left != null)
                            {
                                left.SetArea(node.GetArea());
                            }

                            parent.SetChild(side, left);
                        }
                        else
                        {
                            this.bspTree = left;
                            if (left != null)
                            {
                                left.SetParent((BSPCollisionNode)null);
                            }
                        }

                        node.SetChild(0, (BSPCollisionNode)null);
                        ReturnNode(node);
                        node = parent;
                        continue;
                    }
                }
                idx++;
                return(node);
            }
            return(null);
        }