In a new game I’m making, which I’ve done in LWJGL (woo first LWJGL only game!), I want to be able to zoom and pan around the map. I have that working now, but I want the zooming to be around whatever’s in the center of the map.
Right now, I have a 20x20 grid. If I hit zoom in enough times, the top left tile will fill up the whole area. This is done with:
GL11.glTranslatef((float)( X - xShift ), (float)( Y - yShift ), 0);
GL11.glScalef((float)zoom, (float)zoom, 0);
//all my happy drawing
GL11.glPopMatrix();
So I want it smarter so that when I zoom in, it doesn’t zoom about (0,0) but instead it zooms around whatever happens to be in the center of the screen. What’s the best way to do this?
Also, after that’s done, I want to be able to tell what’s under the mouse. AffineTransform is really nice because it let’s you pass it a coordinate and it’ll tell you where that coordinate is, and you can also ask for it to inversely transform the coordinates. Do I have an option like that with the OpenGL transformation matrix?