SFML community forums

Help => Window => Topic started by: WDR on April 11, 2015, 12:48:34 am

Title: How would I set the resize the view based on number of objects on screen?
Post by: WDR on April 11, 2015, 12:48:34 am
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.
Title: Re: How would I set the resize the view based on number of objects on screen?
Post by: AlexxanderX on April 11, 2015, 08:07:49 am
For centering use the function view.setCenter(float x, float y):
Graph_Camera.setCenter(Graph_Camera.getSize().x/2, Graph_Camera.getSize().y/2)
Title: Re: How would I set the resize the view based on number of objects on screen?
Post by: Laurent on April 11, 2015, 09:09:32 am
Compute the bounding box of all your nodes, and then use the reset function.