public bool NodeIntersectsCircle(MeshNode node, Vector3 p, float radius) { if (NavMeshGraph.ContainsPoint(node, p, graph.vertices)) { return(true); } Int3[] vertices = graph.vertices; float r2 = radius * radius; Vector3 p1 = (Vector3)vertices[node[0]], p2 = (Vector3)vertices[node[1]], p3 = (Vector3)vertices[node[2]]; p1.y = p.y; p2.y = p.y; p3.y = p.y; return(Mathfx.DistancePointSegmentStrict(p1, p2, p) < r2 || Mathfx.DistancePointSegmentStrict(p2, p3, p) < r2 || Mathfx.DistancePointSegmentStrict(p3, p1, p) < r2); }
public void SearchBox(BBTreeBox box, Vector3 p, NNConstraint constraint, ref NNInfo nnInfo) //, int intendentLevel = 0) { { if (box.node != null) { //Leaf node if (NavMeshGraph.ContainsPoint(box.node, p, graph.vertices)) { //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); } }