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.


Topics - JoshuaBehrens

Pages: [1]
1
Window / [Solved] Change viewport to keep aspect ratio of scene
« on: July 14, 2014, 02:16:22 pm »
Hey guys,

I am stuck with certain problem: I manage stuff inside of sth you can call a scene and I want to keep the aspect ratio of the scene when the window is resized. I want to do this by changing the viewport. I am used to the fact that the viewport is given in pixels as sf::View seems to use percentage values of the window size I scale my calculated viewport down with these lines:

// down scale to % units ; windoww/h are from the resize event
viewport.width  = viewport.width  / windoww;
viewport.height = viewport.height / windowh;
// center
viewport.left = ( 1.0 - viewport.width  ) * 0.5;
viewport.top  = ( 1.0 - viewport.height ) * 0.5;

But it seems that my calculations are always wrong :/ and I guess I am stuck in my head so I can't see the problem. I tried this way to get the right upscaled/cropped size:
 // in = ( scenew, sceneh ); clip = ( windoww, windowh )
sf::Vector2f scaleToFit( const sf::Vector2f& in, const sf::Vector2f& clip )
{
        sf::Vector2f ret( in );
        if ( ( clip.y * in.x ) / in.y >= clip.x )
        {
                ret.y = ( clip.x * in.y ) / in.x;
                ret.x = clip.x;
        }
        else if ( ( clip.x * in.y ) / in.x >= clip.y )
        {
                ret.x = ( clip.y * in.x ) / in.y;
                ret.y = clip.y;
        }
        else
                ret = clip;
        return ret;
}
 
All I get is strange resizing. The scene keeps in the center but if I extend the width of the window (there should be black panels on the left and right) the black panels get very big so the scene does not keep its ratio and I don't know why. I hope I can get some help here.

Just for your information: This is what all happens on the resize event but I don't expect an error there:
sf::View v( sf::FloatRect( 0, 0, scenew, sceneh ) );
sf::FloatRect viewport( sf::Vector2f( 0, 0 ), scaleToFit( sf::Vector2f( screenw, screenh ), sf::Vector2f( windoww, windowh ) ) );
viewport.width  = viewport.width  / basicSettings.windoww;
viewport.height = viewport.height / basicSettings.windowh;
viewport.left = ( 1.0 - viewport.width  ) * 0.5;
viewport.top  = ( 1.0 - viewport.height ) * 0.5;
v.setViewport( viewport );
window.setView( v );
 

2
General / Weird horizontal lines
« on: July 14, 2013, 01:36:05 pm »
I do not use the sfml-graphics-package for this, so I m posting this in the General-Subforum.

I draw some triangles. My friends see these lines, me not. I tried VSync and Framelimit. Both didnt helped it. How do I fix this, and what do I need to tell you to investigate this?

3
Network / TCP Server does not react instantly
« on: April 01, 2013, 08:08:01 pm »
Hey guys,

I'm trying to get small tcp server working. At first I put the project in as attachment. You have to build it for your own due to the upload limitations of the forum. Everything but the network part is cut out. There are some things I don't understand why they are how they are. The server reacts only when I send a broadcast message although it has it's own thread. Also connectings and disconnectings are not send right. Not all receive the messages (there is a pattern due to the order of connects but I can't figure out why it is as it is). I'm currenly doing a video to this. I'll post it in a few minutes.
I hope someone can give me some hints to fix this.

JoshuaBehrens

[attachment deleted by admin]

4
Hello guys,

I tried this:
#include <SFML/Network.hpp>

#include <map>
#include <list>
#include <string>
#include <cstdio>

bool retrieveLines( const std::string& url, const std::string& file, const std::map< std::string, std::string >& params, std::list< std::string >& out )
{
    sf::Http http( url );
    sf::Http::Request req( file );
    req.setMethod(sf::Http::Request::Get);
    req.setBody("");
    req.setHttpVersion(1, 0);
    for ( std::map< std::string, std::string >::const_iterator cit( params.begin( ) ) ; cit != params.end( ) ; ++cit )
        req.setField( cit->first, cit->second );

    sf::Http::Response res = http.sendRequest( req );

    if ( res.getStatus( ) == 200 )
    {
        printf( "body from %s:\n%s\n", url.c_str( ), res.getBody( ).c_str( ) );
        return true;
    }
    return false;
}

int main( int argc, char** args )
{
    std::map< std::string, std::string > pars;
    std::list< std::string > lines;
    retrieveLines( "joshua-behrens.de","/index.php", pars, lines );

    return 0;
}
But it always closed my console with a very high return number. It is also undebuggable. gdb stops neither on any breakpoint nor any other point where an error could occur. But gdb is fine in other projects. DLLs are with the console, I linked against network-d and system-d. Any hints?
Thanks in advance, JoshuaBehrens

Pages: [1]