예제 #1
0
        private static void DrawBounds(Color[][] texture, AABB2D bounds, NativeQuadTree <T> tree)
        {
            var widthMult  = texture.Length / tree.bounds.Extents.x * 2 / 2 / 2;
            var heightMult = texture[0].Length / tree.bounds.Extents.y * 2 / 2 / 2;

            var widthAdd  = tree.bounds.Center.x + tree.bounds.Extents.x;
            var heightAdd = tree.bounds.Center.y + tree.bounds.Extents.y;

            var top  = new float2(bounds.Center.x, bounds.Center.y - bounds.Extents.y);
            var left = new float2(bounds.Center.x - bounds.Extents.x, bounds.Center.y);

            for (var leftToRight = 0; leftToRight < bounds.Extents.x * 2; leftToRight++)
            {
                var poxX = left.x + leftToRight;
                texture[(int)((poxX + widthAdd) * widthMult)][(int)((bounds.Center.y + heightAdd + bounds.Extents.y) * heightMult)] = Color.blue;
                texture[(int)((poxX + widthAdd) * widthMult)][(int)((bounds.Center.y + heightAdd - bounds.Extents.y) * heightMult)] = Color.blue;
            }

            for (var topToBottom = 0; topToBottom < bounds.Extents.y * 2; topToBottom++)
            {
                var posY = top.y + topToBottom;
                texture[(int)((bounds.Center.x + widthAdd + bounds.Extents.x) * widthMult)][(int)((posY + heightAdd) * heightMult)] = Color.blue;
                texture[(int)((bounds.Center.x + widthAdd - bounds.Extents.x) * widthMult)][(int)((posY + heightAdd) * heightMult)] = Color.blue;
            }
        }
예제 #2
0
        public static void Draw(NativeQuadTree <T> tree, NativeList <QuadElement <T> > results, AABB2D range,
                                Color[][] texture)
        {
            var widthMult  = texture.Length / tree.bounds.Extents.x * 2 / 2 / 2;
            var heightMult = texture[0].Length / tree.bounds.Extents.y * 2 / 2 / 2;

            var widthAdd  = tree.bounds.Center.x + tree.bounds.Extents.x;
            var heightAdd = tree.bounds.Center.y + tree.bounds.Extents.y;

            for (var i = 0; i < tree.nodes.Length; i++)
            {
                var node = tree.nodes[i]; //UnsafeUtility.ReadArrayElement<QuadNode>(tree.nodes->Ptr, i);

                if (node.count > 0)
                {
                    for (var k = 0; k < node.count; k++)
                    {
                        //var element = UnsafeUtility.ReadArrayElement<QuadElement<T>>(tree.elements->Ptr, node.firstChildIndex + k);
                        var element = tree.elements[node.firstChildIndex + k];

                        texture[(int)((element.pos.x + widthAdd) * widthMult)]
                        [(int)((element.pos.y + heightAdd) * heightMult)] = Color.red;
                    }
                }
            }

            foreach (var element in results)
            {
                texture[(int)((element.pos.x + widthAdd) * widthMult)]
                [(int)((element.pos.y + heightAdd) * heightMult)] = Color.green;
            }

            NativeQuadTree <T> .DrawBounds(texture, range, tree);
        }
            public void Query(NativeQuadTree <T> tree, AABB2D bounds, NativeList <QuadElement <T> > results)
            {
                this.tree   = tree;
                this.bounds = bounds;
                this.count  = 0;

                // Get pointer to inner list data for faster writing
                //this.fastResults = (UnsafeList*)NativeListUnsafeUtility.GetInternalListDataPtrUnchecked(ref results);

                this.RecursiveRangeQuery(results, tree.bounds, false, 1, 1);
                results.Length = this.count;

                //this.fastResults->Length = this.count;
            }