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

Author Topic: Good old sf::View methods  (Read 6837 times)

0 Members and 1 Guest are viewing this topic.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Good old sf::View methods
« on: August 02, 2009, 07:31:59 pm »
Hey.

Before SFML2, sf::View got some methods like GetRect() and SetFromRect(). SetFromRect() is still available through the new Reset(), but GetRect() isn't. That's probably because of the underlying data storage, since you're saving the view's center and not the rectangle anymore.

Is it possible to have a GetRect() again or at least a GetPosition() and SetPosition()? For me, it would be easier for some map movements. I'm currently doing the calculations by myself (get the center and subtract half of the view's size), but would rather see it in SFML itself.

Greetings

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Good old sf::View methods
« Reply #1 on: August 02, 2009, 08:28:19 pm »
It's no longer possible to retrieve an axis-aligned rectangle because of the new rotation.
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Good old sf::View methods
« Reply #2 on: August 02, 2009, 09:20:17 pm »
That's reasonable. :(

Maybe it's not the right place in the feature requests board, but I've used sf::View to provide pixel-wise movements for a 2D tilemap, which was a superb future of the old sf::View's behaviour. When the map is moved by 1 pixel, I just move the sf::View respectively -- mainly to avoid setting the positions of all visible sf::Sprites.

Any suggestions on making this still possible?

Edit: I just remember I've used the sf::View "scrolling" for a side scroller game. This wouldn't be possible anymore, too. I'd love to have a replacement for that, if possible.

Edit²: After some thinking I guess it's still possible by saving an sf::FloatRect myself, adding offsets to it and stuffing it into sf::View::Render(). Am I right that this will reset the sf::View exactly to the rectangle I provide? (no chance to test it atm)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Good old sf::View methods
« Reply #3 on: August 02, 2009, 10:20:23 pm »
Oh, so you're just talking about moving the view? Of course this is still possible, use SetCenter / GetCenter ;)
Laurent Gomila - SFML developer

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Good old sf::View methods
« Reply #4 on: August 02, 2009, 11:56:55 pm »
That solves the problem. It has been just a bit weird to set a center instead of a rectangle/border position. But since rotation is taken into account (which is a killer feature, since it enables changing my 2d tilemap into an isometric map with ease!), this absolutely makes sense.

Thanks. :)

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Good old sf::View methods
« Reply #5 on: August 13, 2009, 03:25:04 pm »
By the way, I guess it's okay if there aren't too many redundant methods (GetRect <-> GetCenter, GetSize), since such a functionality can easily be implemented by an own, global function... ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Good old sf::View methods
« Reply #6 on: August 14, 2009, 01:49:27 am »
True, but the public interface must (not should) be consistent. Therefore if class A has a rect and provides a GetRect() method, so should class X if it has a rect and it's somewhat useful for the developer.

This is one of the smaller things that can really disturb me while programming. Class A uses SetPosition( sf::Vector2i &foo ) and class B uses SetPosition( int x, int y ). I could argue that you can easily create such functions yourself, but that doesn't help anybody.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Good old sf::View methods
« Reply #7 on: August 14, 2009, 08:24:06 pm »
Concerning GetRect(), I don't fully agree with you. The existence of a GetRect() method shouldn't depend too much on the internal implementation. For example, why should sf::String have a GetRect() method, while sf::Sprite has none? A bounding rectangle obviously makes sense at sprites, too. All this stuff could be made much easier if the implementation were more uniform.

If those classes represent their geometry by three vectors (namely position, origin and size) and support respective getter and setter functions, the interface will be more consistent. This would allow to program generically and write a single function template which can be applied to all objects meeting those requirements:
Code: [Select]
template <typename RectangularObject>
sf::FloatRect GetBoundingRect(const RectangularObject& Obj)
{
    sf::Vector2f LeftUpper = Obj.GetPosition() - Obj.GetOrigin();
    sf::Vector2f RightLower = LeftUpper + Obj.GetSize();

    return sf::FloatRect(LeftUpper.x, LeftUpper.y, RightLower.x, RightLower.y);
}
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Good old sf::View methods
« Reply #8 on: August 15, 2009, 06:37:27 pm »
I like that approach, nothing to complain, sorry. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Good old sf::View methods
« Reply #9 on: August 15, 2009, 06:47:21 pm »
The interface will be much more consistent in SFML 2.
Laurent Gomila - SFML developer

Dominator

  • Newbie
  • *
  • Posts: 37
    • View Profile
Good old sf::View methods
« Reply #10 on: October 19, 2009, 09:49:14 pm »
Accessing View.Rotation causes an EntryPointNotFoundException in .NET.
I didn't investigate any further yet - maybe the export is missing?
I just wanted you to know in case you didn't already.  :wink:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Good old sf::View methods
« Reply #11 on: October 19, 2009, 10:03:16 pm »
Quote
Accessing View.Rotation causes an EntryPointNotFoundException in .NET.
I didn't investigate any further yet - maybe the export is missing?
I just wanted you to know in case you didn't already

I didn't know.
SFML.Net is not tested a lot, so I need as much feedback as possible. Thank you :)
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Good old sf::View methods
« Reply #12 on: October 21, 2009, 09:42:31 am »
This should be fixed now.
Laurent Gomila - SFML developer