Zoom to mouse position

Started by
0 comments, last by Drew_Benton 19 years ago
Hi, I'm having a hard time just getting this to work. I have a 2D zoomable map using glortho and glscale. Now the zooming alone is no problem, as long as it's done with respect to the center. Now I want to zoom in on whereever the mouse is at, and after the zoom I want my mouse to be at the exact same position as it was before the zoom. I'm translating (the center) before my drawing actions, so I figure that applying some sort of factor to this translation will result in the effect I'm seeking. Only, it's not. [sad] ( The center and mouse positions are available in the world coordinate system.) Anyone ever done anything like that? If so, how did you do it? tia, CipherCraft
Advertisement
Quote:Original post by CipherCraft
Now I want to zoom in on whereever the mouse is at, and after the zoom I want my mouse to be at the exact same position as it was before the zoom.


Just a quick question on the theory, if you zoom in on a point, doesn't thatpoint the become the center? I mean when you click somewhere and want it to be zoomed, wouldn't it be more natural to let the cursor take on as the new center position? Just an idea.

As for how you could go about this, if you know the center of the screen, and you know the mouse position before the zoom, you should be able to set the mouse position to where it was after the zoom. To do this, instead of translating the center to the mouse point, you would only trnslate the offest from the center of the screen to the mouse position.

So I guess the best way I could explain it is if you setup a proportion to where the mouse was before the zoom, then set it to that after the zoom. That way, I think it would be easy to get what you are after. For example, if you have a 100x100 screen and you click at 10x10, the proportion would be 10/100 = .10. If your new zoom area is now 10x10, then you set the position by that, to which your cursor would not be at 1,1 - 10 * .1, 10 * .1

I have not tried any of this nor done this before, but it is one idea of how I would go about it. Good luck!

This topic is closed to new replies.

Advertisement