SFML community forums

General => Feature requests => Topic started by: Aster on September 02, 2013, 09:38:38 am

Title: Getting bounds for sf::View
Post by: Aster on September 02, 2013, 09:38:38 am
Hiya,

In most of my games involving an sf::View, I write a little function that looks somewhat like:
sf::FloatRect getViewBounds(const sf::View &view)
{
        sf::FloatRect rt;
        rt.left = view.getCenter().x - view.getSize().x/2.f;
        rt.top  = view.getCenter().y - view.getSize().y/2.f;
        rt.width  = view.getSize().x;
        rt.height = view.getSize().y;
        return rt;
}
 

As you can guess, it returns an sf::FloatRect containing information on the bounds of a given sf::View. This function has many uses, such as checking if something is on-screen or not using sf::Rect's very useful .contains() and .intersects() functions.

My feature request is to ask if such a thing could be stuck into sf::View by default, as it has many uses and it's pretty essential for game development, in my opinion.

Thanks,
Aster
Title: Re: Getting bounds for sf::View
Post by: Laurent on September 02, 2013, 09:53:37 am
It is impossible: if the view is rotated you cannot construct such a rectangle (SFML has no way of representing rotated rectangles).
Title: Re: Getting bounds for sf::View
Post by: Aster on September 02, 2013, 09:57:34 am
Ah, I see.

Could you not apply the rotation then get the topmost value, leftmost value, etc?
I don't think it's necessary to have it at 100% precision, covering exactly the bounds of the view.

EDIT: I now feel stupid for not thinking about rotations, as I'm currently making a game closely bound to rotations.
Title: Re: Getting bounds for sf::View
Post by: Ixrec on September 02, 2013, 10:10:51 am
Not using FloatRect.  That class simply doesn't support rotation (nor should it).  What you describe is entirely possible, but it's outside SFML's scope so you'd have to write a function to do it yourself (which isn't too hard, so feel free to ask about that).
Title: Re: Getting bounds for sf::View
Post by: Laurent on September 02, 2013, 10:15:57 am
Well, returning the axis-aligned bounding rectangle of the rotated view would be possible (that's what getGlobalBounds() does for Sprite, Text and Shape). And since most people don't use rotated views anyway, the function would return the exact bounds of the view in most cases.

So I'm not saying no, but I need to think about it ;)
Title: Re: Getting bounds for sf::View
Post by: Aster on September 02, 2013, 10:18:55 am
Alright. It would be really cool and useful in any case.

Thanks for your time. :)
Title: Re: Getting bounds for sf::View
Post by: Lo-X on September 02, 2013, 10:28:50 am
Actually it could be usefull to me too, I stored the "view" (scene, part of world, whatever) bounds in a separated variable.

I've to admit I do not use rotated views so much, but sometimes I need to rotate the scene 90° or 180°.Still that's a powerfull feature.
Title: Re: Getting bounds for sf::View
Post by: RyanPaul87 on December 30, 2021, 04:30:43 am
Did this ever get added?