Pathfinding.BBTree.Insert C# (CSharp) Method

Insert() public method

public Insert ( Pathfinding.MeshNode node ) : void
node Pathfinding.MeshNode
return void
		public void Insert (MeshNode node) {
			BBTreeBox box = new BBTreeBox (this,node);
			
			if (root == null) {
				root = box;
				return;
			}
			
			BBTreeBox c = root;
			while (true) {
				
				c.rect = ExpandToContain (c.rect,box.rect);
				if (c.node != null) {
					//Is Leaf
					c.c1 = box;
					BBTreeBox box2 = new BBTreeBox (this,c.node);
					//Console.WriteLine ("Inserted "+box.node+", rect "+box.rect.ToString ());
					c.c2 = box2;
					
					
					c.node = null;
					//c.rect = c.rect.
					return;
				} else {
					float e1 = ExpansionRequired (c.c1.rect,box.rect);
					float e2 = ExpansionRequired (c.c2.rect,box.rect);
					
					//Choose the rect requiring the least expansion to contain box.rect
					if (e1 < e2) {
						c = c.c1;
					} else if (e2 < e1) {
						c = c.c2;
					} else {
						//Equal, Choose the one with the smallest area
						c = RectArea (c.c1.rect) < RectArea (c.c2.rect) ? c.c1 : c.c2;
					}
				}
			}
		}
		

Usage Example

Ejemplo n.º 1
0
        /** Rebuilds the BBTree on a NavGraph.
         * \astarpro
         * \see NavMeshGraph.bbTree */
        public static void RebuildBBTree(NavMeshGraph graph)
        {
            //Build Axis Aligned Bounding Box Tree

            BBTree bbTree = graph.bbTree;

            bbTree = bbTree ?? new BBTree(graph);
            bbTree.Clear();

            var nodes = graph.nodes;

            for (int i = nodes.Length - 1; i >= 0; i--)
            {
                bbTree.Insert(nodes[i]);
            }

            graph.bbTree = bbTree;
        }
All Usage Examples Of Pathfinding.BBTree::Insert