1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using UnityEngine;
- namespace ARLocation
- {
-
-
-
-
- public class CatmullRomSpline : Spline
- {
-
-
-
- private Vector3 startHandle;
-
-
-
- private Vector3 endHandle;
-
-
-
- public float Alpha
- {
- get
- {
- return alpha;
- }
- set
- {
- alpha = value;
- CalculateSegments(lastSampleSize);
- }
- }
- float alpha;
- int lastSampleSize;
-
-
-
-
-
-
- public CatmullRomSpline(Vector3[] points, int n, float alpha)
- {
- Points = (Vector3[])points.Clone();
- this.alpha = alpha;
- CalculateSegments(n);
- }
-
-
-
-
- public sealed override void CalculateSegments(int n)
- {
- lastSampleSize = n;
- segmentCount = (Points.Length - 1);
- lengths = new float[segmentCount];
- segments = new Curve[segmentCount];
- startHandle = 2 * Points[0] - Points[1];
- endHandle = 2 * Points[segmentCount] - Points[segmentCount - 1];
- Length = 0;
- for (var i = 0; i < segmentCount; i++)
- {
- segments[i] = new CatmullRomCurve(
- i == 0 ? startHandle : Points[i - 1],
- Points[i],
- Points[i + 1],
- (i + 1) == segmentCount ? endHandle : Points[i + 2],
- Alpha
- );
- Length += segments[i].EstimateLength(n);
- lengths[i] = Length;
- }
- }
- }
- }
|