SFML community forums

Help => Graphics => Topic started by: BMB on December 11, 2011, 11:28:06 pm

Title: Understanding the View class
Post by: BMB on December 11, 2011, 11:28:06 pm
Can someone explain in simple English how this works? I am having a lot of trouble understanding it.
Title: Understanding the View class
Post by: mateandmetal on December 11, 2011, 11:49:59 pm
sf::View Camera;
sf::FloatRect CameraFR;
sf::Vector2f CameraPos;

// Camera settings
CameraFR.Left = 0;
CameraFR.Top = 0;
CameraFR.Width = (float) (your window width)
CameraFR.Height = (float) (your window Height);

// Set the viewport
Camera.Reset(CamaraFR);
Camera.SetViewport(sf::FloatRect(0, 0, 1, 1));

// Set the camera center
Camera.SetCenter (CameraPos);

// Set the camera
yourWindow.SetView(Camera);

then draw your scene
move the camera with CameraPos :)
Title: Understanding the View class
Post by: Laurent on December 12, 2011, 07:39:05 am
There's an online doc and a tutorial (in simple english ;)). Have you read them?
Title: Understanding the View class
Post by: BMB on December 12, 2011, 10:00:51 am
Quote from: "Laurent"
There's an online doc and a tutorial (in simple English ;)). Have you read them?

Yes, I did. After reading them, I still didn't understand it. I think I am having trouble with the concepts, for instance: Do I draw to the window coordinates or the view's? Are the window coordinates changed? Or do I keep drawing as usual and the window will just display it according to the view? And when I rotate/zoom/whatever am I changing the view's source or target? Or is it the same thing?

For instance, can someone please explain how the following scenario would translate into window/views code?
A game map of 2000*2000 pixels. The window is 800*600, displaying only a part of the map (say the middle). In the top right corner of it, there is a mini map of 100*100, displaying the entire map, rotated at 45 degrees (so the center of it will actually be at 100 from the top and right, not at 50)

Here is how it seems to me it might go, though I am still unclear on the exact code:
[list=1]

These are some of the things I am unclear about that I can think of off the top of my head. If anyone could clarify them for me, I would appreciate it.

P.S. I know this is probably a terrible way to handle this scenario, as it involves "drawing" the whole map at full resolution to some memory surface every time. It would be much more efficient to draw only the visible area, and draw a reduced resolution one in the minimap, but it seems to me to cover most of the points I don't understand, so for the purpose of this question, please explain how to do it with views, not a better way.
Title: Understanding the View class
Post by: BMB on December 12, 2011, 03:50:12 pm
After much trial and error, here are my conclusions about the View class:
Title: Understanding the View class
Post by: Laurent on December 12, 2011, 04:18:16 pm
Your conclusions are good, I think you understood everything about views.

(I didn't have the time to give you a detailed answer today, sorry that you had to try by yourself)