Hello Guest

Making a working "camera" in a 2D orthogonal environment

  • 17 Replies
  • 26165 Views
Re: Making a working "camera" in a 2D orthogonal environment
« Reply #15 on: October 19, 2010, 15:06:18 »
This is what I came up with:

        Camera c = DataManager.getCurrentCamera();
       
        GL11.glScaled(c.getZoom(), c.getZoom(), 1);
        double w = Display.getDisplayMode().getWidth()/2;
        double h = Display.getDisplayMode().getHeight()/2;
        GL11.glTranslated(-c.getX() + w / c.getZoom(), -c.getY() + h / c.getZoom(), 0);


I put it right after I draw the background of the scene. It was the simplest I could get it.

Re: Making a working "camera" in a 2D orthogonal environment
« Reply #16 on: October 20, 2010, 03:27:28 »
Here is an example of my camera
Code: [Select]
    private void renderCamera(Camera camera) {
        // Size And Position
        Vector3f pos = camera.getPosition();
        Vector3f size = camera.getViewport();
        Vector3f center = camera.getCenter();
        // Do we need to zoom the camera?
        float zoomFactor = camera.getZoom();
        if (zoomFactor != 1.0f) {
            GL11.glViewport(0, 0, (int) size.x, (int) size.y);
            GL11.glOrtho(0, size.x / zoomFactor, size.y / zoomFactor, 0, -100, 100);
        }
        // Move the matrix with teh camerca
        GL11.glTranslatef(-pos.x + center.x, -pos.y + center.y, pos.z);
        GL11.glRotatef(camera.getRotation(), 0.0f, 0.0f, 1.0f);
        GL11.glTranslatef(-center.x, -center.y, -pos.z);
    }

Re: Making a working "camera" in a 2D orthogonal environment
« Reply #17 on: October 21, 2010, 11:09:32 »
I see. Very nice.

Thanks for all the help, everyone.