public void Link( QuadPatch left, QuadPatch right, QuadPatch up, QuadPatch down )
 {
     m_Left = left;
     m_Right = right;
     m_Up = up;
     m_Down = down;
 }
 public QuadPatchTree( Terrain terrain )
 {
     terrain.SetTerrainArea( Width, Height );
     m_Vertices = new QuadPatchVertices( );
     m_Root = new QuadPatch( terrain, m_Vertices, Color.Black, -Width / 2, -Height / 2, Width, Height );
 }
        private void IncreaseDetail( )
        {
            m_Vertices.Deallocate( m_VbIndex );

            float hW = m_Width / 2;
            float hD = m_Depth / 2;

            try
            {
                QuadPatch tl = new QuadPatch( m_Terrain, m_Vertices, Color.Red, m_X, m_Z, hW, hD );
                QuadPatch tr = new QuadPatch( m_Terrain, m_Vertices, Color.Black, m_X + hW, m_Z, hW, hD );
                QuadPatch bl = new QuadPatch( m_Terrain, m_Vertices, Color.Black, m_X, m_Z + hD, hW, hD );
                QuadPatch br = new QuadPatch( m_Terrain, m_Vertices, Color.Red, m_X + hW, m_Z + hD, hW, hD );

                tl.Link( m_Left, tr, m_Up, bl );
                tr.Link( tl, m_Right, m_Up, br );
                bl.Link( m_Left, br, tl, m_Down );
                br.Link( bl, m_Right, tr, m_Down );

                m_Children = new QuadPatch[ 4 ];
                m_Children[ TopLeftChild ] = tl;
                m_Children[ TopRightChild ] = tr;
                m_Children[ BottomLeftChild ] = bl;
                m_Children[ BottomRightChild ] = br;
            }
            catch ( OutOfMemoryException )
            {
                m_Children = null;
            }
        }