Java 多个摄像头和剪刀堆栈?

Java 多个摄像头和剪刀堆栈?,java,camera,libgdx,Java,Camera,Libgdx,我目前正在尝试制作一个游戏,我对使用摄像头还是个新手,我认为可能需要两个正交摄像头,但我不确定这是否是最有效的方法,甚至不知道如何做到这一点 基本上,我希望这是它的布局: 主要区域是主要内容所在的地方,这是一个服务器界面。游戏级别是实际游戏部分所在的位置。我目前正在使用剪刀堆栈切割该区域,但通过此演示,结果让我质疑如何进行此操作: public class TestScissorStackAndCamera extends ApplicationAdapter { private

我目前正在尝试制作一个游戏,我对使用摄像头还是个新手,我认为可能需要两个
正交摄像头
,但我不确定这是否是最有效的方法,甚至不知道如何做到这一点

基本上,我希望这是它的布局:


主要区域是主要内容所在的地方,这是一个服务器界面。游戏级别是实际游戏部分所在的位置。我目前正在使用
剪刀堆栈
切割该区域,但通过此演示,结果让我质疑如何进行此操作:

public class TestScissorStackAndCamera extends ApplicationAdapter {

    private SpriteBatch batch;
    private OrthographicCamera camera;
    private Sprite sprite;
    private int width, height;

    @Override
    public void create() {
        Gdx.gl.glClearColor(0, 0, 0, 0);
        width = Gdx.graphics.getWidth();
        height = Gdx.graphics.getHeight();
        batch = new SpriteBatch();
        camera = new OrthographicCamera(width, height);
        camera.position.set(width / 2, height / 2, 0);
        camera.update();
        createSprite();
    }

    private void createSprite() {
        Pixmap map = new Pixmap(width, height, Format.RGBA8888);
        map.setColor(Color.RED);
        map.fillRectangle(0, 0, width, height);
        map.setColor(Color.BLUE);
        map.drawLine(width / 2, 0, width / 2, height);
        map.drawLine(0, height / 2, width, height / 2);
        Texture texture = new Texture(map);
        sprite = new Sprite(texture);
    }

    @Override
    public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.setProjectionMatrix(camera.combined); // The Question!
        batch.begin();
        {
            Rectangle scissors = new Rectangle();
            Rectangle area = new Rectangle(10, 10, width - 20, height - 20);
            ScissorStack.calculateScissors(camera, batch.getTransformMatrix(), area, scissors);
            ScissorStack.pushScissors(scissors);
            batch.draw(sprite, 0, 0);
            batch.flush();
            ScissorStack.popScissors();
        }
        batch.end();
    }

    public static void main(String[] args) {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.title = "ScissorStack & Camera Test";
        config.resizable = false;
        new LwjglApplication(new TestScissorStackAndCamera(), config);
    }
}
提问批处理.setProjectionMatrix(camera.combined)
我在代码中用注释标记了一行,
问题,这是影响结果的因素。如果我没有它,使用
camera.translate(…)
方法,图像在
(0,0)
处绘制,但它所做的是移动查看的部分。如果我有这条线,当我使用
camera.translate(…)
方法时,图像分别绘制到相机的位置

就我目前正在开发的游戏而言,它在没有设置
projectionMatrix
的情况下表现得很糟糕,但是当我设置它时,它会扰乱游戏其余部分的定位。我甚至添加了一些测试功能,但它并没有在正确的
剪刀堆栈中进行渲染

我如何设置两个摄像头,或者如何才能正确有效地设置我正在尝试的内容

我的实际游戏(不是模型)就是这样做的。它应该在红线内渲染,但不是:

如果您想查看我当前处理
剪刀堆栈
正交摄影机
的游戏级别代码:

public GameLevel(int x, int y, int displayWidth, int displayHeight) {
    this.x = x; // x = 10
    this.y = y; // y = 10
    this.displayWidth = displayWidth; // displayWidth = Gdx.graphics.getWidth() - x - 10
    this.displayHeight = displayHeight; // displayHeight = Gdx.graphics.getHeight() - y - 120
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(displayWidth / 2, displayHeight / 2, 0);
    // FBLAGame.batch.setProjectionMatrix(camera.combined);
    camera.update();
    init();
}

...

@Override
public void render() {
    Rectangle area = new Rectangle(x, y, displayWidth, displayHeight);
    Rectangle scissor = new Rectangle();
    Matrix4 matrix = FBLAGame.batch.getTransformMatrix();
    ScissorStack.calculateScissors(camera, matrix, area, scissor);
    ScissorStack.pushScissors(scissor);
    renderLevel();
    FBLAGame.batch.flush();
    ScissorStack.popScissors();
    Pixmap map = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA8888);
    map.setColor(Color.RED);
    map.drawRectangle((int) area.x, (int) area.y, (int) area.width, (int) area.height);
    Texture t = new Texture(map);
    map.dispose();
    FBLAGame.batch.draw(t, 0, 0);
}

如果我理解正确,您希望绘制
level
和某种
HUD
。为此,我建议首先使用
levelCamera
绘制
Level
,然后使用
hudCamera
绘制
HUD
。虽然
levelCamera
可以四处移动并显示
Level
的不同部分,但是
hudCamera
应该始终保持在相同的位置。每次绘制每个投影矩阵时,我会设置投影矩阵吗?如果对
HUD
Level
使用相同的
SpriteBatch
,然后,您需要在每个渲染循环中设置
projectionMatrix
2次:一开始,设置
levelCamera
projectionMatrix
,绘制leven后,设置
hudCamera
projectionMatrix
。如果使用2
SpriteBatch
es,则只需设置
levelBatch
projectionMatrix
每个渲染回路,因为
levelCamera
可以“漫游”。
HUD摄像头
保持在同一点上。只需确保在调用
hudBatch.begin()之前调用
levelBatch.end