mardi 14 juin 2016

LIBGDX: How do you horizontally/vertically flip a camera view?

I am trying to create a four way symmetric program that has 1 camera viewing a specific scene, but just flipping the view of the camera for each of the 4 panels.

For example: symmetry

Quadrant 1 would be the regular orientation of the world with positive x to the right and positive y upwards. Quadrant 2 would be positive x to the left and positive y upwards, and so on.

I've figured out a way to draw the same camera view in multiple panels by starting and ending my spritebatch multiple times (not sure if this is a bad thing but it's the way I got it to work) and changing the glViewport of each panel.

    batch.setProjectionMatrix(cam.combined);

    batch.begin();        
    Gdx.gl.glViewport(0,Gdx.graphics.getHeight()/2,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
    batch.draw(img, 0, 0);
    batch.end();

    batch.begin();
    Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
    batch.draw(img, 0, 0);
    batch.end();        

    batch.begin();
    Gdx.gl.glViewport(Gdx.graphics.getWidth()/2,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
    batch.draw(img, 0, 0);
    batch.end();

    batch.begin();
    Gdx.gl.glViewport(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2);
    batch.draw(img, 0, 0);
    batch.end();

I think a linear transformation would do it but I haven't worked with libgdx or linear algebra enough to see an immediate clear answer.

Any help would be appreciated. Thanks.

Aucun commentaire:

Enregistrer un commentaire