Ejemplo n.º 1
0
 public static List<Vector2> GetSmoothPoint(List<Vector2> targetArray, float precision, bool headtotial = true)
 {
     //1.获取采样点
     if (precision == 1) { return targetArray; }
     List<Vectorr2> samplePoint = new List<Vectorr2>();
     int samcount = (int)((float)targetArray.Count * precision);
     int interval = targetArray.Count / samcount;
     for (int sam = 0; sam < samcount; sam++)
     {
         Vector2 get = targetArray[sam * interval];
         samplePoint.Add(new Vectorr2(get.x, get.y));
     }
     samplePoint.Add(new Vectorr2(targetArray[targetArray.Count - 1].x, targetArray[targetArray.Count - 1].y));
     //2.从采样点开始对用户画的点数据进行重采样
     List<Vector2> tempToGl = new List<Vector2>();//准备交给Gl的数据
     int glCount = targetArray.Count;
     float inter = 1.0f / (float)glCount;
     for (float a = 0; a < 1; )
     {
         Vectorr2[] test1 = new Vectorr2[samcount + 1];
         samplePoint.CopyTo(test1);
         Vectorr2 myV = GetBezierPoint(test1, a);
         tempToGl.Add(new Vector2(myV.x, myV.y));
         a += inter;
     }
     //3.将重建的点数据处理并交给Gl
     if (headtotial)
         tempToGl[tempToGl.Count - 1] = tempToGl[0];
     return tempToGl;
     //结束平滑代码
 }
Ejemplo n.º 2
0
 public static int GetCount(Vectorr2[] list)
 {
     int count = 0;
     for (int a = 0; a < list.Length; a++)
     {
         if (list[a] != null) count++;
     }
     return count;
 }
Ejemplo n.º 3
0
 //t从0-1
 public static Vectorr2 GetBezierPoint(Vectorr2[] pointList, float t)
 {
     int count = GetCount(pointList);
     if (count == 1)
     {
         return pointList[0];
     }
     else
     {
         for (int a = 0; a < count - 1; a++)
         {
             pointList[a] = (1 - t) * pointList[a] + t * pointList[a + 1];
         }
         pointList[count - 1] = null;
         return GetBezierPoint(pointList, t);
     }
 }