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

Author Topic: How would I set the resize the view based on number of objects on screen?  (Read 1654 times)

0 Members and 1 Guest are viewing this topic.

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
OK... So, I'm using sf::View to create a view of a graph. At present, I am able to zoom in and out and move the the view in all directions. Currently, the graph generates four nodes and the view is at the default,

Graph_Camera.reset(sf::FloatRect(0.0f, 0.0f, Window.getSize().x, Window.getSize().y));

Graph_Camera.setViewport(sf::FloatRect(0.0f, 0.0f, 1.0f, 1.0f));

How would I resize the view in such a way that when more nodes are added, the view zooms out to display all nodes that are initially out of bounds at default? Also, an important point to note is that the change in number of nodes is not dynamic. It is predetermined before the window is rendered.

I tried setSize() but it is not centering on the Window center. Here's what I did,

Graph_Camera.setSize(Node_List.size() * 200, Node_List.size() * 200);

Graph_Camera.setViewport(sf::FloatRect(0.0f, 0.0f, 1.0f, 1.0f));

Please help me on this. Thanks.
« Last Edit: April 11, 2015, 01:22:18 am by WDR »

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
For centering use the function view.setCenter(float x, float y):
Graph_Camera.setCenter(Graph_Camera.getSize().x/2, Graph_Camera.getSize().y/2)
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Compute the bounding box of all your nodes, and then use the reset function.
Laurent Gomila - SFML developer

 

anything