Ejemplo n.º 1
0
        public void Build()
        {
            int         idx, count;
            SplinePoint p1, p2, p3, p4;


            if (mPoints.Count < 2)
            {
                mSegments = null;
                Length    = 0;
                return;
            }
            if (WrapType == WrapMode.Loop)
            {
                count = mPoints.Count;
            }
            else
            {
                count = mPoints.Count - 1;
            }

            mSegments = new SplineSegment[count];
            Length    = 0;
            idx       = 0;

            if (WrapType == WrapMode.Loop)
            {
                while (idx < count)
                {
                    p1 = mPoints[XSplineUtil.WrapIndex(idx - 1, mPoints.Count)];
                    p2 = mPoints[XSplineUtil.WrapIndex(idx, mPoints.Count)];
                    p3 = mPoints[XSplineUtil.WrapIndex(idx + 1, mPoints.Count)];
                    p4 = mPoints[XSplineUtil.WrapIndex(idx + 2, mPoints.Count)];

                    mSegments[idx] = new SplineSegment(InterpolateType);
                    if (InterpolateType == SplineType.Linear || InterpolateType == SplineType.Bezier)
                    {
                        BuildSegment(mSegments[idx], p1, p2, p3, p4);
                    }
                    else
                    {
                        BuildSegment(mSegments[idx], p2, p1, p4, p3);
                    }
                    ++idx;
                }
            }
            else
            {
                while (idx < count)
                {
                    p1 = mPoints[XSplineUtil.ClampIndex(idx - 1, mPoints.Count)];
                    p2 = mPoints[XSplineUtil.ClampIndex(idx, mPoints.Count)];
                    p3 = mPoints[XSplineUtil.ClampIndex(idx + 1, mPoints.Count)];
                    p4 = mPoints[XSplineUtil.ClampIndex(idx + 2, mPoints.Count)];

                    mSegments[idx] = new SplineSegment(InterpolateType);
                    if (InterpolateType == SplineType.Linear || InterpolateType == SplineType.Bezier)
                    {
                        BuildSegment(mSegments[idx], p1, p2, p3, p4);
                    }
                    else
                    {
                        BuildSegment(mSegments[idx], p2, p1, p4, p3);
                    }
                    ++idx;
                }
            }
            ++mBuildnum;
        }
Ejemplo n.º 2
0
 public void SetOffsetPercent(float offset)
 {
     offset  = XSplineUtil.WrapPosition(mSpline.WrapType, offset, mSpline.Length);
     mSegidx = mSpline.FindSegment(offset * mSpline.Length);
     mSegpos = offset - mSpline.GetSegmentStartLength(mSegidx);
 }