Exemple #1
0
        private void DrawAabbTree()
        {
            var treeRootDrawParams = new DrawnParams
            {
                position  = V.xy((ClientSize.Width + 225) / 2, 10),
                layersize = V.xy(ClientSize.Width - 250, 15f),
            };

            _hoveredNode = null;
            DrawTree(_world.tree.Root, treeRootDrawParams, treeRootDrawParams);
        }
Exemple #2
0
        private void DrawTree(IRectTreeNode node, DrawnParams drawTarget, DrawnParams drawActual)
        {
            if (node == null)
            {
                return;
            }
            if (!node.Children().Any())
            {
                return;
            }


            var newDrawActual = drawTarget;

            if (drawns.TryGetValue(node, out var drawn))
            {
                float spd = ClientSize.Width / 50f;
                newDrawActual = drawn.Approach(spd, 2 * spd, drawTarget);
            }

            drawns[node] = newDrawActual;


            int i = 0;

            foreach (var child in node.Children())
            {
                var childDrawActual = ComputeChildDrawLocation(node, i, newDrawActual);
                var pen             = Pens.Green;
                if (_hoveredNode == null && Vec2.Dist(childDrawActual.position, _viewMouse) < 10)
                {
                    _hoveredNode = child;
                    pen          = Pens.Red;
                }
                _graphics.DrawLine(
                    pen,
                    newDrawActual.position.x,
                    newDrawActual.position.y,
                    childDrawActual.position.x,
                    childDrawActual.position.y
                    );
                if (child.Children().Any())
                {
                    var childDrawTarget = ComputeChildDrawLocation(node, i, drawTarget);
                    DrawTree(child, childDrawTarget, childDrawActual);
                }
                i++;
            }
        }
Exemple #3
0
        private static DrawnParams ComputeChildDrawLocation(IRectTreeNode node, int childIndex, DrawnParams parentDrawParams)
        {
            int   count = node.Children().Count();
            float temp  = (childIndex + 1) / (float)(count + 1) - 0.5f;

            return(new DrawnParams
            {
                position = parentDrawParams.position + new Vec2(parentDrawParams.layersize.x * temp, parentDrawParams.layersize.y),
                layersize = new Vec2(parentDrawParams.layersize.x * (1f / count), parentDrawParams.layersize.y),
            });
        }