2

I'm trying to draw a curve line using BSpline and ShapeRenderer. With perspective camera I found myself able to do that. If I try to use OrthographicCamera, instead, nothing gets rendered on the screen. My goal is to draw a BSPline with ShapeRenderer and a Sprite that follow the same design as the Shape. Can anyone tell me how to fix this / what I am doing wrong? thanks a lot

public class MyGdxGame extends GdxTest implements ApplicationListener {
    private SpriteBatch spriteBatch;
    ParticleEffect effect;
    int emitterIndex;
    Array<ParticleEmitter> emitters;
    int particleCount = 10;
    float fpsCounter;
    InputProcessor inputProcessor;

    int CAMERA_WIDTH = 640; //Gdx.graphics.getWidth(); if use this function an exception is arose
    int CAMERA_HEIGHT = 480; //Gdx.graphics.getHeight(); if use this function an exception is arose

    BspHbCached hb;
    ShapeRenderer renderer;
    int nPoints;
    private OrthographicCamera camera;

    @Override
    public void create () {
    hb = new BspHbCached(CAMERA_WIDTH/4, CAMERA_WIDTH/4); // caching points for curve to draw
    renderer = new ShapeRenderer();
    nPoints = hb.getNumSamplePoints();

    camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);

    camera.position.set(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f, 0);  
    camera.update();    

    spriteBatch = new SpriteBatch();

    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("data/test.p"), Gdx.files.internal("data"));
    effect.setPosition(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    // Of course, a ParticleEffect is normally just used, without messing around with its emitters.
    emitters = new Array(effect.getEmitters());
    effect.getEmitters().clear();
    effect.getEmitters().add(emitters.get(0));

    inputProcessor = new InputProcessor() {
    public boolean touchUp (int x, int y, int pointer, int button) {
    return false;
    }

Here are my other important methods:

    public void render () {

    float delta = Gdx.graphics.getDeltaTime();
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);


    renderer.setProjectionMatrix(camera.combined);
    spriteBatch.setProjectionMatrix(camera.combined);
    for(int i = 0; i < nPoints - 1; i++) // all points contained in bspline to draw
    {

    renderer.begin(ShapeType.Line);
    renderer.setColor(Color.RED);
    renderer.line(p1,p2);
    renderer.end();
    }


    spriteBatch.begin();
    effect.draw(spriteBatch, delta);
    spriteBatch.end();

    fpsCounter += delta;
    if (fpsCounter > 3) {
    fpsCounter = 0;
    int activeCount = emitters.get(emitterIndex).getActiveCount();
    Gdx.app.log("libgdx", activeCount + "/" + particleCount + " particles, FPS: " + Gdx.graphics.getFramesPerSecond());
    }

    }   
}

NB: my starting point was Path Interface Splines

4

0 回答 0