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

Author Topic: mapPixelToCoords returns  (Read 6142 times)

0 Members and 3 Guests are viewing this topic.

metulburr

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
mapPixelToCoords returns
« on: December 02, 2013, 06:08:34 pm »
I dont understand why does mapPixelToCoords take in a an integer and returns a float, whereas mapCoordstoPixel takes in a float and returns an interger?
Quote
Vector2f        mapPixelToCoords (const Vector2i &point) const
        Convert a point from target coordinates to world coordinates, using the current view.
 
Vector2f        mapPixelToCoords (const Vector2i &point, const View &view) const
        Convert a point from target coordinates to world coordinates.
 
Vector2i        mapCoordsToPixel (const Vector2f &point) const
        Convert a point from world coordinates to target coordinates, using the current view.
 
Vector2i        mapCoordsToPixel (const Vector2f &point, const View &view) const
        Convert a point from world coordinates to target coordinates.

The part i am having a problem with is:
sf::Vector2f mouse = window.mapPixelToCoords(sf::Vector2i(event.mouseMove.x, event.mouseMove.y));
pixel to coords takes in an int,and returns a float...However floats are not needed. So i would rather return an integer for mouse, but yet cannot because pixels to coords must return of type Vector2f. That or have pixel to coords take in mouse as a float, but that it not possible as well. So how can i get nice flow of only integers or only floats without switching between the two?
OS Ubuntu 13.04, Arch Linux, Gentoo, Windows 7/8
SFML 2.1
Ati Radeon HD 6770

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: mapPixelToCoords returns
« Reply #1 on: December 02, 2013, 06:17:01 pm »
Pixels can't exist in fractions, thus an interger is used (you can't have 0.3 pixel). The coordinate system for objects (shape at position x,y) does not have a fixed grid (you can place a shape at 0.3, 0.7).

The "pixel system" is directly mapped to what you see on your screen, 1px = 1px.
The "coords system" is virtual can depends on your sf::View, which you can zoom, move and rotate.

The two functions exist to convert between the two "systems". ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: mapPixelToCoords returns
« Reply #2 on: December 02, 2013, 08:38:57 pm »
To extend a little bit on the subject: if you have to manually convert between coordinate types (i.e. you want to pass a Vector2i to a function which takes a Vector2f) then it's a very good indication that something's wrong in your logic.
Laurent Gomila - SFML developer