2

したがって、私の目標は、これに似たスプラインを描くことです(線が各ポイントを通過する場所): ここに画像の説明を入力

ただし、スプラインはループします (終点 2 から始点に戻ります)。

ここに画像の説明を入力

catmullromspline の「連続」ブール値を変更してみましたが、画面の中央にドットしか描画されませんでした。

線画も最後の点に到達した時点で終了しましたが、始点と終点で線がまだ曲がっていたので、結果は醜いものでした。

ソース コードを隅々まで調べましたが、ループを防止できる関数は見つかりませんでした。

そして、私の知る限り、ベジェ スプラインはすべてのポイントを通過するわけではありません (ポイントの近くを通過するだけです)。

それで、私は何をすべきですか?

これが私のコードです:

...
public class GameScreen implements Screen {
    final game game;
    float w=800;
    float h=480;
    OrthographicCamera camera;
    long startTime;

    Texture baseTexture=new Texture(Gdx.files.internal("white.png"));

    public GameScreen(final game gam) {
        this.game = gam;
        startTime = TimeUtils.millis();

        camera = new OrthographicCamera();
        camera.setToOrtho(false, w, h);

        setup();
    }

    //https://github.com/libgdx/libgdx/wiki/Path-interface-&-Splines
    int k = 10000; //increase k for more fidelity to the spline
    Vector2[] points = new Vector2[k];
    Vector2 cp[] = new Vector2[]{
            new Vector2(w/2, h), new Vector2(w/2, h/2),new Vector2(50, 50)
        };
    ShapeRenderer rope=new ShapeRenderer();
    public void setup(){
        CatmullRomSpline<Vector2> myCatmull = new CatmullRomSpline<Vector2>( cp, true);
        for(int i = 0; i < k; ++i)
        {
            points[i] = new Vector2();
            myCatmull.valueAt(points[i], ((float)i)/((float)k-1));
        }
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);  
        Gdx.gl20.glLineWidth(50);
        game.batch.begin();
            rope.setAutoShapeType(true);
            rope.begin();
            for(int i = 0; i < k-1; ++i)
            {
                //rope.line(points[i], points[i+1]);
                //shaper.line(myCatmull.valueAt(points[i], ((float)i)/((float)k-1)), myCatmull.valueAt(points[i+1], ((float)i)/((float)k-1)));
                game.batch.draw(baseTexture, points[i].x, points[i].y, 5, 5);
            }
            rope.end();

            for(int i=0;i<cp.length;i++){//draw the location of each point
                game.font.draw(game.batch, "point "+i, cp[i].x, cp[i].y);
            }


            //logging systems
            for(int i=0;i<20;i++){
                if(Gdx.input.isTouched(i))
                    game.font.draw(game.batch, "x:"+Gdx.input.getX(i)+" y:"+Gdx.input.getY(i), 0, (game.font.getCapHeight()+10)*(i+1));
            }
            game.font.draw(game.batch, "fps:"+Gdx.graphics.getFramesPerSecond()+" log:"+log, 0, h-game.font.getCapHeight());
        game.batch.end();
    }
    ...
4

0 に答える 0