Exemplo n.º 1
0
        private SphereTreeNode FindChildToDemote(SphereTreeNode s)
        {
            if (MO.DoLog)
            {
                MO.Log(" Demote this {0} s {1}", this, s);
            }
            Debug.Assert(s.leafNode, "s isn't a leaf node");
            // All children are occupied, and s is not wholly contained in
            // any of them.  Combine s with some child, creating a
            // subordinate.  Choose the child whose center is nearest
            // s.center.  If the child has a larger radius, insert s in
            // the child.  If the child has a smaller radius, s becomes
            // the child, and the child is inserted in s.
            float closest      = float.MaxValue;
            int   closestChild = -1;

            for (int i = 0; i < childCount; i++)
            {
                SphereTreeNode child = children[i];
                Debug.Assert(child != null, "Null child!");
                float d = Primitives.DistanceSquared(s.center, child.center);
                if (d < closest)
                {
                    closest      = d;
                    closestChild = i;
                }
            }
            Debug.Assert(closestChild >= 0, "closestChild not found!");
            SphereTreeNode cs = children[closestChild];

            if (cs.leafNode)
            {
                if (MO.DoLog)
                {
                    MO.Log(" Calling CombineLeafNodes to combine {0} with {1}", cs, this);
                }
                SphereTreeNode n = cs.CombineLeafNodes(s);
                children[closestChild] = n;
                return(n);
            }
            else if (cs.ChildSlotsFree() > 0)
            {
                cs.AddChild(s);
                cs.RecalculateCenterAndRadius();
                return(cs);
            }
            else
            {
                SphereTreeNode n = new SphereTreeNode(sphereTree);
                RemoveChild(cs);
                AddChild(n);
                n.AddChild(cs);
                n.AddChild(s);
                n.RecalculateCenterAndRadius();
                if (MO.DoLog)
                {
                    MO.Log(" In demote, made new node n {0}", n);
                }
                return(n);
            }
        }
Exemplo n.º 2
0
 public bool PointInsideSphere(Vector3 p)
 {
     return(Primitives.DistanceSquared(p, center) <= radius * radius);
 }
Exemplo n.º 3
0
 public bool SphereOverlap(BasicSphere S)
 {
     return(Primitives.DistanceSquared(center, S.center) <
            Primitives.Square(radius + S.radius));
 }
Exemplo n.º 4
0
        public bool Contains(BasicSphere s)
        {
            float sqSep = Primitives.DistanceSquared(s.center, center);

            return((sqSep + s.radius * s.radius) <= radius * radius);
        }