SFML community forums

Help => Graphics => Topic started by: shackra on February 11, 2013, 11:24:59 pm

Title: [SOLVED] How to know if a point is visible or not for the player?
Post by: shackra on February 11, 2013, 11:24:59 pm
Hello! :)

Please watch the following graphic:
(http://ompldr.org/vaGZwZg/example.png)

I'm trying to wrap my mind on the process of asserting if certain point is or not visible for the user according to any sf::View object(?). In other words, I can't thought on a way of differentiate point A from point B regarding on the issue of if one of them are visible or not for the player...

any thoughts or advices on this? :O
cheers! :)
Title: Re: How to know if a point is visible or not for the player?
Post by: Nexus on February 11, 2013, 11:34:43 pm
To find out whether a certain point is visible, you can check if the current view contains it.
sf::View view = window.getView();
sf::FloatRect viewRect(view.getCenter() - view.getSize() / 2.f, view.getSize());

sf::Vector2f point(...);
bool visible = viewRect.contains(point);

Things get more trickier when you consider rotated views.
Title: Re: How to know if a point is visible or not for the player?
Post by: shackra on February 12, 2013, 12:30:26 am
To find out whether a certain point is visible, you can check if the current view contains it.
sf::View view = window.getView();
sf::FloatRect viewRect(view.getCenter() - view.getSize() / 2.f, view.getSize());

sf::Vector2f point(...);
bool visible = viewRect.contains(point);

Really, that's all? D: I thought that it was more tough... anyway, I'll test that. Thank You! :)

Things get more trickier when you consider rotated views.

:O I'll take that on consideration!