Пример #1
0
        public void RenderNodeBoundingBox <T>(IXNAGame game, IQuadTreeNode <T> quadTreeNode) where T : IQuadTreeNode <T>
        {
            if (quadTreeNode == null)
            {
                return;
            }

            QuadTreeNodeData <T> node = quadTreeNode.NodeData;

            RenderNodeBoundingBox(game, node.UpperLeft);
            RenderNodeBoundingBox(game, node.UpperRight);
            RenderNodeBoundingBox(game, node.LowerLeft);
            RenderNodeBoundingBox(game, node.LowerRight);

            //TODO: Calculate level is quite lame here and slow, since we loop the tree level by level
            int   level = QuadTree.CalculateLevel(quadTreeNode);
            Color col;

            if (level < levelColors.Length)
            {
                col = levelColors[level];
            }
            else
            {
                col = levelColors[levelColors.Length - 1];
            }

            game.LineManager3D.AddBox(quadTreeNode.NodeData.BoundingBox.xna(), col);
        }
Пример #2
0
        //       private ulong address;
        //protected QuadTreeNode upperLeft;
        //protected QuadTreeNode upperRight;
        //protected QuadTreeNode lowerLeft;
        //protected QuadTreeNode lowerRight;
        //protected QuadTreeNode parent;
        //protected BoundingBox boundingBox = new BoundingBox();
        //protected bool isStatic = false;
        //protected Common.GeoMipMap.TerrainBlock terrainBlock;

        //public enum ChildDir
        //{
        //    UpperLeft = 0,
        //    UpperRight = 1,
        //    LowerLeft = 2,
        //    LowerRight = 3
        //}

        //public QuadTreeNode()
        //    : base()
        //{
        //    //UpdateAdress();
        //}

        //~QuadTreeNode()
        //{
        //    Dispose( false );
        //}


        //public void Dispose()
        //{
        //    Dispose( true );
        //    GC.SuppressFinalize( this );
        //}

        //protected virtual void Dispose( bool disposing )
        //{
        //    lock ( this )
        //    {
        //        if ( disposing )
        //        {
        //            if ( upperLeft != null )
        //                upperLeft.Dispose();

        //            if ( upperRight != null )
        //                upperRight.Dispose();

        //            if ( lowerLeft != null )
        //                lowerLeft.Dispose();

        //            if ( lowerRight != null )
        //                lowerRight.Dispose();

        //            if ( parent != null )
        //                parent.RemoveChild( this );

        //        }

        //        upperLeft = null;
        //        upperRight = null;
        //        lowerLeft = null;
        //        lowerRight = null;
        //        parent = null;
        //    }

        //}


        public static void Split <T>(T node) where T : class, IQuadTreeNode <T>
        {
            if (node.NodeData.UpperLeft != null && node.NodeData.UpperRight != null && node.NodeData.LowerLeft != null && node.NodeData.LowerRight != null)
            {
                return;
            }
            Vector3 half = new Vector3(node.NodeData.BoundingBox.Maximum.X - node.NodeData.BoundingBox.Minimum.X, 0, node.NodeData.BoundingBox.Maximum.Z - node.NodeData.BoundingBox.Minimum.Z);

            half  *= 0.5f;
            half.Y = node.NodeData.BoundingBox.Maximum.Y - node.NodeData.BoundingBox.Minimum.Y;

            //NOTE: This is a heavy operation, since it copies the nodeData to the stack, and later in the code back to the heap.
            // Performance should be verified.
            QuadTreeNodeData <T> nodeData  = node.NodeData; // WARNING: THIS IS A HEAVY OPERATION
            QuadTreeNodeData <T> childData = new QuadTreeNodeData <T>();
            Vector3 min;

            childData.Parent = node;

            if (node.NodeData.UpperLeft == null)
            {
                min = nodeData.BoundingBox.Minimum + new Vector3(0, 0, 0);
                childData.BoundingBox       = new BoundingBox(min, min + half);
                nodeData.UpperLeft          = node.CreateChild(childData);
                nodeData.UpperLeft.NodeData = childData;
            }
            if (node.NodeData.UpperRight == null)
            {
                min = nodeData.BoundingBox.Minimum + new Vector3(half.X, 0, 0);
                childData.BoundingBox = new BoundingBox(min, min + half);
                nodeData.UpperRight   = node.CreateChild(childData);
            }
            nodeData.UpperRight.NodeData = childData;

            if (node.NodeData.LowerLeft == null)
            {
                min = nodeData.BoundingBox.Minimum + new Vector3(0, 0, half.Z);
                childData.BoundingBox       = new BoundingBox(min, min + half);
                nodeData.LowerLeft          = node.CreateChild(childData);
                nodeData.LowerLeft.NodeData = childData;
            }
            if (node.NodeData.LowerRight == null)
            {
                min = nodeData.BoundingBox.Minimum + new Vector3(half.X, 0, half.Z);
                childData.BoundingBox        = new BoundingBox(min, min + half);
                nodeData.LowerRight          = node.CreateChild(childData);
                nodeData.LowerRight.NodeData = childData;
            }

            node.NodeData = nodeData;

            /*upperLeft.UpdateAdress();
             * upperRight.UpdateAdress();
             * lowerLeft.UpdateAdress();
             * lowerRight.UpdateAdress();*/
        }
Пример #3
0
        public void RenderNodeGroundBoundig <T>(IXNAGame game, IQuadTreeNode <T> quadTreeNode) where T : IQuadTreeNode <T>
        {
            if (quadTreeNode == null)
            {
                return;
            }

            QuadTreeNodeData <T> node = quadTreeNode.NodeData;

            RenderNodeGroundBoundig(game, node.UpperLeft);
            RenderNodeGroundBoundig(game, node.UpperRight);
            RenderNodeGroundBoundig(game, node.LowerLeft);
            RenderNodeGroundBoundig(game, node.LowerRight);

            //if ( node.IsLeaf == false ) return;
            //FloorLowerLeft = min
            //TopUpperRight = max

            //TODO: Calculate level is quite lame here and slow, since we loop the tree level by level
            int   level = QuadTree.CalculateLevel(quadTreeNode);
            Color col;

            if (level < levelColors.Length)
            {
                col = levelColors[level];
            }
            else
            {
                col = levelColors[levelColors.Length - 1];
            }

            Vector3 radius = (node.BoundingBox.Maximum - node.BoundingBox.Minimum).xna();
            Vector3 radX   = new Vector3(radius.X, 0, 0);
            Vector3 radY   = new Vector3(0, radius.Y, 0);
            Vector3 radZ   = new Vector3(0, 0, radius.Z);
            Vector3 min    = node.BoundingBox.Minimum.xna();

            min.Y = -1 + level;


            Vector3 fll = min;
            Vector3 flr = min + radX;
            Vector3 ful = min + radZ;
            Vector3 fur = min + radX + radZ;



            //grondvlak
            game.LineManager3D.AddLine(fll, flr, col);
            game.LineManager3D.AddLine(flr, fur, col);
            game.LineManager3D.AddLine(fur, ful, col);
            game.LineManager3D.AddLine(ful, fll, col);
        }
Пример #4
0
        /// <summary>
        /// This functions loops through all nodes and renders the node when the given predicate returns true for given node. It uses the out color argument to determine the color of the rendered node.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="game"></param>
        /// <param name="quadTreeNode"></param>
        /// <param name="predicate"></param>
        public void RenderNodeGroundBoundig <T>(IXNAGame game, T quadTreeNode, RenderNodePredicate <T> predicate) where T : class, IQuadTreeNode <T>
        {
            if (quadTreeNode == null)
            {
                return;
            }

            QuadTreeNodeData <T> node = quadTreeNode.NodeData;

            RenderNodeGroundBoundig(game, node.UpperLeft, predicate);
            RenderNodeGroundBoundig(game, node.UpperRight, predicate);
            RenderNodeGroundBoundig(game, node.LowerLeft, predicate);
            RenderNodeGroundBoundig(game, node.LowerRight, predicate);


            Color col;

            if (!predicate(quadTreeNode, out col))
            {
                return;
            }

            //TODO: Calculate level is quite lame here and slow, since we loop the tree level by level
            int level = QuadTree.CalculateLevel(quadTreeNode);


            Vector3 radius = (node.BoundingBox.Maximum - node.BoundingBox.Minimum).xna();
            Vector3 radX   = new Vector3(radius.X, 0, 0);
            Vector3 radY   = new Vector3(0, radius.Y, 0);
            Vector3 radZ   = new Vector3(0, 0, radius.Z);
            Vector3 min    = node.BoundingBox.Minimum.xna();

            min.Y = -1 + level;


            Vector3 fll = min;
            Vector3 flr = min + radX;
            Vector3 ful = min + radZ;
            Vector3 fur = min + radX + radZ;



            //grondvlak
            game.LineManager3D.AddLine(fll, flr, col);
            game.LineManager3D.AddLine(flr, fur, col);
            game.LineManager3D.AddLine(fur, ful, col);
            game.LineManager3D.AddLine(ful, fll, col);
        }
Пример #5
0
        public static void Merge <T>(IQuadTreeNode <T> node) where T : class, IQuadTreeNode <T>
        {
            QuadTreeNodeData <T> nodeData = node.NodeData;

            /*if (nodeData.UpperLeft != null)
             *  upperLeft.Dispose();
             *
             * if (nodeData.UpperRight != null)
             *  upperRight.Dispose();
             *
             * if (nodeData.LowerLeft != null)
             *  lowerLeft.Dispose();
             *
             * if (nodeData.LowerRight != null)
             *  lowerRight.Dispose();*/

            nodeData.UpperLeft  = null;
            nodeData.UpperRight = null;
            nodeData.LowerLeft  = null;
            nodeData.LowerRight = null;

            node.NodeData = nodeData;
        }