我正在使用 libgdx
尝试使用此doc绘制一些曲线 .
但是,当我渲染时,它只是一条直线,任何想法为什么它不会弯曲?
我假设 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();
}
}
呈现..
1 回答
catmullrom spline至少需要四个样本 . 因此,您需要添加更多样本才能看到实际曲线 .
Here's an example which you can copy, paste and run .