void QueryBoxInBounds (RecastBBTreeBox box, Rect bounds, List<RecastMeshObj> boxes) { if (box.mesh != null) { //Leaf node if (RectIntersectsRect (box.rect,bounds)) { // Found a RecastMeshObj, add it to the result boxes.Add (box.mesh); } else { } } else { #if ASTARDEBUG Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMin),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMax),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMin,0,box.rect.yMax),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMax,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); #endif //Search children if (RectIntersectsRect (box.c1.rect,bounds)) { QueryBoxInBounds (box.c1, bounds, boxes); } if (RectIntersectsRect (box.c2.rect,bounds)) { QueryBoxInBounds (box.c2, bounds, boxes); } } }
RecastBBTreeBox RemoveBox (RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!RectIntersectsRect (c.rect,bounds)) { return c; } if (c.mesh == mesh) { found = true; return null; } if (c.mesh == null && !found) { c.c1 = RemoveBox (c.c1, mesh, bounds, ref found); if (c.c1 == null) { return c.c2; } if (!found) { c.c2 = RemoveBox (c.c2, mesh, bounds, ref found); if (c.c2 == null) { return c.c1; } } if (found) { c.rect = ExpandToContain (c.c1.rect, c.c2.rect); } } return c; }
public void ToString() { RecastBBTreeBox root = this.root; new Stack <RecastBBTreeBox>().Push(root); root.WriteChildren(0); }
public void TestIntersections(Vector3 p, float radius) { RecastBBTreeBox box = root; TestIntersections(box, p, radius); }
void QueryBoxInBounds(RecastBBTreeBox box, Rect bounds, List <RecastMeshObj> boxes) { if (box.mesh != null) { //Leaf node if (RectIntersectsRect(box.rect, bounds)) { // Found a RecastMeshObj, add it to the result boxes.Add(box.mesh); } } else { #if ASTARDEBUG Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMin), new Vector3(box.rect.xMax, 0, box.rect.yMin), Color.white); Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMax), new Vector3(box.rect.xMax, 0, box.rect.yMax), Color.white); Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMin), new Vector3(box.rect.xMin, 0, box.rect.yMax), Color.white); Debug.DrawLine(new Vector3(box.rect.xMax, 0, box.rect.yMin), new Vector3(box.rect.xMax, 0, box.rect.yMax), Color.white); #endif //Search children if (RectIntersectsRect(box.c1.rect, bounds)) { QueryBoxInBounds(box.c1, bounds, boxes); } if (RectIntersectsRect(box.c2.rect, bounds)) { QueryBoxInBounds(box.c2, bounds, boxes); } } }
private RecastBBTreeBox RemoveBox(RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!this.RectIntersectsRect(c.rect, bounds)) { return(c); } if (c.mesh == mesh) { found = true; return(null); } if (c.mesh == null && !found) { c.c1 = this.RemoveBox(c.c1, mesh, bounds, ref found); if (c.c1 == null) { return(c.c2); } if (!found) { c.c2 = this.RemoveBox(c.c2, mesh, bounds, ref found); if (c.c2 == null) { return(c.c1); } } if (found) { c.rect = this.ExpandToContain(c.c1.rect, c.c2.rect); } } return(c); }
void QueryBoxInBounds(RecastBBTreeBox box, Rect bounds, List <RecastMeshObj> boxes) { if (box.mesh != null) { // Leaf node if (RectIntersectsRect(box.rect, bounds)) { // Found a RecastMeshObj, add it to the result boxes.Add(box.mesh); } } else { // Search children if (RectIntersectsRect(box.c1.rect, bounds)) { QueryBoxInBounds(box.c1, bounds, boxes); } if (RectIntersectsRect(box.c2.rect, bounds)) { QueryBoxInBounds(box.c2, bounds, boxes); } } }
public void ToString() { RecastBBTreeBox recastBBTreeBox = this.root; Stack <RecastBBTreeBox> stack = new Stack <RecastBBTreeBox>(); stack.Push(recastBBTreeBox); recastBBTreeBox.WriteChildren(0); }
public void TestIntersections(RecastBBTreeBox box, Vector3 p, float radius) { if (box != null) { this.RectIntersectsCircle(box.rect, p, radius); this.TestIntersections(box.c1, p, radius); this.TestIntersections(box.c2, p, radius); } }
public void QueryInBounds(Rect bounds, List <RecastMeshObj> buffer) { RecastBBTreeBox root = this.root; if (root != null) { this.QueryBoxInBounds(root, bounds, buffer); } }
public void QueryInBounds(Rect bounds, List <RecastMeshObj> buffer) { RecastBBTreeBox recastBBTreeBox = this.root; if (recastBBTreeBox == null) { return; } this.QueryBoxInBounds(recastBBTreeBox, bounds, buffer); }
/*public NNInfo Query (Vector3 p) { * * RecastBBTreeBox c = root; * * if (c == null) { * return new NNInfo(); * } * * NNInfo nnInfo = new NNInfo (); * * SearchBox (c,p, constraint, ref nnInfo); * * nnInfo.UpdateInfo (); * * return nnInfo; * }*/ /** Queries the tree for the best node, searching within a circle around \a p with the specified radius. * Will fill in both the constrained node and the not constrained node in the NNInfo. * * \see QueryClosest */ /*public NNInfo QueryCircle (Vector3 p, float radius) { * BBTreeBox c = root; * * if (c == null) { * return new NNInfo(); * } * #if ASTARDEBUG * Vector3 prev = new Vector3 (1,0,0)*radius+p; * for (double i=0;i< Math.PI*2; i += Math.PI/50.0) { * Vector3 cpos = new Vector3 ((float)Math.Cos (i),0,(float)Math.Sin (i))*radius+p; * Debug.DrawLine (prev,cpos,Color.yellow); * prev = cpos; * } #endif * * NNInfo nnInfo = new NNInfo (null); * * SearchBoxCircle (c,p, radius, constraint, ref nnInfo); * * nnInfo.UpdateInfo (); * * return nnInfo; * }*/ /** Queries the tree for the closest node to \a p constrained by the NNConstraint. * Note that this function will, unlike QueryCircle, only fill in the constrained node. * If you want a node not constrained by any NNConstraint, do an additional search with constraint = NNConstraint.None * * \see QueryCircle */ /*public NNInfo QueryClosest (Vector3 p, out float distance) { * distance = float.PositiveInfinity; * return QueryClosest (p, constraint, ref distance, new NNInfo (null)); * }*/ /** Queries the tree for the closest node to \a p constrained by the NNConstraint trying to improve an existing solution. * Note that this function will, unlike QueryCircle, only fill in the constrained node. * If you want a node not constrained by any NNConstraint, do an additional search with constraint = NNConstraint.None * * This search will start from the \a previous NNInfo and improve it if possible. * Even if the search fails on this call, the solution will never be worse than \a previous. * * * \param distance The best distance for the \a previous solution. Will be updated with the best distance * after this search. Will be positive infinity if no node could be found. * Set to positive infinity if there was no previous solution. * * * \see QueryCircle */ public void QueryInBounds(Rect bounds, List <RecastMeshObj> buffer) { RecastBBTreeBox c = root; if (c == null) { return; } QueryBoxInBounds(c, bounds, buffer); }
public new void ToString() { //Console.WriteLine ("Root "+(root.node != null ? root.node.ToString () : "")); RecastBBTreeBox c = root; Stack <RecastBBTreeBox> stack = new Stack <RecastBBTreeBox>(); stack.Push(c); c.WriteChildren(0); }
public void TestIntersections(RecastBBTreeBox box, Vector3 p, float radius) { if (box == null) { return; } RectIntersectsCircle(box.rect, p, radius); TestIntersections(box.c1, p, radius); TestIntersections(box.c2, p, radius); }
public void OnDrawGizmos(RecastBBTreeBox box) { if (box != null) { Vector3 vector = new Vector3(box.rect.xMin, 0f, box.rect.yMin); Vector3 vector2 = new Vector3(box.rect.xMax, 0f, box.rect.yMax); Vector3 center = (Vector3)((vector + vector2) * 0.5f); Vector3 size = (Vector3)((vector2 - center) * 2f); Gizmos.DrawCube(center, size); this.OnDrawGizmos(box.c1); this.OnDrawGizmos(box.c2); } }
/** Inserts a mesh node in the tree */ public void Insert(RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox(this, mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain(c.rect, box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; RecastBBTreeBox box2 = new RecastBBTreeBox(this, c.mesh); //Console.WriteLine ("Inserted "+box.node+", rect "+box.rect.ToString ()); c.c2 = box2; c.mesh = 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; } } } }
public void OnDrawGizmos(RecastBBTreeBox box) { if (box == null) { return; } Vector3 a = new Vector3(box.rect.xMin, 0f, box.rect.yMin); Vector3 vector = new Vector3(box.rect.xMax, 0f, box.rect.yMax); Vector3 vector2 = (a + vector) * 0.5f; Vector3 size = (vector - vector2) * 2f; Gizmos.DrawCube(vector2, size); this.OnDrawGizmos(box.c1); this.OnDrawGizmos(box.c2); }
/// <summary>Inserts a RecastMeshObj in the tree at its current position</summary> public void Insert(RecastMeshObj mesh) { var box = new RecastBBTreeBox(mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain(c.rect, box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; var box2 = new RecastBBTreeBox(c.mesh); c.c2 = box2; c.mesh = null; 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; } } } }
/** Removes the specified mesh from the tree. * Assumes that it has the correct bounds information. * * \returns True if the mesh was removed from the tree, false otherwise. */ public bool Remove (RecastMeshObj mesh) { if (mesh == null) throw new ArgumentNullException("mesh"); if (root == null) { return false; } bool found = false; Bounds b = mesh.GetBounds(); //Convert to top down rect Rect r = Rect.MinMaxRect(b.min.x, b.min.z, b.max.x, b.max.z); root = RemoveBox(root, mesh, r, ref found); return found; }
public void QueryBoxInBounds(RecastBBTreeBox box, Rect bounds, List <RecastMeshObj> boxes) { if (box.mesh != null) { //Leaf node if (RectIntersectsRect(box.rect, bounds)) { //Update the NNInfo #if ASTARDEBUG Debug.DrawLine((Vector3)box.node.GetVertex(1) + Vector3.up * 0.2f, (Vector3)box.node.GetVertex(2) + Vector3.up * 0.2f, Color.red); Debug.DrawLine((Vector3)box.node.GetVertex(0) + Vector3.up * 0.2f, (Vector3)box.node.GetVertex(1) + Vector3.up * 0.2f, Color.red); Debug.DrawLine((Vector3)box.node.GetVertex(2) + Vector3.up * 0.2f, (Vector3)box.node.GetVertex(0) + Vector3.up * 0.2f, Color.red); #endif boxes.Add(box.mesh); } else { #if ASTARDEBUG Debug.DrawLine((Vector3)box.node.GetVertex(0), (Vector3)box.node.GetVertex(1), Color.blue); Debug.DrawLine((Vector3)box.node.GetVertex(1), (Vector3)box.node.GetVertex(2), Color.blue); Debug.DrawLine((Vector3)box.node.GetVertex(2), (Vector3)box.node.GetVertex(0), Color.blue); #endif } } else { #if ASTARDEBUG Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMin), new Vector3(box.rect.xMax, 0, box.rect.yMin), Color.white); Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMax), new Vector3(box.rect.xMax, 0, box.rect.yMax), Color.white); Debug.DrawLine(new Vector3(box.rect.xMin, 0, box.rect.yMin), new Vector3(box.rect.xMin, 0, box.rect.yMax), Color.white); Debug.DrawLine(new Vector3(box.rect.xMax, 0, box.rect.yMin), new Vector3(box.rect.xMax, 0, box.rect.yMax), Color.white); #endif //Search children if (RectIntersectsRect(box.c1.rect, bounds)) { QueryBoxInBounds(box.c1, bounds, boxes); } if (RectIntersectsRect(box.c2.rect, bounds)) { QueryBoxInBounds(box.c2, bounds, boxes); } } }
public bool Remove(RecastMeshObj mesh) { if (mesh == null) { throw new ArgumentNullException("mesh"); } if (this.root == null) { return(false); } bool result = false; Bounds bounds = mesh.GetBounds(); Rect bounds2 = Rect.MinMaxRect(bounds.min.x, bounds.min.z, bounds.max.x, bounds.max.z); this.root = this.RemoveBox(this.root, mesh, bounds2, ref result); return(result); }
public void OnDrawGizmos(RecastBBTreeBox box) { if (box == null) { return; } Vector3 min = new Vector3(box.rect.xMin, 0, box.rect.yMin); Vector3 max = new Vector3(box.rect.xMax, 0, box.rect.yMax); Vector3 center = (min + max) * 0.5F; Vector3 size = (max - center) * 2; Gizmos.DrawCube(center, size); OnDrawGizmos(box.c1); OnDrawGizmos(box.c2); }
public void OnDrawGizmos(RecastBBTreeBox box) { if (box == null) { return; } Vector3 vector; vector..ctor(box.rect.xMin, 0f, box.rect.yMin); Vector3 vector2; vector2..ctor(box.rect.xMax, 0f, box.rect.yMax); Vector3 vector3 = (vector + vector2) * 0.5f; Vector3 vector4 = (vector2 - vector3) * 2f; Gizmos.DrawCube(vector3, vector4); this.OnDrawGizmos(box.c1); this.OnDrawGizmos(box.c2); }
/*public void SearchBoxCircle (BBTreeBox box, Vector3 p, float radius, NNConstraint constraint, ref NNInfo nnInfo) {//, int intendentLevel = 0) { * * if (box.node != null) { * //Leaf node * if (NodeIntersectsCircle (box.node,p,radius)) { * //Update the NNInfo * #if ASTARDEBUG * Debug.DrawLine ((Vector3)box.node.GetVertex(0),(Vector3)box.node.GetVertex(1),Color.red); * Debug.DrawLine ((Vector3)box.node.GetVertex(1),(Vector3)box.node.GetVertex(2),Color.red); * Debug.DrawLine ((Vector3)box.node.GetVertex(2),(Vector3)box.node.GetVertex(0),Color.red); #endif * * Vector3 closest = box.node.ClosestPointOnNode (p);//NavMeshGraph.ClosestPointOnNode (box.node,graph.vertices,p); * float dist = (closest-p).sqrMagnitude; * * if (nnInfo.node == null) { * nnInfo.node = box.node; * nnInfo.clampedPosition = closest; * } else if (dist < (nnInfo.clampedPosition - p).sqrMagnitude) { * nnInfo.node = box.node; * nnInfo.clampedPosition = closest; * } * if (constraint.Suitable (box.node)) { * if (nnInfo.constrainedNode == null) { * nnInfo.constrainedNode = box.node; * nnInfo.constClampedPosition = closest; * } else if (dist < (nnInfo.constClampedPosition - p).sqrMagnitude) { * nnInfo.constrainedNode = box.node; * nnInfo.constClampedPosition = closest; * } * } * } else { #if ASTARDEBUG * Debug.DrawLine ((Vector3)box.node.GetVertex(0),(Vector3)box.node.GetVertex(1),Color.blue); * Debug.DrawLine ((Vector3)box.node.GetVertex(1),(Vector3)box.node.GetVertex(2),Color.blue); * Debug.DrawLine ((Vector3)box.node.GetVertex(2),(Vector3)box.node.GetVertex(0),Color.blue); #endif * } * return; * } * #if ASTARDEBUG * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMin),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMax),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMin,0,box.rect.yMax),Color.white); * Debug.DrawLine (new Vector3 (box.rect.xMax,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); #endif * * //Search children * if (RectIntersectsCircle (box.c1.rect,p,radius)) { * SearchBoxCircle (box.c1,p, radius, ref nnInfo); * } * * if (RectIntersectsCircle (box.c2.rect,p,radius)) { * SearchBoxCircle (box.c2,p, radius, ref nnInfo); * } * }*/ /*public void SearchBox (BBTreeBox box, Vector3 p, NNConstraint constraint, ref NNInfo nnInfo) {//, int intendentLevel = 0) { * * if (box.node != null) { * //Leaf node * if (box.node.ContainsPoint ((Int3)p)) { * //Update the NNInfo * * if (nnInfo.node == null) { * nnInfo.node = box.node; * } else if (Mathf.Abs(((Vector3)box.node.Position).y - p.y) < Mathf.Abs (((Vector3)nnInfo.node.Position).y - p.y)) { * nnInfo.node = box.node; * } * if (constraint.Suitable (box.node)) { * if (nnInfo.constrainedNode == null) { * nnInfo.constrainedNode = box.node; * } else if (Mathf.Abs(box.node.Position.y - p.y) < Mathf.Abs (nnInfo.constrainedNode.Position.y - p.y)) { * nnInfo.constrainedNode = box.node; * } * } * } * return; * } * * //Search children * if (RectContains (box.c1.rect,p)) { * SearchBox (box.c1,p, constraint, ref nnInfo); * } * * if (RectContains (box.c2.rect,p)) { * SearchBox (box.c2,p, constraint, ref nnInfo); * } * }*/ /** Removes the specified mesh from the tree. * Assumes that it has the correct bounds information. * * \returns True if the mesh was removed from the tree, false otherwise. */ public bool Remove(RecastMeshObj mesh) { if (mesh == null) { throw new System.ArgumentNullException("mesh"); } if (root == null) { return(false); } bool found = false; Bounds b = mesh.GetBounds(); //Convert to top down rect Rect r = Rect.MinMaxRect(b.min.x, b.min.z, b.max.x, b.max.z); root = RemoveBox(root, mesh, r, ref found); return(found); }
public void QueryBoxInBounds(RecastBBTreeBox box, Rect bounds, List <RecastMeshObj> boxes) { if (box.mesh != null) { if (this.RectIntersectsRect(box.rect, bounds)) { boxes.Add(box.mesh); } } else { if (this.RectIntersectsRect(box.c1.rect, bounds)) { this.QueryBoxInBounds(box.c1, bounds, boxes); } if (this.RectIntersectsRect(box.c2.rect, bounds)) { this.QueryBoxInBounds(box.c2, bounds, boxes); } } }
public void Insert(RecastMeshObj mesh) { RecastBBTreeBox recastBBTreeBox = new RecastBBTreeBox(this, mesh); if (this.root == null) { this.root = recastBBTreeBox; return; } RecastBBTreeBox recastBBTreeBox2 = this.root; while (true) { recastBBTreeBox2.rect = this.ExpandToContain(recastBBTreeBox2.rect, recastBBTreeBox.rect); if (recastBBTreeBox2.mesh != null) { break; } float num = this.ExpansionRequired(recastBBTreeBox2.c1.rect, recastBBTreeBox.rect); float num2 = this.ExpansionRequired(recastBBTreeBox2.c2.rect, recastBBTreeBox.rect); if (num < num2) { recastBBTreeBox2 = recastBBTreeBox2.c1; } else if (num2 < num) { recastBBTreeBox2 = recastBBTreeBox2.c2; } else { recastBBTreeBox2 = ((this.RectArea(recastBBTreeBox2.c1.rect) >= this.RectArea(recastBBTreeBox2.c2.rect)) ? recastBBTreeBox2.c2 : recastBBTreeBox2.c1); } } recastBBTreeBox2.c1 = recastBBTreeBox; RecastBBTreeBox c = new RecastBBTreeBox(this, recastBBTreeBox2.mesh); recastBBTreeBox2.c2 = c; recastBBTreeBox2.mesh = null; }
public void Insert(RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox(this, mesh); if (this.root == null) { this.root = box; return; } RecastBBTreeBox root = this.root; Label_0022: root.rect = this.ExpandToContain(root.rect, box.rect); if (root.mesh != null) { root.c1 = box; RecastBBTreeBox box3 = new RecastBBTreeBox(this, root.mesh); root.c2 = box3; root.mesh = null; } else { float num = this.ExpansionRequired(root.c1.rect, box.rect); float num2 = this.ExpansionRequired(root.c2.rect, box.rect); if (num < num2) { root = root.c1; } else if (num2 < num) { root = root.c2; } else { root = (this.RectArea(root.c1.rect) >= this.RectArea(root.c2.rect)) ? root.c2 : root.c1; } goto Label_0022; } }
RecastBBTreeBox RemoveBox(RecastBBTreeBox c, RecastMeshObj mesh, Rect bounds, ref bool found) { if (!RectIntersectsRect(c.rect, bounds)) { return(c); } if (c.mesh == mesh) { found = true; return(null); } if (c.mesh == null && !found) { c.c1 = RemoveBox(c.c1, mesh, bounds, ref found); if (c.c1 == null) { return(c.c2); } if (!found) { c.c2 = RemoveBox(c.c2, mesh, bounds, ref found); if (c.c2 == null) { return(c.c1); } } // TODO: Will this ever be called? if (found) { c.rect = ExpandToContain(c.c1.rect, c.c2.rect); } } return(c); }
/** Inserts a mesh node in the tree */ public void Insert (RecastMeshObj mesh) { RecastBBTreeBox box = new RecastBBTreeBox (this,mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain (c.rect,box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; RecastBBTreeBox box2 = new RecastBBTreeBox (this,c.mesh); //Console.WriteLine ("Inserted "+box.node+", rect "+box.rect.ToString ()); c.c2 = box2; c.mesh = 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; } } } }
public void TestIntersections (RecastBBTreeBox box, Vector3 p, float radius) { if (box == null) { return; } RectIntersectsCircle (box.rect,p,radius); TestIntersections (box.c1,p,radius); TestIntersections (box.c2,p,radius); }
public void QueryBoxInBounds (RecastBBTreeBox box, Rect bounds, List<RecastMeshObj> boxes) { if (box.mesh != null) { //Leaf node if (RectIntersectsRect (box.rect,bounds)) { //Update the NNInfo #if ASTARDEBUG Debug.DrawLine ((Vector3)box.node.GetVertex(1) + Vector3.up*0.2f,(Vector3)box.node.GetVertex(2) + Vector3.up*0.2f,Color.red); Debug.DrawLine ((Vector3)box.node.GetVertex(0) + Vector3.up*0.2f,(Vector3)box.node.GetVertex(1) + Vector3.up*0.2f,Color.red); Debug.DrawLine ((Vector3)box.node.GetVertex(2) + Vector3.up*0.2f,(Vector3)box.node.GetVertex(0) + Vector3.up*0.2f,Color.red); #endif boxes.Add (box.mesh); } else { #if ASTARDEBUG Debug.DrawLine ((Vector3)box.node.GetVertex(0),(Vector3)box.node.GetVertex(1),Color.blue); Debug.DrawLine ((Vector3)box.node.GetVertex(1),(Vector3)box.node.GetVertex(2),Color.blue); Debug.DrawLine ((Vector3)box.node.GetVertex(2),(Vector3)box.node.GetVertex(0),Color.blue); #endif } } else { #if ASTARDEBUG Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMin),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMax),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMin,0,box.rect.yMin),new Vector3 (box.rect.xMin,0,box.rect.yMax),Color.white); Debug.DrawLine (new Vector3 (box.rect.xMax,0,box.rect.yMin),new Vector3 (box.rect.xMax,0,box.rect.yMax),Color.white); #endif //Search children if (RectIntersectsRect (box.c1.rect,bounds)) { QueryBoxInBounds (box.c1, bounds, boxes); } if (RectIntersectsRect (box.c2.rect,bounds)) { QueryBoxInBounds (box.c2, bounds, boxes); } } }
/** Inserts a RecastMeshObj in the tree at its current position */ public void Insert (RecastMeshObj mesh) { var box = new RecastBBTreeBox (mesh); if (root == null) { root = box; return; } RecastBBTreeBox c = root; while (true) { c.rect = ExpandToContain (c.rect,box.rect); if (c.mesh != null) { //Is Leaf c.c1 = box; var box2 = new RecastBBTreeBox (c.mesh); c.c2 = box2; c.mesh = null; 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; } } } }
public void OnDrawGizmos (RecastBBTreeBox box) { if (box == null) { return; } var min = new Vector3 (box.rect.xMin,0,box.rect.yMin); var max = new Vector3 (box.rect.xMax,0,box.rect.yMax); Vector3 center = (min+max)*0.5F; Vector3 size = (max-center)*2; Gizmos.DrawCube (center,size); OnDrawGizmos (box.c1); OnDrawGizmos (box.c2); }
public void TestIntersections(Vector3 p, float radius) { RecastBBTreeBox root = this.root; this.TestIntersections(root, p, radius); }