Some days ago, I've felt a need to add a camera to my game, it's a puzzle. That would let me move the board, zoom in and etc. This gave me control to do boards muuuch larger, soon, more complex puzzles.
But today when i was implementing such a toolbar, I've found which problems the camera gave me too.
In logic, it is simple. I want the toolbar to be fixed, and the board be free. That is, when I zoom in, the board zoom, but the toolbar stays.
My camera code look as follows:
public void Camera::draw(GL10 gl) {
gl.glMatrixMode(GL10.GL_PROJECTION); // Select the projection matrix
gl.glLoadIdentity(); // Reset the projection matrix
gl.glOrthof(0.0f, width * zoom, 0.0f, height * zoom, 0.0f, 1.0f);
// Translating
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(-position.X, -position.Y, 0);
}
Very simple, but stills functional.
To draw a scene I do the following:
public void Game::draw(GL10 gl) {
camera.draw(gl);
currentLevel.board.draw(gl);
}
I've came with the problem to add the toolbar.
public void draw(GL10 gl) {
toolbar.draw(gl);
camera.draw(gl);
currentLevel.board.draw(gl);
}
I've thought about letting it came first than the camera draw, so it would be fixed. I was wrong.
Nice images examples for you:
A normal board
The effect expected for zoom in, just the board zooms
The effect that i got when i zoom in everything zooms, even the draw that came before the camera.
You can think of this as a camera that supports HUD. I saw people solving this by using a scale factor instead of using glOrthof. But this would mess all my coordinate system. Are there any other alternative for me? If so, how can I implement it?