Hello everyone! I am attempting to make a 2D top down “map” sort of thing in Processing for a simulation I’m working on. I’m trying to make it so you can pan the camera with WASD and zoom into the point where your mouse is with the scroll wheel. However, I can’t figure out how to make it zoom in on the point where the mouse is without also causing the mouse to move the whole map around. The above code is what I currently have
Note: the w, a, s, and d variables are booleans that are just true if you hold down that key, those arent the source of the issue.
I know the issue is something with the scale function, since the second I comment it out it no longer interferes with the position of the grid I’m drawing
@jafal That’s not quite what I’m looking for, thank you for the reply though! I have a top down map(imagine like a minimap from a video game) and I can pan around it with WASD and I want the camera to zoom in on the point of the position of the mouse on said map. So the center of the zoom should be the mouseX and mouseY
As you can see, it’s able to zoom in on the point where the mouse is, but the entire grid also follows the mouse(but only when the zoom scale isnt equal to 1) when the position of the map should only be able to be changed by WASD
Also note: I use the scroll wheel to change the camScale variable
Basically I just cant figure out how to stop the grid from moving alongside the mouse while also still allowing it to zoom in on where the mouse is located
Just as a quick update, I ended up figuring it out! So it turns out I was performing the zooming correctly, but the issue was in the fact that the camera’s origin is in the top left corner. So when I zoomed out, the entire camera appeared to move down and to the right. I fixed it by just adding code to shift the camera up and to the left by half of the amount that it zooms if that makes sense
draw() should not translate by the mouse position. Instead, when you change the scale, you need to change camX and camY so that they move relative to the world-space position of the mouse.
I simplified draw() and updated mouseWheel() to make the changes: