Ejemplo n.º 1
0
        public override void Build()
        {
            int idx, count;
            BezierSplinePoint pp, sp, ep, np;

            //
            if (m_points.Count < 2)
            {
                m_segments = null;
                m_length   = 0;
                return;
            }
            if (m_wrapmode == SplineWrapMode.Loop)
            {
                count = m_points.Count;
            }
            else
            {
                count = m_points.Count - 1;
            }
            //
            m_segments = new BezierSplineSegment[count];
            m_length   = 0;
            idx        = 0;
            if (m_wrapmode == SplineWrapMode.Loop)
            {
                while (idx < count)
                {
                    pp = m_points[SplineUtil.WrapIndex(idx - 1, m_points.Count)];
                    sp = m_points[SplineUtil.WrapIndex(idx, m_points.Count)];
                    ep = m_points[SplineUtil.WrapIndex(idx + 1, m_points.Count)];
                    np = m_points[SplineUtil.WrapIndex(idx + 2, m_points.Count)];

                    m_segments[idx] = new BezierSplineSegment();
                    BuildSegment(m_segments[idx], pp, sp, ep, np);
                    ++idx;
                }
            }
            else
            {
                while (idx < count)
                {
                    pp = m_points[SplineUtil.ClampIndex(idx - 1, m_points.Count)];
                    sp = m_points[SplineUtil.ClampIndex(idx, m_points.Count)];
                    ep = m_points[SplineUtil.ClampIndex(idx + 1, m_points.Count)];
                    np = m_points[SplineUtil.ClampIndex(idx + 2, m_points.Count)];

                    m_segments[idx] = new BezierSplineSegment();
                    BuildSegment(m_segments[idx], pp, sp, ep, np);
                    ++idx;
                }
            }

            ++m_buildnum;

            if (OnSplineRebuild != null)
            {
                OnSplineRebuild();
            }
        }
Ejemplo n.º 2
0
 public void SetOffset(float offset)
 {
     offset   = SplineUtil.WrapPosition(m_spline.WrapMode, offset, m_spline.Length);
     m_segidx = m_spline.FindSegment(offset);
     m_segpos = offset - m_spline.GetSegmentStartLength(m_segidx);
 }