In this project I’m working on, I’ve implemented panning and zooming around. Panning works great, and the zoom works, but it’s unnatural, as it zooms in on the origin instead of where your mouse cursor is.
I’ve created a basic version here which basically is what I have right now. I would like it so that you can zoom in at the mouse pointer, not at the origin instead. I’ve searched through this forum and have found several posts on this topic, (including this, this, and this) and I have tried to implement them with no success.
I know I need to first translate to the camera. (for panning) Afterward, I’m not sure exactly what to do, but I know I need to translate, then scale, and probably translate back.
What I have is:
translate(camera); // 2d vector scale(zoom); // float, higher number is more zoomed in
I’ve tried many things, but this is the closest I got:
translate(camera); translate(mouseX, mouseY); scale(zoom); translate(-mouseX, -mouseY);
I would really appreciate it if someone could help me with this!