public float FastArcLength(Dc2dWaypoint wp) { float arcLength = 0.0f; Dc2dUtils.ArcLengthUtil(wp.position, wp.position + wp.tanOne, wp.endPosition + wp.tanTwo, wp.endPosition, 5, ref arcLength); return(arcLength); }
private void renderTrack() { for (int j = 0; j < allWaypoints.Length - 1; j++) { for (int i = 1; i <= accuracy; i++) { float t = i / (float)accuracy; int nodeIndex = j * 3; Vector3 pixel = Dc2dUtils.CalculateCubicBezierPoint(t, allWaypoints[j].position, allWaypoints[j].position + allWaypoints[j].tanOne, allWaypoints[j].endPosition + allWaypoints[j].tanTwo, allWaypoints[j].endPosition); lineRenderer.positionCount = ((j * accuracy) + i); lineRenderer.SetPosition((j * accuracy) + (i - 1), pixel); } } lineRenderer.enabled = true; trackRendererUpdated = true; }
public Vector3 getTrackedObjectBasedPosition(Vector3 trackedObject) { Vector3 reVector = Vector3.zero; bool pointFound = false; for (int i = 0; i < allWaypoints.Length - 1; i++) { if (trackedObject.x > allWaypoints[i].position.x && trackedObject.x < allWaypoints[i + 1].position.x) { pointFound = true; // get start point Vector3 startPoint = allWaypoints[i].position; // distance of x into dolly line (0-1) float distance = 1.0f - (allWaypoints[i].endPosition.x - trackedObject.x) / (allWaypoints[i].endPosition.x - allWaypoints[i].position.x); // multiply vector by distance reVector = Dc2dUtils.CalculateCubicBezierPoint(distance, allWaypoints[i].position, allWaypoints[i].position + allWaypoints[i].tanOne, allWaypoints[i].endPosition + allWaypoints[i].tanTwo, allWaypoints[i].endPosition); } } // if lock to track if (lockOnTrack) { if (trackedObject.x < allWaypoints[0].position.x) { reVector = allWaypoints[0].position; pointFound = true; } else if (trackedObject.x > allWaypoints[allWaypoints.Length - 1].position.x) { reVector = allWaypoints[allWaypoints.Length - 1].position; pointFound = true; } } if (!pointFound) { reVector = trackedObject; } return(reVector); }