Skip to content
Snippets Groups Projects

[toy] Make the example more interactive

Merged Tristan de Cacqueray requested to merge TristanCacqueray/fir:pretty-toy into master

This change implements some of the improvements listed in #85 .

Edited by Tristan de Cacqueray

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added 3 commits

    • 2759021e - [toy] Compute FPS
    • f63ba021 - [toy] Add a Play/Pause button to stop the simulation
    • cdb29ba1 - [toy] Show FPS in the ImGui window

    Compare with previous version

  • Tristan de Cacqueray changed title from [toy] Use the window dimention defined in the Shader module to [toy] Make the example more interactive

    changed title from [toy] Use the window dimention defined in the Shader module to [toy] Make the example more interactive

  • Tristan de Cacqueray changed the description

    changed the description

  • added 2 commits

    • 30f24f8c - [examples] Add mouseWheel input
    • b30db3e3 - [toy] Use the mouse wheel for the range value

    Compare with previous version

  • added 1 commit

    • 873618fc - [toy] Use the mouse wheel for the range value

    Compare with previous version

  • added 2 commits

    • 34007d09 - [examples] Add pos2Coord helper function
    • 822813c5 - [toy] Adjust origin location on mouse scroll

    Compare with previous version

  • added 5 commits

    • a0112a80 - [toy] Adjust for screen ratio
    • 99b14519 - [toy] Discard inputs captured by dear imgui
    • 28a0d004 - [toy] Handle mouse click to change the origin
    • 4fc79e20 - [toy] Use the sliders to change the color and max iter
    • e6a8bad2 - [toy] Add toggle to see the map view

    Compare with previous version

  • added 1 commit

    • 9d1e8e08 - [toy] Adjust the starting coordinates for a good map view

    Compare with previous version

  • merged

  • Thank you for accepting the change as is :-) Well as you can see I'm struggling a bit with some part of the implementation, and I would be more than happy to rewrite the change as you see fit.

  • 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.

  • BTW my "zoomFactor" should be the reciprocal of your "range", if I've understood correctly how you set things up.

  • mentioned in issue #85

Please register or sign in to reply
Loading