2016-06-13 16 views
0

1つのカメラが特定のシーンを表示するが、4つのパネルのそれぞれに対してカメラのビューを反転させる4方向対称プログラムを作成しようとしています。例えばLIBGDX:カメラビューをどのように水平/垂直に反転させますか?

symmetry

象限1は、右及び正のy上方に正のxと世界の定期的な向きであろう。 象限2は、左に正のx、上に正のyなどとなります。

複数のパネルで同じカメラビューを描画する方法を考えましたが、これはスプライトバッチを複数回開始したり終了したりすることで(これは悪いことではないかどうかはわかりませんが、各パネルのglViewport。

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(); 

私は線形変換がそれを行うだろうと思いますが、私はlibgdxまたは即時明確な答えを参照するのに十分な線形代数で働いていません。

ご協力いただければ幸いです。ありがとう。

答えて

0

次のコンストラクタを使用して、それTextureRegion 1にをキャストできるテクスチャのインスタンスがある場合。カメラに

を反転

は、カメラをいじってなくてフリップを行うための周りに行列を保管してください。

private final Matrix4 tmpM = new Matrix4(); 

その後、次の3つの裏返し象限のためにそれを反転することができます

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

Gdx.gl.glViewport(0,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2); 
batch.setProjectionMatrix(tmpM.set(cam.combined).scl(1, -1, 1)); 
batch.begin();   
batch.draw(img, 0, 0); 
batch.end(); 

Gdx.gl.glViewport(Gdx.graphics.getWidth()/2,0,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2); 
batch.setProjectionMatrix(tmpM.set(cam.combined).scl(-1, -1, 1)); 
batch.begin();   
batch.draw(img, 0, 0); 
batch.end(); 

Gdx.gl.glViewport(Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2,Gdx.graphics.getWidth()/2,Gdx.graphics.getHeight()/2); 
batch.setProjectionMatrix(tmpM.set(cam.combined).scl(-1, -1, 1)); 
batch.begin();   
batch.draw(img, 0, 0); 
batch.end(); 

フレームバッファ

シーンが複雑な場合、実際のシーンが一つだけ描かれているので、これは速いかもしれ時間。サイズ変更でフレームバッファオブジェクトを作成します。 try/catchは、古いか予算の低い電話の中には、フレームバッファオブジェクト内のRGBA8888カラーをサポートしていないものがあるためです。次のように

public void resize (int width, int height){ 
    if (frameBuffer != null) frameBuffer.dispose(); 
    try { 
     frameBuffer = new FrameBuffer(Pixmap.Format.RGBA8888, width/2, height/2, false); 
    } catch (GdxRuntimeException e) { 
     frameBuffer = new FrameBuffer(Pixmap.Format.RGB565, width/2, height/2, false); 
    } 
} 

そして、それを使用する:

frameBuffer.begin(); 
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
batch.setProjectionMatrix(cam.combined); 
batch.begin();   
batch.draw(img, 0, 0); 
batch.end(); 
frameBuffer.end(); 

Texture fbTex = frameBuffer.getColorBufferTexture(); 
batch.getProjectionMatrix().idt(); 
batch.begin(); 
batch.draw(fbTex, -1, 1, 1, -1); 
batch.draw(fbTex, -1, 0, 1, 1); 
batch.draw(fbTex, 0, 0, 1, 1); 
batch.draw(fbTex, 0, 1, 1, -1); 
batch.end(); 
0

あなただけbatch.draw()

void flip(boolean x, boolean y); 

メソッドを使用してTextureRegionを反転させることができます。

imgはあなたがこれを行うことができますカップルの方法があります

public TextureRegion(Texture texture) 
関連する問題