SFML community forums

Help => Window => Topic started by: JCSopko on March 14, 2011, 06:45:10 pm

Title: [SFML2] Retrieving screen aspect ratio and applying to view
Post by: JCSopko 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!
Title: [SFML2] Retrieving screen aspect ratio and applying to view
Post by: JCSopko on March 19, 2011, 09:41:50 am
Noone?
Title: [SFML2] Retrieving screen aspect ratio and applying to view
Post by: Groogy 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
Title: [SFML2] Retrieving screen aspect ratio and applying to view
Post by: JCSopko 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. =[