Zooming around the mouse cursor.
I have a question regarding Zooming in and out around the cursor location. If anyone has time or knows a solution I would appreciate it. ;)
I have reached a point where I can't figure out how to solve it. What I wan't to do is be able to zoom where ever the cursor location is on the screen. I have a solution that "kind of" works but when you move the mouse to a new location the display jumps over to the new location, minus the new scaling. Mathematically I understand why it is jumping but I don't know how to solve it. Tons of other programs do this kind of thing all the time.
So I created a simple setup that has a two circles and a box with an axis showing at the world-origin. I can move the mouse somewhere and use the mouse wheel to zoom in and out. That works fine. But if I move the mouse to a new location and try zooming I get the "jump". This is the scenegraph of the simple test harness:
And here is the app running.
And here is the source:
Ctrl-MMB to zoom and LMB to slide the window around.
The orange arrow is my solution based on a typical scaling-about-a-center transform. It works as long as the mouse stays in one place. Basically you translate to the origin, scale, and translate back. This is the same thing done when scaling objects about their center.
So I thought why don't I just update the translation transforms while the mouse moves. This works but the "world" slides around, as you would predict.
Well anyway, I was wondering if anyone already knows the solution for this. My guess is that the solution has something to with an inverse scaling trick but I just can't seem to envision it.
Thanks for any kind ideas. ;)