Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mouse coordinates on zoomed/unzoomed view are driving me crazy  (Read 1463 times)

0 Members and 1 Guest are viewing this topic.

barnack

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
Mouse coordinates on zoomed/unzoomed view are driving me crazy
« on: December 13, 2018, 08:04:10 pm »
I've a main view used to show a workspace (like paint for example), which can be zoomed/unzoomed and rotated.

The zoom is defined by a global multiplier: scrolling the wheel changes that multiplier, then the view size becomes equal to the window size times that multiplier. That way i can keep the zoom value when the window is resized.

My problem is, while mouse coordinates are mapped perfectly with a 1x zoom, any different value of the zoom screws the mapping (of course, mapping coordinates is a property of the window, not of the view); but i'm having quite an hard time understanding what maths should i apply to the mouse coordinates in order to have them be aware of the zoom.
if ((delta > 0 && graphics_zoom > 0.8) || (delta < 0 && graphics_zoom < 20))
        {
        graphics_zoom += delta * -0.2;
        view_work_area.setSize(window.getSize().x * graphics_zoom, window.getSize().y * graphics_zoom);
        }
 
where delta is the scrolling wheel value

« Last Edit: December 13, 2018, 08:05:58 pm by barnack »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Mouse coordinates on zoomed/unzoomed view are driving me crazy
« Reply #1 on: December 14, 2018, 12:44:18 am »
SFML provides functions to map between pixels and world coordinates.

sf::RenderTarget::mapPixelToCoords() and sf::RenderTarget::mapCoordsToPixel()

 

anything