示例#1
0
    public int AddRageSplinePoint(float splinePosition)
    {
        RageSplinePoint[] tmpPoints = new RageSplinePoint[points.Length + 1];

        int newIndex = GetCeilIndex(splinePosition);

        Vector3 tangent = (GetPoint(splinePosition + 0.001f) - GetPoint(splinePosition - 0.001f)).normalized;
        float mag = points[mod(newIndex-1, points.Length)].outCtrl.magnitude * 0.25f + points[mod(newIndex, points.Length)].inCtrl.magnitude * 0.25f;
        tmpPoints[newIndex] = new RageSplinePoint(GetPoint(splinePosition), mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), true);

        //tmpPoints[newIndex] = new RageSplinePoint(GetPoint(splinePosition), GetSmoothCtrlForNewPoint(splinePosition)[0], GetSmoothCtrlForNewPoint(splinePosition)[1], GetWidth(splinePosition), false);

        for (int i = 0; i < tmpPoints.Length; i++)
        {
            if (i < newIndex)
            {
                tmpPoints[i] = points[i];
            }
            if (i > newIndex)
            {
                tmpPoints[i] = points[i-1];
            }
        }
        points = tmpPoints;
        return newIndex;
    }
示例#2
0
    public Vector3 GetPoint(float t)
    {
        if (t < 0.00001f || t > 0.99999f)
        {
            t = mod(t, 1f);
        }

        int   i  = GetFloorIndex(t);
        int   i2 = GetCeilIndex(t);
        float f  = GetSegmentPosition(t);

        RageSplinePoint p1 = points[i];
        RageSplinePoint p2 = points[i2];

        //if (Mathf.Approximately(t, 1f))
        //{
        //    Debug.Log(i + "," + i2);
        //}

        float d  = 1f - f;
        float d2 = d * d;
        float f2 = f * f;

        return(d2 * d * p1.point + 3f * d2 * f * (p1.point + p1.outCtrl) + 3f * d * f2 * (p2.point + p2.inCtrl) + f2 * f * p2.point);
    }
示例#3
0
    public RageCurve(Vector3[] pts, Vector3[] ctrl, bool[] natural, float[] width)
    {
        points = new RageSplinePoint[pts.Length];

        for (int i = 0; i < pts.Length; i++)
        {
            points[i] = new RageSplinePoint(pts[i], ctrl[i * 2], ctrl[i * 2 + 1], width[i], natural[i]);
        }
    }
示例#4
0
    public RageCurve(Vector3[] pts, Vector3[] ctrl, bool[] natural, float[] width)
    {
        points = new RageSplinePoint[pts.Length];

        for (int i = 0; i < pts.Length; i++)
        {
            points[i] = new RageSplinePoint(pts[i], ctrl[i * 2], ctrl[i * 2 + 1], width[i], natural[i]);
        }
    }
示例#5
0
    public int AddRageSplinePoint(float splinePosition)
    {
        var tmpPoints = new RageSplinePoint[points.Length + 1];

        int newIndex = GetCeilIndex(splinePosition);

        Vector3 tangent = (GetPoint(splinePosition + 0.001f) - GetPoint(splinePosition - 0.001f)).normalized;
        float mag = points[mod(newIndex - 1, points.Length)].outCtrl.magnitude * 0.25f + points[mod(newIndex, points.Length)].inCtrl.magnitude * 0.25f;
        //tmpPoints[newIndex] = new RageSplinePoint(GetPoint(splinePosition), mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), true);

        var idxPrev = PointsIndex(newIndex - 1, points);
        var idxNext = PointsIndex(newIndex, points);
        var pointPrev = points[idxPrev];
        var pointNext = points[idxNext];
        var pointCurrent = new RageSplinePoint(GetPoint(splinePosition), mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), false);
        tmpPoints[newIndex] = pointCurrent;

        float previousPointOffset = GetNearestSplinePoint(pointPrev.point, 1000);
        float nextPointOffset = GetNearestSplinePoint(pointNext.point, 1000);
        float currentPointOffset = GetNearestSplinePoint(pointCurrent.point, 1000);

        if (previousPointOffset > currentPointOffset) previousPointOffset -= 1f;
        if (nextPointOffset < currentPointOffset) nextPointOffset += 1f;

        float segmentLength = Mathf.Abs(nextPointOffset - previousPointOffset);

        float t = 0.5f;

        if (!Mathf.Approximately(segmentLength, 0))
            t = Mathf.Abs(currentPointOffset - previousPointOffset) / segmentLength;

        Vector3 newOutCtrl = t * pointPrev.outCtrl;
        Vector3 newInCtrl = (1 - t) * pointNext.inCtrl;

        Vector3 P1_2 = (1 - t) * (pointPrev.point + pointPrev.outCtrl) + (t) * (pointNext.point + pointNext.inCtrl);

        Vector3 P01_12 = (1 - t) * (pointPrev.point + newOutCtrl) + t * P1_2;
        Vector3 P12_23 = (1 - t) * P1_2 + t * (pointNext.point + newInCtrl);

        pointCurrent.inCtrl = pointCurrent.inCtrl.normalized * (P01_12 - pointCurrent.point).magnitude;
        pointCurrent.outCtrl = pointCurrent.outCtrl.normalized * (P12_23 - pointCurrent.point).magnitude;

        pointPrev.outCtrl = newOutCtrl;
        pointNext.inCtrl = newInCtrl;

        // Copy all existing points data to the new point set
        for (int i = 0; i < tmpPoints.Length; i++) {
            if (i < newIndex)
                tmpPoints[i] = points[i];
            if (i > newIndex)
                tmpPoints[i] = points[i - 1];
        }
        points = tmpPoints;
        return newIndex;
    }
示例#6
0
 public void AddRageSplinePoint(int index, Vector3 position, Vector3 inCtrl, Vector3 outCtrl, float width,  bool natural)
 {
     RageSplinePoint[] tmpPoints = new RageSplinePoint[points.Length + 1];
     tmpPoints[index] = new RageSplinePoint(position, inCtrl, outCtrl, width, natural);
     for (int i = 0; i < tmpPoints.Length; i++)
     {
         if (i < index)
         {
             tmpPoints[i] = points[i];
         }
         if (i > index)
         {
             tmpPoints[i] = points[i - 1];
         }
     }
     points = tmpPoints;
 }
示例#7
0
    public void AddRageSplinePoint(int index, Vector3 position, Vector3 inCtrl, Vector3 outCtrl, float width, bool natural)
    {
        var tmpPoints = new RageSplinePoint[points.Length + 1];

        for (int i = 0; i < tmpPoints.Length; i++)
        {
            if (i < index)
            {
                tmpPoints[i] = points[i];
            }
            if (i > index)
            {
                tmpPoints[i] = points[i - 1];
            }
        }
        tmpPoints[index] = new RageSplinePoint(position, inCtrl, outCtrl, width, natural);
        points           = tmpPoints;
    }
示例#8
0
 public void DelPoint(int index)
 {
     if (points.Length > 2)
     {
         RageSplinePoint[] tmpPoints = new RageSplinePoint[points.Length - 1];
         for (int i = 0; i < tmpPoints.Length; i++)
         {
             if (i < index)
             {
                 tmpPoints[i] = points[i];
             }
             if (i >= index)
             {
                 tmpPoints[i] = points[i + 1];
             }
         }
         points = tmpPoints;
     }
 }
示例#9
0
 public void AddRageSplinePoint(int index, Vector3 position)
 {
     RageSplinePoint[] tmpPoints = new RageSplinePoint[points.Length + 1];
     float splinePosition = (float)index / (float)points.Length + 1f / (float)points.Length;
     Vector3 tangent = position - GetPoint(splinePosition - 0.001f).normalized;
     float mag = (points[mod(index, points.Length)].point - points[mod(index + 1, points.Length)].point).magnitude * 0.25f;
     tmpPoints[index] = new RageSplinePoint(position, mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), true);
     for (int i = 0; i < tmpPoints.Length; i++)
     {
         if (i < index)
         {
             tmpPoints[i] = points[i];
         }
         if (i > index)
         {
             tmpPoints[i] = points[i - 1];
         }
     }
     points = tmpPoints;
 }
示例#10
0
 public void AddPoint(float location)
 {
     RageSplinePoint[] tmpPoints = new RageSplinePoint[points.Length + 1];
     int newIndex = GetCeilIndex(location);
     Vector3 tangent = (GetPoint(location+0.001f)-GetPoint(location-0.001f)).normalized;
     float mag = (points[mod(newIndex, points.Length)].point - points[mod(newIndex + 1, points.Length)].point).magnitude * 0.25f;
     tmpPoints[newIndex] = new RageSplinePoint(GetPoint(location), mag * tangent * -1f, mag * tangent, GetWidth(location), true);
     for (int i = 0; i < tmpPoints.Length; i++)
     {
         if (i < newIndex)
         {
             tmpPoints[i] = points[i];
         }
         if (i > newIndex)
         {
             tmpPoints[i] = points[i-1];
         }
     }
     points = tmpPoints;
 }
示例#11
0
    public void DelPoint(int index)
    {
        if (points.Length <= 2)
        {
            return;
        }

        var tmpPoints = new RageSplinePoint[points.Length - 1];

        for (int i = 0; i < tmpPoints.Length; i++)
        {
            if (i < index)
            {
                tmpPoints[i] = points[i];
                continue;
            }
            tmpPoints[i] = points[i + 1];
        }
        points = tmpPoints;
    }
示例#12
0
    public Vector3 CalculateNormal(float t, Vector3 up)
    {
        if (points.Length <= 0)
        {
            return(new Vector3(1f, 0f, 0f));
        }

        t = Mathf.Clamp01(t);
        float t1 = t - 0.001f;

        t1 = mod(t1, 1f);

        int   i1 = GetFloorIndex(t1);
        int   i2 = GetCeilIndex(t1);
        float f1 = GetSegmentPosition(t1);

        RageSplinePoint p1 = points[i1];
        RageSplinePoint p2 = points[i2];

        float t2 = t + 0.001f;

        t2 = mod(t2, 1f);

        int   i3 = GetFloorIndex(t2);
        int   i4 = GetCeilIndex(t2);
        float f2 = GetSegmentPosition(t2);

        RageSplinePoint p3 = points[i3];
        RageSplinePoint p4 = points[i4];

        Vector3 tangent1 = (-3f * p1.point + 9f * (p1.point + p1.outCtrl) - 9f * (p2.point + p2.inCtrl) + 3f * p2.point) * f1 * f1
                           + (6f * p1.point - 12f * (p1.point + p1.outCtrl) + 6f * (p2.point + p2.inCtrl)) * f1
                           - 3f * p1.point + 3f * (p1.point + p1.outCtrl);

        Vector3 tangent2 = (-3f * p3.point + 9f * (p3.point + p3.outCtrl) - 9f * (p4.point + p4.inCtrl) + 3f * p4.point) * f2 * f2
                           + (6f * p3.point - 12f * (p3.point + p3.outCtrl) + 6f * (p4.point + p4.inCtrl)) * f2
                           - 3f * p3.point + 3f * (p3.point + p3.outCtrl);

        return(Vector3.Cross((tangent1.normalized + tangent2.normalized) * 0.5f, up).normalized);
    }
示例#13
0
    public void AddRageSplinePoint(int index, Vector3 position)
    {
        RageSplinePoint[] tmpPoints      = new RageSplinePoint[points.Length + 1];
        float             splinePosition = (float)index / (float)points.Length + 1f / (float)points.Length;
        Vector3           tangent        = position - GetPoint(splinePosition - 0.001f).normalized;
        float             mag            = (points[mod(index, points.Length)].point - points[mod(index + 1, points.Length)].point).magnitude * 0.25f;

        tmpPoints[index] = new RageSplinePoint(position, mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), true);
        for (int i = 0; i < tmpPoints.Length; i++)
        {
            if (i < index)
            {
                tmpPoints[i] = points[i];
            }
            else
            if (i > index)
            {
                tmpPoints[i] = points[i - 1];
            }
        }
        points = tmpPoints;
    }
示例#14
0
    public int AddRageSplinePoint(float splinePosition)
    {
        var tmpPoints = new RageSplinePoint[points.Length + 1];

        int newIndex = GetCeilIndex(splinePosition);

        // TODO: Check if splinePosition/weight doesn't go over 1
        Vector3 tangent = (GetPoint(splinePosition + 0.001f) - GetPoint(splinePosition - 0.001f)).normalized;
        float   mag     = points[mod(newIndex - 1, points.Length)].outCtrl.magnitude * 0.25f + points[mod(newIndex, points.Length)].inCtrl.magnitude * 0.25f;
        //tmpPoints[newIndex] = new RageSplinePoint(GetPoint(splinePosition), mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), true);

        var idxPrev      = PointsIndex(newIndex - 1, points);
        var idxNext      = PointsIndex(newIndex, points);
        var pointPrev    = points[idxPrev];
        var pointNext    = points[idxNext];
        var pointCurrent = new RageSplinePoint(GetPoint(splinePosition), mag * tangent * -1f, mag * tangent, GetWidth(splinePosition), false);

        tmpPoints[newIndex] = pointCurrent;

        float previousPointOffset = GetNearestSplinePoint(pointPrev.point, 1000);
        float nextPointOffset     = GetNearestSplinePoint(pointNext.point, 1000);
        float currentPointOffset  = GetNearestSplinePoint(pointCurrent.point, 1000);

        if (previousPointOffset > currentPointOffset)
        {
            previousPointOffset -= 1f;
        }
        if (nextPointOffset < currentPointOffset)
        {
            nextPointOffset += 1f;
        }

        float segmentLength = Mathf.Abs(nextPointOffset - previousPointOffset);

        float t = 0.5f;

        if (!Mathf.Approximately(segmentLength, 0))
        {
            t = Mathf.Abs(currentPointOffset - previousPointOffset) / segmentLength;
        }

        Vector3 newOutCtrl = t * pointPrev.outCtrl;
        Vector3 newInCtrl  = (1 - t) * pointNext.inCtrl;

        Vector3 P1_2 = (1 - t) * (pointPrev.point + pointPrev.outCtrl) + (t) * (pointNext.point + pointNext.inCtrl);

        Vector3 P01_12 = (1 - t) * (pointPrev.point + newOutCtrl) + t * P1_2;
        Vector3 P12_23 = (1 - t) * P1_2 + t * (pointNext.point + newInCtrl);

        pointCurrent.inCtrl  = pointCurrent.inCtrl.normalized * (P01_12 - pointCurrent.point).magnitude;
        pointCurrent.outCtrl = pointCurrent.outCtrl.normalized * (P12_23 - pointCurrent.point).magnitude;

        pointPrev.natural = pointNext.natural = false;
        pointPrev.outCtrl = newOutCtrl;
        pointNext.inCtrl  = newInCtrl;

        // Copy all existing points data to the new point set
        for (int i = 0; i < tmpPoints.Length; i++)
        {
            if (i < newIndex)
            {
                tmpPoints[i] = points[i];
            }
            if (i > newIndex)
            {
                tmpPoints[i] = points[i - 1];
            }
        }
        points = tmpPoints;
        return(newIndex);
    }
示例#15
0
    public void DelPoint(int index)
    {
        if (points.Length <= 2) return;

        var tmpPoints = new RageSplinePoint[points.Length - 1];
        for (int i = 0; i < tmpPoints.Length; i++) {
            if (i < index) {
                tmpPoints[i] = points[i];
                continue;
            }
            tmpPoints[i] = points[i + 1];
        }
        points = tmpPoints;
    }
示例#16
0
 public void flipPointOrder()
 {
     RageSplinePoint[] newPoints = new RageSplinePoint[GetPointCount()];
     for (int i = 0; i < GetPointCount(); i++)
     {
         Vector3 inCtrl = spline.points[GetPointCount() - i - 1].inCtrl;
         Vector3 outCtrl = spline.points[GetPointCount() - i - 1].outCtrl;
         newPoints[i] = spline.points[GetPointCount() - i - 1];
         newPoints[i].inCtrl = outCtrl;
         newPoints[i].outCtrl = inCtrl;
     }
     spline.points = newPoints;
 }
示例#17
0
 private int PointsIndex(int index, RageSplinePoint[] pointsArray)
 {
     return mod(index, pointsArray.Length);
 }