Ejemplo n.º 1
0
        public SphereTreeNode FindSubsphereContainerInternal(CollisionShape shape)
        {
            // If more than one child contains shape, return this
            int            count     = 0;
            SphereTreeNode container = null;

            for (int i = 0; i < childCount; i++)
            {
                SphereTreeNode child = children[i];
                if (child != null && child.Contains(shape))
                {
                    count++;
                    container = child;
                }
            }
            if (count > 1)
            {
                return(this);
            }
            else if (count == 0)
            {
                return(null);
            }
            else
            {
                container = container.FindSubsphereContainer(shape);
                SphereTreeNode result = (container == null ? this : container);
                return(result);
            }
        }
Ejemplo n.º 2
0
        public void InsertSphereTreeNode(SphereTreeNode s)
        {
            Debug.Assert(s.leafNode);
            if (leafNode)
            {
                CombineLeafNodes(s);
                parent.RecalculateCenterAndRadius();
                return;
            }

            SphereTreeNode child = null;

            for (int i = 0; i < childCount; i++)
            {
                child = children[i];
                if (child != null && child.Contains(s))
                {
                    child.InsertSphereTreeNode(s);
                    RecalculateCenterAndRadius();
                    return;
                }
            }

            // Not contained in any child, so create it here
            bool inserted = false;

            for (int i = 0; i < childCount; i++)
            {
                if (children[i] == null)
                {
                    s.parent    = this;
                    children[i] = s;
                    inserted    = true;
                    if (MO.DoLog)
                    {
                        MO.Log(" Inserted sphere {0} in parent {1}", s, this);
                    }
                    break;
                }
            }
            if (!inserted)
            {
                child = FindChildToDemote(s);
            }
            RecalculateCenterAndRadius();
        }
Ejemplo n.º 3
0
 public void AddToIntersectingShapes(CollisionShape shape)
 {
     if (shape == containedShape || !SphereOverlap(shape))
     {
         return;
     }
     for (int i = 0; i < childCount; i++)
     {
         SphereTreeNode child = children[i];
         if (child != null)
         {
             if (child.Contains(shape))
             {
                 child.AddToIntersectingShapes(shape);
                 return;
             }
         }
     }
     // Not wholly contained in a child so add it to our list
     AddIntersectingShape(shape);
     // Add it to any child that overlaps
     AddToChildIntersectingShapes(shape);
 }