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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Bross

Pages: [1]
1
Window / Re: Viewports
« on: August 02, 2014, 01:22:10 pm »
So... the top-left of the viewport is at (50,50)?
If so, you could apply the same calculations to find out 50 pixels. e.g. viewportOffsetX = 50 / windowWidth.
Then, you could just add it to both of the x ratios.
Same for y.

Thanks! This works.

        int viewportOffsetX = 50;
        int viewportOffsetY = 50;
        int viewportWidth = 200;
        int viewportHeight = 200;
       
        int windowWidth = window.getSize().x;
        int windowHeight = window.getSize().y;
       
        sf::View view(sf::FloatRect(static_cast<float>(viewportOffsetX), static_cast<float>(viewportOffsetY),
                                                                        static_cast<float>(viewportWidth), static_cast<float>(viewportHeight)));

        float viewportOffsetXRatio = static_cast<float>(viewportOffsetX) / windowWidth;
        float viewportOffsetYRatio = static_cast<float>(viewportOffsetY) / windowHeight;

        float viewportWidthRatio = static_cast<float>(viewportWidth) / windowWidth;
        float viewportHeightRatio = static_cast<float>(viewportHeight) / windowHeight;

        view.setViewport(sf::FloatRect(viewportOffsetXRatio, viewportOffsetYRatio,
                                                                viewportWidthRatio, viewportHeightRatio));

        window.setView(view);
 

Let me know if this works. Not certain of my calculations  :P

This is why i call it unintutive.  There will be method for set viewport without this calculation (IMHO setViewport internally doing exact reverse calculations, so there are round errors).

2
Window / Re: Viewports
« on: August 02, 2014, 01:39:43 am »
What does "on 50x50" mean?

Absolute position in main window, which is 1024x768, so is in upper left.

3
Window / Viewports
« on: August 01, 2014, 11:47:36 pm »
Is there method to set pixel perfect viewport position? For example I have 1024x768 window and I want set viewport on 50x50 with 200 width and 200 height. And in that viewport I do not want any zoom, any streching, just plain 1:1 display as in default view but clipped.

It is not intuitive that viewport use ratios and not absolute pixels as any other SFML functions. It is very confusing.

Pages: [1]