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

Author Topic: [SOLVED] How to know if a point is visible or not for the player?  (Read 2446 times)

0 Members and 1 Guest are viewing this topic.

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Hello! :)

Please watch the following graphic:


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! :)
« Last Edit: February 14, 2013, 12:08:52 am by shackra »

GNU User
Python programmer
Blog

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: How to know if a point is visible or not for the player?
« Reply #1 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

shackra

  • Jr. Member
  • **
  • Posts: 54
    • View Profile
    • http://swt.encyclomundi.org
Re: How to know if a point is visible or not for the player?
« Reply #2 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!

GNU User
Python programmer
Blog

 

anything