public static void InsertLeaf( btDbvt pdbvt, btDbvtNode root, btDbvtNode leaf ) { if( pdbvt.Root == null ) { pdbvt.Root = leaf; leaf.parent = null; } else { if( !root.IsLeaf() ) { do { if( btDbvtVolume.Select( ref leaf.volume, ref root._children0.volume, ref root._children1.volume ) == 0 ) root = root._children0; else root = root._children1; } while( !root.IsLeaf() ); } btDbvtNode prev = root.parent; btDbvtVolume mergeResults = btDbvtVolume.Merge( ref leaf.volume, ref root.volume ); btDbvtNode node = CreateNode2( pdbvt, prev, ref mergeResults, null ); if( prev != null ) { if( IndexOf( root ) == 0 ) prev._children0 = node; else prev._children1 = node; node._children0 = root; root.parent = node; node._children1 = leaf; leaf.parent = node; do { if( !prev.volume.Contain( ref node.volume ) ) { btDbvtVolume.Merge( ref prev._children0.volume, ref prev._children1.volume, out prev.volume ); } else { break; } node = prev; } while( null != ( prev = node.parent ) ); } else { node._children0 = root; root.parent = node; node._children1 = leaf; leaf.parent = node; pdbvt.Root = node; } } }
public static void RecurseDeleteNode( btDbvt pdbvt, btDbvtNode node ) { if( !node.IsLeaf() ) { RecurseDeleteNode( pdbvt, node._children0 ); RecurseDeleteNode( pdbvt, node._children1 ); } if( node == pdbvt.m_root ) { pdbvt.m_root = null; } DeleteNode( pdbvt, node ); }