vladkomarr

Untitled

Nov 30th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. sf::View StateStack::updateView()
  2. {
  3.     //calculate the correct view size / ratio for window size
  4.     m_context.defaultView.setSize(1920.f, 1080.f);
  5.     m_context.defaultView.setCenter(960.f, 540.f);
  6.  
  7.     auto vModeWidth = static_cast<float>(m_context.appInstance.getVideoSettings().VideoMode.width);
  8.     auto vModeHeight = static_cast<float>(m_context.appInstance.getVideoSettings().VideoMode.height);
  9.  
  10.     auto winSize = sf::Vector2f(vModeWidth, vModeHeight);
  11.     float windowRatio = winSize.x / winSize.y;
  12.     float viewRatio = 16.f / 9.f;
  13.  
  14.     float sizeY = windowRatio / viewRatio;
  15.     float top = (1.f - sizeY) / 2.f;
  16.  
  17.     m_context.defaultView.setViewport({ { 0.f, top }, { 1.f, sizeY } });
  18.  
  19.     for (auto& state : m_stack)
  20.         state->setContext(m_context);
  21.  
  22.     return m_context.defaultView;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment