示例#1
0
    public QuadTree2 RecoverTree()
    {
        if (parent != null)
        {
            if (!parent.a.tag)
            {
                parent.a = null;
            }
            if (!parent.b.tag)
            {
                parent.b = null;
            }
            if (!parent.c.tag)
            {
                parent.c = null;
            }
            if (!parent.d.tag)
            {
                parent.d = null;
            }

            if (parent.tag)
            {
                return(parent);
            }
            else
            {
                return(parent.RecoverTree());
            }
        }

        return(null);
    }
示例#2
0
    void LocalUpdate(Vector3 oldPos, Vector3 newPos)
    {
        if (QuadTree2.refTree == null)
        {
            bInit = false;
        }
        else
        {
            float     tminx1 = 0.0f;
            float     tmaxx1 = 0.0f;
            float     tminz1 = 0.0f;
            float     tmaxz1 = 0.0f;
            QuadTree2 t1     = QuadTree2.refTree.Find(oldPos.x, oldPos.z, ref tminx1, ref tmaxx1, ref tminz1, ref tmaxz1);

            float     tminx2 = 0.0f;
            float     tmaxx2 = 0.0f;
            float     tminz2 = 0.0f;
            float     tmaxz2 = 0.0f;
            QuadTree2 t2     = QuadTree2.refTree.Find(newPos.x, newPos.z, ref tminx2, ref tmaxx2, ref tminz2, ref tmaxz2);

            if (!t1.Equals(t2) && t1.parent != t2.parent)
            {
                QuadTree2 parentTree = t1.RecoverTree();
                if (parentTree != null)
                {
                    bool flag2 = true;

                    if (parentTree.minx <= t2.minx &&
                        parentTree.maxx >= t2.maxx &&
                        parentTree.minz <= t2.minz &&
                        parentTree.maxz >= t2.maxz)
                    {
                        flag2 = false;
                    }

                    if (flag2)
                    {
                        if (tmaxx2 == tminx1)
                        {
                            // t2 is a neighbor to the left of t1
                            //print ("t2 is a neighbor to the left of t1");
                            t2.BuildTree(newPos);
                        }
                        else if (tminx2 == tmaxx1)
                        {
                            // t2 is a neighbor to the right of t1
                            //print ("t2 is a neighbor to the right of t1");
                            t2.BuildTree(newPos);
                        }
                        else if (tminz2 == tmaxz1)
                        {
                            //t2 is a neighbor on top of t1
                            //print ("t2 is a neighbor on top of t1");
                            t2.BuildTree(newPos);
                        }
                        else if (tmaxz2 == tminz1)
                        {
                            //t2 is a neighbor below t1
                            //print ("t2 is a neighbor below t1");
                            t2.BuildTree(newPos);
                        }
                        else
                        {
                            // not a neighbor
                            bInit = false;
                        }
                    }
                    else
                    {
                        parentTree.BuildTree(newPos);
                    }
                }
                else
                {
                    bInit = false;
                }
            }
            else
            {
                // they are the same quad-tree node
            }

            P = new Vector3(newPos.x, newPos.y, newPos.z);
        }
    }