SFML community forums

Help => General => Topic started by: metulburr on December 02, 2013, 06:08:34 pm

Title: mapPixelToCoords returns
Post by: metulburr 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?
Title: AW: mapPixelToCoords returns
Post by: eXpl0it3r 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". ;)
Title: Re: mapPixelToCoords returns
Post by: Laurent 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.