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

Author Topic: Entity Selection box using zoom  (Read 1600 times)

0 Members and 1 Guest are viewing this topic.

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Entity Selection box using zoom
« on: January 09, 2020, 08:27:26 pm »
Hi,
   Need a little help to draw a rectangle shape after zooming an entity(image).
   I am using view class to zoom an image. I have two view -
   1/ that draws the images, main view
   2/ to draw the rectangle, overlay view
Everything is working fine. But the problem comes when I zoom an image using main.zoom(200%), normal is 100%. The image size increases, My question is, how do I make the overlay rectangle zoom with main view, without changing its pixel size. I have attached an image. This is a selection rectangle that every application uses to show the user that an image is selected.

The right side(100%) and left side(200%) image is what I am getting. What I actually want to make is the third(bottom) image.

I am using SFML and wxWidgets.

Thanks in advance.
« Last Edit: January 09, 2020, 08:29:57 pm by Birdron »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Entity Selection box using zoom
« Reply #1 on: January 10, 2020, 07:58:55 am »
Quote
how do I make the overlay rectangle zoom with main view
Wouldn't it be simpler to draw it in the same view? Why is it in a different one, if it needs to follow the geometry of entities drawn in the main view?
Laurent Gomila - SFML developer

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Entity Selection box using zoom
« Reply #2 on: January 10, 2020, 11:01:27 am »
Yes, it works if I draw it in same view, but than the rectangle also get zoomed in.
I have attached an image.
Image 1 is 100%, but when I zoom it, its pixel size increases like image 2. I want to keep the pixel size of the rectangle same pixel like image 3, bottom.

Thanks for reply.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Entity Selection box using zoom
« Reply #3 on: January 10, 2020, 01:26:04 pm »
I see.

Then what you must do is to map the position and size (of the selection) from main view to overlay view. Probably with something like:
window.mapPixelToCoords(window.mapCoordsToPixel(position, mainView), overlayView);

Do this both for the top-left corner the bottom-right corner and you get the coordinates of your rectangle in proper overlay coordinates.
Laurent Gomila - SFML developer

Birdron

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: Entity Selection box using zoom
« Reply #4 on: January 11, 2020, 09:22:41 am »
I am doing like this
setView(mainView)
sprite.draw(*this);
selection.draw(*this);

setView(overlayView);
sf::Vector2f position = selection.getPosition();
sf::Vector2f scale = selection.getScale();
mapPixelToCoords( mapCoordsToPixel( position, mainView), overlayView);
mapPixelToCoords( mapCoordsToPixel( scale, mainView), overlayView);
 
It is not mapping the pixel. I am getting the same result like image 2.

Thanks for reply.
« Last Edit: January 11, 2020, 09:35:31 am by Birdron »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Entity Selection box using zoom
« Reply #5 on: January 12, 2020, 11:20:09 am »
You can't map a scale to different coordinate systems like this. You must map positions.

Quote from: Laurent
Do this both for the top-left corner and the bottom-right corner
Laurent Gomila - SFML developer

 

anything