[toy] Make the example more interactive
This change implements some of the improvements listed in #85 .
Merge request reports
Activity
added 2 commits
added 1 commit
- 873618fc - [toy] Use the mouse wheel for the range value
added 5 commits
Toggle commit listadded 1 commit
- 9d1e8e08 - [toy] Adjust the starting coordinates for a good map view
Yes, well it's certainly an improvement over the current state of the example, and I don't have the time right now to make improvements of my own (unfortunately).
The only thing I would say is that currently the mouse scrolling is done relative to the center of the window, but I think it should be done relative to the cursor position. As it is, scrolling in and then back out ends up translating the view if the cursor isn't centered in the middle of the window.
I'm hoping to be able to find time to rewrite the examples to handle window resizing and multiple windows. I don't think it's that hard, but it's a bit tiresome as you end up having to change all the examples and account for the current implementation of the shader reload watcher. There shouldn't be anything particularly difficult about it though.
Here's a formula I've used in this situation:
-- Compute the new window center after scrolling. newCenter oldZoomFactor newZoomFactor ( V2 old_x old_y ) ( V2 mouse_x mouse_y ) = let r = 1 - oldZoomFactor / newZoomFactor in V2 ( old_x + r * ( mouse_x - old_x ) ) ( old_y + r * ( mouse_y - old_y ) )
For the scroll, I'm trying to make it similar to what google map do, though the current implementation doesn't work well. It seems like zoom out should not be affected by the mouse position, and for zoom in, we just need to make sure the current mouse position stay in the screen.
And to handle multiple windows, I started the work in !22 (merged) where I'm just duplicating the code for the toy example.
I opened Google Maps to confirm, and they indeed always scroll in/out around the mouse cursor, not around the center of the screen.
The formula I wrote in my previous post should be all you need to compute the new image center after a scroll event; the whole point is that when scrolling, the point that's under the mouse cursor should not move.mentioned in issue #85