我正在实现这个简单的教程
blog.xoppa.com/basic-3d-using-libgdx-2/
但试图用正交相机替换透视相机。
但是,我在理解相机位置的工作原理方面遇到了一些问题:
我补充说
cam2 = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.position.set(0,0,10);
cam2.lookAt(0, 0, 0);
cam2.update()
我得到一个非常小的正方形。如果我改变立场。
cam2.position.set(0,0,100);
我什么都看不到,我想知道为什么正交相机应该忽略 z。
基本上我需要的是创建一个 3D 形状并同时在两个不同的视图中显示它,一个使用透视图,另一个使用正交相机。
谢谢!
这是完整的代码
public class MyGdxGame implements ApplicationListener {
// public PerspectiveCamera cam;
public OrthographicCamera cam2;
public ModelBatch modelBatch;
public Model model;
public ModelInstance instance;
@Override
public void create() {
modelBatch = new ModelBatch();
// cam = new PerspectiveCamera(67, Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
cam2 = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam2.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
// cam.position.set(10f, 10f, 10f);
// cam.lookAt(0, 0, 0);
// cam.near = 1f;
// cam.far = 300f;
// cam.update();
cam2.position.set(0, 0,0);
cam2.lookAt(0, 0, 0);
cam2.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(50f, 50f, 50f,
new Material(ColorAttribute.createDiffuse(Color.GREEN)),
Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
}
@Override
public void render() {
cam2.update();
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(),
Gdx.graphics.getHeight());
// Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
// modelBatch.begin(cam);
// modelBatch.render(instance);
// modelBatch.end();
//
// Gdx.gl.glViewport(Gdx.graphics.getWidth()/2, 0, Gdx.graphics.getWidth()/2,
// Gdx.graphics.getHeight()/2);
//
modelBatch.begin(cam2);
modelBatch.render(instance);
modelBatch.end();
}
@Override
public void dispose() {
modelBatch.dispose();
model.dispose();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}