I'm implementing this simple tutorial
blog.xoppa.com/basic-3d-using-libgdx-2/
but trying to substitute the perspective camera with an orthographic one.
However, I've some problems in understanding how the camera position works:
I added
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()
and I get a very tiny square. If I change the position.
cam2.position.set(0,0,100);
I can't see anything, and I wonder why since the orthographic camera should ignore the z.
Basically what I need is to create a 3D shape and display it at the same time in two different views, one using a perspective came and the other one using a orthographic camera.
Thanks!
Here is the full code
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() {
}
}