Points uniformly spread on bézier curve should be functional.

This commit is contained in:
William Moberg
2016-05-26 15:16:23 +02:00
parent fc764b4ec2
commit abffff6482
2 changed files with 19 additions and 13 deletions
+15 -9
View File
@@ -561,8 +561,6 @@ public class BezierCurve : MonoBehaviour {
return points[points.Length - 1].position;
}
float segmentLength = length / 2;
float totalLength = 0;
for (int i = 0; i < points.Length - 1; i++) {
var p1 = points[i];
@@ -579,15 +577,23 @@ public class BezierCurve : MonoBehaviour {
continue;
} else {
var curveDistance = distance - totalLength;
var segmentIndex = (float)Math.Floor(curveDistance / segmentLength);
var segmentStart = segmentIndex * segmentLength;
var segmentEnd = (segmentIndex + 1) * segmentLength;
var segmentDistance = curveDistance - segmentStart;
Vector3 s1 = GetPoint(p1, p2, segmentStart / curveLength);
Vector3 s2 = GetPoint(p1, p2, segmentEnd / curveLength);
//Calculate the very first line segment
Vector3 s1 = p1.position;
Vector3 s2 = GetPoint(p1, p2, 1.0f / resolution);
float mag = (s2 - s1).magnitude;
float polylineLength = mag;
return GetLinearPoint(s1, s2, segmentDistance / segmentLength);
//Keep calculating line segments until we have traveled more than curveDistance.
for (int segmentIndex = 2; polylineLength < curveDistance; segmentIndex++) {
s1 = s2;
s2 = GetPoint(p1, p2, (float)segmentIndex / resolution);
mag = (s2 - s1).magnitude;
polylineLength += mag;
}
//The desired position should be between s1 and s2.
//polylineLength should be slightly greater than curveDistance, the difference gives the 't' value.
return GetLinearPoint(s1, s2, 1 - (polylineLength - curveDistance) / mag);
}
}
+2 -2
View File
@@ -21,14 +21,14 @@ public class WarehouseColumn : MonoBehaviour {
void Update() {
if (Application.isPlaying) {
//offset += Time.deltaTime;
//Offset += Time.deltaTime * 4;
}
foreach (Transform row in rows) {
var i = row.GetSiblingIndex();
var distance = (float)i / (rows.childCount) * curve.length + Offset;
distance = Mathf.Repeat(distance, curve.length);
var pos = curve.GetPointAtDistance(distance);
var pos = curve.GetUniformPointAtDistance(distance);
row.position = pos;
}
}