Camera zooming on specific point

I’m using LibGDX, and I’d very much like to zoom in on something specific in my game.
Using the OrthographicCamera, changing the zoom field works wonders, but it zooms in on the center of the screen.

I’d like to move the camera while zooming, so that the point I’m zooming in on, remains on the same window-coordinate.

This would require some magic, figuring out how much I need to move the camera and in what direction, based on a point.

This is my attempt at it. Needless to say, it doesn’t work as expected.

public void zoomMaintainPoint(int x, int y, float zoom, OrthographicCamera camera) {
		Vector3 pointToMaintain = new Vector3(x, y, 0);
		camera.project(pointToMaintain);
		camera.zoom = zoom;
		Vector3 pointNewPos = new Vector3(pointToMaintain);
		camera.unproject(pointNewPos);
		int deltaX = (int) (pointNewPos.x - pointToMaintain.x);
		int deltaY = (int) (pointNewPos.y - pointToMaintain.y);
		camera.translate(deltaX, deltaY);
	}

I’m as clueless as you, and I also need this :confused:

Orthographic projections don’t have a real zoom…you can only scale & translate.

I’m quite aware. I think you can see through that flaw in my statement, to help me though. :slight_smile:
I think you know what I meant with the original question.

[quote]final Point2DFloat before = getMouseCoordInGame();
updateViewport();
final Point2DFloat after = getMouseCoordInGame();
Camera.setCameraPos2D(Camera.getLookingAt().getX() + before.getX() - after.getX(), Camera.getLookingAt().getY() + before.getY() - after.getY());
[/quote]
This is the code in the State of Profit map that handles that. In general, check where the mouse was (in the game, not in the applet), do the zoom, check where it is after and move the camera the difference. :slight_smile:

Mike

That is what I was doing, and I’m confident I can make it work now.
I think my only problem was that I did not update the camera after zooming it. Obviously, project/unproject isn’t going to work, if it’s not updated.

Thanks again.