public List<Vector3> CurvedNonuniform (List<Vector3> path) {
if (maxSegmentLength <= 0) {
Debug.LogWarning ("Max Segment Length is <= 0 which would cause DivByZero-exception or other nasty errors (avoid this)");
return path;
}
int pointCounter = 0;
for (int i=0;i<path.Count-1;i++) {
//pointCounter += Mathf.FloorToInt ((path[i]-path[i+1]).magnitude / maxSegmentLength)+1;
float dist = (path[i]-path[i+1]).magnitude;
//In order to avoid floating point errors as much as possible, and in lack of a better solution
//loop through it EXACTLY as the other code further down will
for (float t=0;t<=dist;t+=maxSegmentLength) {
pointCounter++;
}
}
List<Vector3> subdivided = ListPool<Vector3>.Claim (pointCounter);
//Set first velocity
Vector3 preEndVel = (path[1]-path[0]).normalized;
for (int i=0;i<path.Count-1;i++) {
//subdivided[counter] = path[i];
//counter++;
float dist = (path[i]-path[i+1]).magnitude;
Vector3 startVel1 = preEndVel;
Vector3 endVel1 = i < path.Count-2 ? ((path[i+2]-path[i+1]).normalized - (path[i]-path[i+1]).normalized).normalized : (path[i+1]-path[i]).normalized;
Vector3 startVel = startVel1 * dist * factor;
Vector3 endVel = endVel1 * dist * factor;
Vector3 start = path[i];
Vector3 end = path[i+1];
//Vector3 p1 = start + startVel;
//Vector3 p2 = end - endVel;
float onedivdist = 1F / dist;
for (float t=0;t<=dist;t+=maxSegmentLength) {
float t2 = t * onedivdist;
subdivided.Add (GetPointOnCubic(start,end,startVel,endVel,t2));
//counter++;
}
preEndVel = endVel1;
}
subdivided[subdivided.Count-1] = path[path.Count-1];
return subdivided;
}