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

Author Topic: [SFML2] Retrieving screen aspect ratio and applying to view  (Read 3590 times)

0 Members and 1 Guest are viewing this topic.

JCSopko

  • Newbie
  • *
  • Posts: 19
    • View Profile
[SFML2] Retrieving screen aspect ratio and applying to view
« on: March 14, 2011, 06:45:10 pm »
I was unsure whether to put this here or in the Graphics forum but basically I'm trying to set my camera view to a size of an equal aspect ratio of the monitor.

Code: [Select]
VideoMode videoMode = sf::VideoMode::GetDesktopMode();
float aspectRatio = (float)videoMode.Width/(float)videoMode.Height;
float screenSize = 380;

scene->view = new sf::View(sf::FloatRect(0, 0, screenSize, screenSize/aspectRatio));


Hypothetically this should work with any given screenSize but I'm still getting pretty profound distortion with certain numbers (such as 800 on a 16:9 monitor).

Is there a better way to control the field of view while still keeping the proper aspect ratio (no stretching) no matter what monitor you're on?

Thanks!

JCSopko

  • Newbie
  • *
  • Posts: 19
    • View Profile
[SFML2] Retrieving screen aspect ratio and applying to view
« Reply #1 on: March 19, 2011, 09:41:50 am »
Noone?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
[SFML2] Retrieving screen aspect ratio and applying to view
« Reply #2 on: March 19, 2011, 08:29:50 pm »
Shouldn't you use multiplication in the last argument when constructing the view? The height should be smaller if the ratio is <0
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

JCSopko

  • Newbie
  • *
  • Posts: 19
    • View Profile
[SFML2] Retrieving screen aspect ratio and applying to view
« Reply #3 on: March 19, 2011, 09:39:11 pm »
Aspect ratio is width divided by height. Width is the larger number on just about all monitors. For example the aspect ratio derived from my monitor is 16 divided by 9 which comes out to be about 1.777778. So division is the proper operation.

What I need to do is find an equation to be able to identify when distortion will occur and then increase the view marginally to prevent distortion.

I was hoping someone already has done this or it was built into SFML somehow but I've still gotten no reply. =[

 

anything