2
\$\begingroup\$

I've just started developing game in android using LibGDX. I've follow some samples and now my simple game can draw path when user move their finger around the screen.

now problems appear when i add another feature to allow user to pinch zoom in and out. after zooming OUT the orthographic camera user can still draw the path BUT the path can no longer follow user finger to the edge of the screen, the user can only draw the path around the center of the screen. looks like the coordinate projection after zoom out not changed and still limited to the projection before zoom out!

how can i make my game to keep drawing line around the entire screen even after the user have zooming out the camera?

here's my code:

   1. in my Screen implemented class:

@Override
public void render(float arg0) {
    Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    Gdx.gl.glEnable(GL20.GL_BLEND);
    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    renderer.render();
}


@Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        // TODO Auto-generated method stub
        isDrawing = true;

        Vector2 v = new Vector2(screenX, Gdx.graphics.getHeight()-screenY);

        //add new point for drawing path
        inputPoints.insert(v);

        return true;
    }

   2. in my Renderer class:

cam = new OrthographicCamera();
    cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    this.cam.update();

public void setZoom(float zoom) {
     this.cam.zoom = zoom;
     this.cam.update();
 }

//the triangle strip renderer
    path = new PathClass();

public void render() {
    cam.update();
    batch.setProjectionMatrix(cam.combined);

    //generate the triangle strip from our path
    Array<Vector2> xox = screen.path();
    path.update(xox);

    //the vertex color for tinting, i.e. for opacity
    path.color = Color.WHITE;

    //render the triangles to the screen
    path.draw(cam);
}

   3. on my PathClass:

public void draw(Camera cam) {
    if (tristrip.size<=0)
        return;

    gl20.begin(cam.combined, GL20.GL_TRIANGLE_STRIP);
    for (int i=0; i<tristrip.size; i++) {
        if (i==batchSize) {
            gl20.end();
            gl20.begin(cam.combined, GL20.GL_TRIANGLE_STRIP);
        }   
        Vector2 point = tristrip.get(i);
        gl20.color(color.r, color.g, color.b, color.a);
        gl20.vertex(point.x, point.y, 0f);
    }
    gl20.end();
}
\$\endgroup\$
2
  • \$\begingroup\$ Did you eventually figure this out? \$\endgroup\$
    – Jax
    May 11, 2015 at 15:59
  • \$\begingroup\$ If you did you could post the answer to your problem and I will up vote. \$\endgroup\$
    – Jax
    May 11, 2015 at 16:00

1 Answer 1

0
\$\begingroup\$
Vector3 v = new Vector3(screenX, Gdx.graphics.getHeight()-screenY, 0);

camera.unproject(v);//converts v to world coords
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .