Beispiel #1
0
    public void Parametrize(int fromSegmentIndex, int toSegmentIndex)
    {
        if (this.knots.Count < 4)
        {
            return;
        }
        int num = Math.Min(toSegmentIndex + 1, this.NbSegments);

        fromSegmentIndex = Math.Max(0, fromSegmentIndex);
        float num2 = 0f;

        if (fromSegmentIndex > 0)
        {
            num2 = this.GetSegmentDistanceFromStart(fromSegmentIndex - 1);
        }
        for (int i = fromSegmentIndex; i < num; i++)
        {
            CatmullRomSpline.SubKnot[] segmentSubKnots = this.GetSegmentSubKnots(i);
            for (int j = 0; j < segmentSubKnots.Length; j++)
            {
                CatmullRomSpline.SubKnot subKnot = default(CatmullRomSpline.SubKnot);
                num2               = (subKnot.distanceFromStart = num2 + this.ComputeLengthOfSegment(i, (float)(j - 1) * this.Epsilon, (float)j * this.Epsilon));
                subKnot.position   = this.GetPositionOnSegment(i, (float)j * this.Epsilon);
                subKnot.tangent    = this.GetTangentOnSegment(i, (float)j * this.Epsilon);
                segmentSubKnots[j] = subKnot;
            }
            this.knots[2 + i].distanceFromStart = num2;
        }
    }
Beispiel #2
0
    public bool PlaceMarker(CatmullRomSpline.Marker result, float distance, CatmullRomSpline.Marker from = null)
    {
        int nbSegments = this.NbSegments;

        if (nbSegments == 0)
        {
            return(false);
        }
        if (distance <= 0f)
        {
            result.segmentIndex  = 0;
            result.subKnotAIndex = 0;
            result.subKnotBIndex = 1;
            result.lerpRatio     = 0f;
            return(true);
        }
        if (distance >= this.Length())
        {
            CatmullRomSpline.SubKnot[] segmentSubKnots = this.GetSegmentSubKnots(nbSegments - 1);
            result.segmentIndex  = nbSegments - 1;
            result.subKnotAIndex = segmentSubKnots.Length - 2;
            result.subKnotBIndex = segmentSubKnots.Length - 1;
            result.lerpRatio     = 1f;
            return(true);
        }
        int num  = 0;
        int num2 = 1;

        if (from != null)
        {
            num = from.segmentIndex;
        }
        for (int i = num; i < nbSegments; i++)
        {
            if (distance <= this.GetSegmentDistanceFromStart(i))
            {
                CatmullRomSpline.SubKnot[] segmentSubKnots = this.GetSegmentSubKnots(i);
                for (int j = num2; j < segmentSubKnots.Length; j++)
                {
                    CatmullRomSpline.SubKnot subKnot = segmentSubKnots[j];
                    if (distance <= subKnot.distanceFromStart)
                    {
                        result.segmentIndex  = i;
                        result.subKnotAIndex = j - 1;
                        result.subKnotBIndex = j;
                        result.lerpRatio     = 1f - (subKnot.distanceFromStart - distance) / (subKnot.distanceFromStart - segmentSubKnots[j - 1].distanceFromStart);
                        break;
                    }
                }
                break;
            }
        }
        return(true);
    }