# libGDX - Why do I have to use camera.setToOrtho what does it do?

I am very confused about camera matrices and I don't know where to start my studying. Maybe I have to study OpenGL, but I don't know C++ ...

Ok so I have a camera, Box2d world and a Box2d body.

private World world;
private Box2DDebugRenderer b2dr;
private OrthographicCamera cam;
private Body player;

@Override
public void create () {
//Create the world without gravity
world = new World(new Vector2(0, 0), false);
b2dr = new Box2DDebugRenderer();
//I create my camera
cam = new OrthographicCamera();

//Create the player
BodyDef bdef = new BodyDef();
bdef.type = BodyDef.BodyType.DynamicBody;

//Sets the body position to the center of the screen
bdef.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

player = world.createBody(bdef);
CircleShape shape = new CircleShape();
player.createFixture(shape, 1f);
}

@Override
public void render () {
world.step(1f/60f, 6, 2);

Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

b2dr.render(world, cam.combined);
}


I am not seeing the player on the center of the screen, just a black void.

But if I add cam.setToOrtho(false); I see the player! Why is that?

setToOrtho sets the camera to Orthographic projection WHY?

The camera is Orthographic what oder projection can it have?? Isn't the orthographic projection obvious?

• According to the documentation, setToOrtho is not about setting it ortho or not ortho, it's about where does the y axis points: up or down. Aug 8 '16 at 17:19
• Both setToOrtho(false) and setToOrtho(true) work, so that shouldn't be the case... Aug 8 '16 at 17:33
• Well maybe the important part is "Sets this camera to an orthographic projection using a viewport fitting the screen resolution, centered at (Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2)". Not sure, though, I'm not an expert in libGDX. Aug 8 '16 at 17:37
• My question is more general... I want to know why I have to set an Orthographic camera to orthographic projection, isn't this by default? I mean what oder projection can an orthographic camera have... Aug 8 '16 at 17:42

setToOrtho does not set the projection type of the camera. An OrthographicCamera will always have an orthographic frustrum.
Looking at the source, it seems to me that setToOrtho is a convenience method to set the viewport size to the screen size and center the camera on the viewport. setToOrtho(false) is showing your character is because your character is within this default viewport that setToOrtho creates.
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

And then every time you change any parameters of your camera, you must call cam.update(); before any draw calls. I usually end up changing the camera so often that I call this every frame.