2015-09-28 230 views
1

我使用libgdx嘗試使用此doc繪製一些曲線。使用libgdx繪製曲線

但是,當我渲染,它只是一條直線,爲什麼它不曲線的任何想法?

我假設myCatmull.valueAt應該填充曲線上的正確點。

public class IABezier { 

    Vector2[] points = new Vector2[100]; 

    public IABezier() { 

     Vector2[] dataSet = new Vector2[2]; 
     dataSet[0] = new Vector2(10.0f, 10.0f); 
     dataSet[1] = new Vector2(20.0f, 20.0f); 

     CatmullRomSpline <Vector2> myCatmull = new CatmullRomSpline <Vector2> (dataSet, true); 
     for (int i = 0; i < 100; ++i) { 

      points[i] = new Vector2(); 
      myCatmull.valueAt(points[i], ((float) i)/((float) 100 - 1)); 
     } 
    } 

    public void draw(ShapeRenderer sRenderer) { 

     sRenderer.begin(ShapeType.Line); 
     sRenderer.identity(); 
     for (int i = 0; i < 100 - 1; ++i) { 

      sRenderer.line(points[i], points[i + 1]); 
     } 
     sRenderer.end(); 
    } 
} 

渲染..

screenshot

回答

1

catmullrom spline需要至少四個樣品。所以你必須添加更多的樣本才能看到實際的曲線。

Vector2[] dataSet = new Vector2[6]; 
    dataSet[0] = new Vector2(10.0f, 10.0f); 
    dataSet[1] = new Vector2(20.0f, 20.0f); 
    dataSet[2] = new Vector2(20.0f, 10.0f); 
    dataSet[3] = new Vector2(10.0f, 20.0f); 
    dataSet[4] = new Vector2(15.0f, 15.0f); 
    dataSet[5] = new Vector2(25.0f, 25.0f); 

Here's an example which you can copy, paste and run