SFML community forums
General => General discussions => Topic started by: leanid.chaika on June 16, 2012, 10:09:22 am
-
I just intresting in OOP decision why window.convertCoords(curPosMouse) not view.convertCoords(curPosMouse) ?
-
convertCoords convert coordinates from the render target perspectiv to the view perspectiv, i.e. the function needs two parameters. Furthermore the function is declared within sf::RenderTarget (http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderTarget.php) so it applies automatically to sf::RenderWindow and sf::RenderTexture.
Now if you'd put it on the view itself you would always have to specify which render target it should convert the coordinates from. If you put it on the render target itself you just need to specify the coordinates and optinal you can give another sf::View as the one that render target is working with.
Also I'm not sure what kinda of internal stuff the function needs from the render target. If uses some private variables then you can't really put it onto the view otherwise you would need to expose private stuff so it could be accessed from the view.
-
convertCoords needs a render target (= the source coordinate system) and a view (= the target coordinate system). So it could be in both classes. But since sf::View doesn't know about sf::RenderTarget, and sf::RenderTarget already has a dependency to sf::View, it's more natural to do it this way.
-
Why, since all the coordinates are made in sf::Vector2f, does convertCoords() accept sf::Vector2i?
-
Because pixel coordinates of the window are defined precisly, i.e. there are no half pixel coordinates. The sf::Mouse::getPosition() also returns a sf::Vector2i.