public void RenderToLine(AccessibleLineRenderer lineRenderer, float lineWidth) { var args = new LineRenderArgs() { LineWidth = lineWidth, StartDistance = 0.0f, EndDistance = CalculateTotalDistance() }; DrawDubin(lineRenderer, args); }
public List <HeadingPositionPair> AsPointsList(LineRenderArgs args, float distInc) { Vector3 nextPos = Vector3.zero; Vector3 nextDir; int dubinIndex = path.Count - 1; float totalLength = this.CalculateTotalDistance(); float pathDistance = 0.0f; DubinCSC currentDubin = path[path.Count - 1]; // Figure out which Dubin in the list we should start on for (int i = 0; i < path.Count; ++i) { pathDistance += path[i].totalLength; if (args.StartDistance <= pathDistance) { currentDubin = path[i]; dubinIndex = i; pathDistance -= path[i].totalLength; break; //Found our dubin } } // const int numSegmentsPerDubin = 100; // int totalNumSegments = numSegmentsPerDubin * (path.Count - dubinIndex); //float distInc = Mathf.Ceil(currentDubin.totalLength / numSegmentsPerDubin); int numPairs = (int)(totalLength / distInc); List <HeadingPositionPair> pathLines = new List <HeadingPositionPair>(numPairs); for (float distance = args.StartDistance; distance < args.EndDistance;) { float relativeDistanceStart = distance - pathDistance; float relativeDistanceEnd = Mathf.Min(currentDubin.totalLength, args.EndDistance - pathDistance); //float distInc = Mathf.Ceil(currentDubin.totalLength / numSegmentsPerDubin); for (float relativeDistance = relativeDistanceStart; relativeDistance <= relativeDistanceEnd; relativeDistance += distInc) { currentDubin.GetPositionAndHeadingFromDistance(relativeDistance, turnRadius, out nextPos, out nextDir); pathLines.Add(new HeadingPositionPair(nextPos, nextDir)); } // ensure that the last spot is included currentDubin.GetPositionAndHeadingFromDistance(relativeDistanceEnd, turnRadius, out nextPos, out nextDir); pathLines.Add(new HeadingPositionPair(nextPos, nextDir)); distance += currentDubin.totalLength; pathDistance += currentDubin.totalLength; dubinIndex++; if (dubinIndex >= path.Count) { break; } currentDubin = path[dubinIndex]; } return(pathLines); }
public void RenderToLine(AccessibleLineRenderer lineRenderer, LineRenderArgs args) { DrawDubin(lineRenderer, args); }
public void DrawDubin(AccessibleLineRenderer lineRenderer, LineRenderArgs args) { if (path == null || path.Count == 0) { //TEMP lineRenderer.enabled = false; return; } lineRenderer.UnderlyingLineRenderer.SetWidth(args.LineWidth, args.LineWidth); //TEMP if (lineRenderer.enabled == false) { lineRenderer.enabled = true; } Vector3 nextPos = Vector3.zero; Vector3 nextDir; int dubinIndex = path.Count - 1; float totalLength = this.CalculateTotalDistance(); float pathDistance = 0.0f; DubinCSC currentDubin = path[path.Count - 1]; // Figure out which Dubin in the list we should start on for (int i = 0; i < path.Count; ++i) { pathDistance += path[i].totalLength; if (args.StartDistance <= pathDistance) { currentDubin = path[i]; dubinIndex = i; pathDistance -= path[i].totalLength; break; //Found our dubin } } const int numSegmentsPerDubin = 100; int totalNumSegments = numSegmentsPerDubin * (path.Count - dubinIndex); lineRenderer.SetVertexCount(totalNumSegments); //hackery int idx = totalNumSegments - 1; for (float distance = args.StartDistance; distance < args.EndDistance;) { float relativeDistanceStart = distance - pathDistance; float relativeDistanceEnd = Mathf.Min(currentDubin.totalLength, args.EndDistance - pathDistance); float distInc = Mathf.Ceil(currentDubin.totalLength / numSegmentsPerDubin); for (float relativeDistance = relativeDistanceStart; relativeDistance <= relativeDistanceEnd; relativeDistance += distInc) { currentDubin.GetPositionAndHeadingFromDistance(relativeDistance, turnRadius, out nextPos, out nextDir); nextPos.y += 1.0f; lineRenderer.SetPosition(idx--, nextPos); } // ensure that the last spot is included currentDubin.GetPositionAndHeadingFromDistance(relativeDistanceEnd, turnRadius, out nextPos, out nextDir); nextPos.y += 1.0f; lineRenderer.SetPosition(idx, nextPos); distance += currentDubin.totalLength; pathDistance += currentDubin.totalLength; dubinIndex++; if (dubinIndex >= path.Count) { break; } currentDubin = path[dubinIndex]; } int badMath = 0; //for (int i = idx; i < totalNumSegments; i++) for (int i = idx; i >= 0; --i) { badMath++; lineRenderer.SetPosition(i, nextPos); } // Debug.Log("BadMath: " + badMath); }