I'm trying to figure out how to zoom onto a 2D point, and reposition the camera accordingly.
Let's say my current screen space is this gray box, with the top left corner x1, y1. I want to zoom in on that red dot, at Fx, Fy, with zoom amount Z. The resulting screen space should be the blue rectangle. How do I find x2, y2?

Now I've been able to figure out the math of this. It should be:
x2 = x1 + Fx / Z
y2 = y1 + Fy / Z
Right? But it seems to fall apart when zooming out, or when I zoom in again. Zooming out still increases it, since Z is always a positive number. Zooming in multiple times has all sorts of issues.
This seems like a very basic operation, yet I've spent many frustrated hours trying to get it to work. My drawing code works fine. I can pan the image, and I can zoom onto point 0,0 without any issues. So theoretically, zooming onto point F would be the same as zooming onto point 0,0 and panning it to F, right?
Thanks for any help.