コード例 #1
0
        internal void DrawQuadTreeNode(ViewPortInfo viewPort,
                                       SpriteBatch spriteBatch,
                                       QuadTreeNode node,
                                       Rectangle destRectangle,
                                       SpriteFont spriteFont,
                                       float globalDispX, float globalDispY)
        {
            if (node == null)
            {
                return;
            }

            int actualX = (int)Math.Ceiling(node.pxBounds.X * viewPort.ActualZoom - globalDispX);
            int actualY = (int)Math.Ceiling(node.pxBounds.Y * viewPort.ActualZoom - globalDispY);

            // We need to calculate the 'Actual' width and height otherwise drawing might be innacurate when zoomed.
            int actualWidth  = (int)Math.Ceiling(node.pxBounds.Width * viewPort.ActualZoom);
            int actualHeight = (int)Math.Ceiling(node.pxBounds.Height * viewPort.ActualZoom);

            // Only draw leaf nodes which are within the viewport specified.
            if (node.ChildNode1 == null &&
                new Rectangle(actualX, actualY, actualWidth, actualHeight).Intersects(destRectangle))
            {
                string nodeText = string.Format("{0}\n\r{1}", node.NodeID, node.Entities.Count);

                SpriteBatchExtensions.DrawRectangle(spriteBatch, new Rectangle(actualX, actualY, actualWidth, actualHeight), Color.Lime, 0);
                spriteBatch.DrawString(
                    spriteFont,
                    nodeText,
                    new Vector2(actualX + actualWidth / 2.0f, actualY + actualHeight / 2.0f) - spriteFont.MeasureString(nodeText) / 2,
                    Color.Lime
                    );
            }

            DrawQuadTreeNode(viewPort, spriteBatch, node.ChildNode1, destRectangle, spriteFont, globalDispX, globalDispY);
            DrawQuadTreeNode(viewPort, spriteBatch, node.ChildNode2, destRectangle, spriteFont, globalDispX, globalDispY);
            DrawQuadTreeNode(viewPort, spriteBatch, node.ChildNode3, destRectangle, spriteFont, globalDispX, globalDispY);
            DrawQuadTreeNode(viewPort, spriteBatch, node.ChildNode4, destRectangle, spriteFont, globalDispX, globalDispY);
        }
コード例 #2
0
        // Validates this nodes MaxEntity/MinEntity requirements
        internal void Validate(QuadTreeNode nodeLimit=null)
        {
            if (this == nodeLimit) return;

            List<Entity> entities = new List<Entity>();
            GetEntities(null, ref entities);

            if (entities.Count <= QuadTree.EntityLimit)
            {
                ChildNode1 = null;
                ChildNode2 = null;
                ChildNode3 = null;
                ChildNode4 = null;
                Entities = entities;

                if (Parent!=nodeLimit)
                    Parent.Validate(nodeLimit);
            }
        }
コード例 #3
0
        internal QuadTreeNode GetQuadTreeNode(float x, float y, float width, float height, QuadTreeNode parentNode)
        {
            QuadTreeNode nodeResult = new QuadTreeNode();

            nodeResult.Reset();
            nodeResult.NodeID   = LatestNodeIndex;
            nodeResult.pxBounds = new FRectangle(x, y, width, height);
            nodeResult.QuadTree = this;
            nodeResult.Parent   = parentNode;

            LatestNodeIndex++;

            return(nodeResult);
        }
コード例 #4
0
        public bool DebugHasNode(QuadTreeNode node)
        {
            if (this == node)
                return true;

            if (!IsLeafNode)
            {
                if (ChildNode1.DebugHasNode(node)) return true;
                if (ChildNode2.DebugHasNode(node)) return true;
                if (ChildNode3.DebugHasNode(node)) return true;
                if (ChildNode4.DebugHasNode(node)) return true;
            }

            return false;
        }