Exemple #1
0
        public void AddCollisionShape(CollisionShape shape)
        {
            // Called with this equal to the root of the tree
            shapesAdded++;
            SphereTreeNode s = new SphereTreeNode(shape, this);

            if (MO.DoLog)
            {
                MO.Log("Adding shape {0} to leaf {1}", shape, s);
            }
            root.InsertSphereTreeNode(s);
            root.AddToIntersectingShapes(shape);
            Debug.Assert(shapesAdded - shapesRemoved <= nodeCount,
                         "shapesAdded - shapesRemoved > nodeCount!");
            MaybeVerifyOrDump();
        }
Exemple #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();
        }