public static DistancePointSegmentStrict ( Vector3 a, Vector3 b, Vector3 p ) : float | ||
a | Vector3 | |
b | Vector3 | |
p | Vector3 | |
리턴 | float |
public static void SimplifyPath2(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint) { int count = result.Count; if (end <= start + 1) { result.Add(nodes[start]); result.Add(nodes[end]); return; } GraphHitInfo graphHitInfo; if (rcg.Linecast(startPoint, endPoint, nodes[start], out graphHitInfo, result) || result[result.Count - 1] != nodes[end]) { result.RemoveRange(count, result.Count - count); int num = -1; float num2 = float.PositiveInfinity; for (int i = start + 1; i < end; i++) { float num3 = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (num == -1 || num3 < num2) { num = i; num2 = num3; } } RichFunnel.SimplifyPath2(rcg, nodes, start, num, result, startPoint, (Vector3)nodes[num].position); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath2(rcg, nodes, num, end, result, (Vector3)nodes[num].position, endPoint); } }
public static void SimplifyPath3(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint, int depth = 0) { if (start == end) { result.Add(nodes[start]); return; } if (start + 1 == end) { result.Add(nodes[start]); result.Add(nodes[end]); return; } int count = result.Count; GraphHitInfo graphHitInfo; if (rcg.Linecast(startPoint, endPoint, nodes[start], out graphHitInfo, result) || result[result.Count - 1] != nodes[end]) { result.RemoveRange(count, result.Count - count); int num = 0; float num2 = 0f; for (int i = start + 1; i < end - 1; i++) { float num3 = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (num3 > num2) { num = i; num2 = num3; } } int num4 = (num + start) / 2; int num5 = (num + end) / 2; if (num4 == num5) { RichFunnel.SimplifyPath3(rcg, nodes, start, num4, result, startPoint, (Vector3)nodes[num4].position, 0); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num4, end, result, (Vector3)nodes[num4].position, endPoint, depth + 1); } else { RichFunnel.SimplifyPath3(rcg, nodes, start, num4, result, startPoint, (Vector3)nodes[num4].position, depth + 1); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num4, num5, result, (Vector3)nodes[num4].position, (Vector3)nodes[num5].position, depth + 1); result.RemoveAt(result.Count - 1); RichFunnel.SimplifyPath3(rcg, nodes, num5, end, result, (Vector3)nodes[num5].position, endPoint, depth + 1); } } }
public static void SimplifyPath2(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint) { int resCount = result.Count; //Debug.DrawLine (startPoint, endPoint, Color.black); //Debug.Break(); if (end <= start + 1) { result.Add(nodes[start]); result.Add(nodes[end]); //t--; return; } GraphHitInfo hit; if ((rcg.Linecast(startPoint, endPoint, nodes[start], out hit, result) || result[result.Count - 1] != nodes[end])) { //System.Console.WriteLine ("Hit"); //Obstacle //Refine further result.RemoveRange(resCount, result.Count - resCount); int minDistNode = -1; float minDist = float.PositiveInfinity; for (int i = start + 1; i < end; i++) { float dist = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (minDistNode == -1 || dist < minDist) { minDistNode = i; minDist = dist; } } SimplifyPath2(rcg, nodes, start, minDistNode, result, startPoint, (Vector3)nodes[minDistNode].position); //Remove start node of next part so that it is not added twice result.RemoveAt(result.Count - 1); SimplifyPath2(rcg, nodes, minDistNode, end, result, (Vector3)nodes[minDistNode].position, endPoint); } }
public static void SimplifyPath3(IRaycastableGraph rcg, List <GraphNode> nodes, int start, int end, List <GraphNode> result, Vector3 startPoint, Vector3 endPoint, int depth = 0) { if (start == end) { result.Add(nodes[start]); return; } if (start + 1 == end) { result.Add(nodes[start]); result.Add(nodes[end]); return; } int resCount = result.Count; GraphHitInfo hit; bool linecast = rcg.Linecast(startPoint, endPoint, nodes[start], out hit, result); if (linecast || result[result.Count - 1] != nodes[end]) { //Debug.DrawLine (startPoint, endPoint, Color.black); //Obstacle //Refine further result.RemoveRange(resCount, result.Count - resCount); int maxDistNode = 0; float maxDist = 0; for (int i = start + 1; i < end - 1; i++) { float dist = AstarMath.DistancePointSegmentStrict(startPoint, endPoint, (Vector3)nodes[i].position); if (dist > maxDist) { maxDistNode = i; maxDist = dist; } } int mid1 = (maxDistNode + start) / 2; int mid2 = (maxDistNode + end) / 2; if (mid1 == mid2) { SimplifyPath3(rcg, nodes, start, mid1, result, startPoint, (Vector3)nodes[mid1].position); //Remove start node of next part so that it is not added twice result.RemoveAt(result.Count - 1); SimplifyPath3(rcg, nodes, mid1, end, result, (Vector3)nodes[mid1].position, endPoint, depth + 1); } else { SimplifyPath3(rcg, nodes, start, mid1, result, startPoint, (Vector3)nodes[mid1].position, depth + 1); //Remove start node of next part so that it is not added twice result.RemoveAt(result.Count - 1); SimplifyPath3(rcg, nodes, mid1, mid2, result, (Vector3)nodes[mid1].position, (Vector3)nodes[mid2].position, depth + 1); //Remove start node of next part so that it is not added twice result.RemoveAt(result.Count - 1); SimplifyPath3(rcg, nodes, mid2, end, result, (Vector3)nodes[mid2].position, endPoint, depth + 1); } } }