Example #1
0
void Viewport::goToMinimapPos(int x, int y)
{

    cornerLU.x = cornerMaxLU.x + zoom[0] * (float)x/256 - 0.5 * zoom[currentZoom];
    cornerLU.y = y2lat_d(lat2y_d(cornerMaxLU.y) - zoom[0] * (float)y/256 + 0.5 * zoom[currentZoom]);

    // prawy zakres
    if (cornerLU.x + zoom[currentZoom] > cornerMaxRB.x)
        cornerLU.x = cornerMaxRB.x - zoom[currentZoom];

    // lewy zakres
    if (cornerLU.x < cornerMaxLU.x)
        cornerLU.x = cornerMaxLU.x;

    // gorny zakres
    if (cornerLU.y > cornerMaxLU.y)
        cornerLU.y = cornerMaxLU.y;

    // dolny zakres
    if (y2lat_d(lat2y_d(cornerLU.y) - zoom[currentZoom]) < cornerMaxRB.y)
        cornerLU.y = y2lat_d(lat2y_d(cornerMaxRB.y) + zoom[currentZoom]);

    moveTo(cornerLU);
    emit refresh();
}
Example #2
0
void Viewport::moveTo(GeoLayer::point point)
{
    cornerLU.x = point.x;
    cornerLU.y = point.y;
    cornerRB.x = point.x + zoom[currentZoom];
    cornerRB.y = y2lat_d(lat2y_d(point.y) - zoom[currentZoom]);
    incX = (cornerRB.x - cornerLU.x) / sizeX;
    incY = (cornerLU.y - cornerRB.y) / sizeY;
}
Example #3
0
Viewport::Viewport(int sizeX_init, int sizeY_init, QObject *parent) : QObject(parent)
{
    sizeX = sizeX_init;
    sizeY = sizeY_init;
    center.x = 19.45;
    center.y = 51.9574;
    cornerMaxLU.x = 19.45 - 5.625;
    cornerMaxRB.x = 19.45 + 5.625;
    cornerMaxLU.y = y2lat_d(lat2y_d(48.5) + 11.25);
    cornerMaxRB.y = 48.5;
    cornerLU = cornerMaxLU;
    cornerRB = cornerMaxRB;
    incX = (cornerMaxRB.x - cornerMaxLU.x) / sizeX;
    incY = (cornerMaxLU.y - cornerMaxRB.y) / sizeY;
    currentZoom = 0;
    zoom=new double[5];
    zoom[0]=11.25;
    zoom[1] = 5.625;
    zoom[2] = 2.813;
    zoom[3] = 1.406;
    zoom[4] = 0.703;
    image = new QImage (sizeX, sizeY, QImage::Format_RGB32);
    image->fill(Qt::black);
}
Example #4
0
int sdl_main( router_t *prouter, tdata_t *ptdata, router_request_t *preq )
{
    router = prouter;
    tdata = ptdata;
    req = preq;

    /* Flags to pass to SDL_SetVideoMode */
    int videoFlags;
    /* main loop variable */
    int done = FALSE;
    /* used to collect events */
    SDL_Event event;
    /* this holds some info about our display */
    const SDL_VideoInfo *videoInfo;
    /* whether or not the window is active */
    int isActive = TRUE;

    /* initialize SDL */
    if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    {
        fprintf( stderr, "Video initialization failed: %s\n",
             SDL_GetError( ) );
        Quit( 1 );
    }

    /* Fetch the video info */
    videoInfo = SDL_GetVideoInfo( );

    if ( !videoInfo )
    {
        fprintf( stderr, "Video query failed: %s\n",
             SDL_GetError( ) );
        Quit( 1 );
    }

    /* the flags to pass to SDL_SetVideoMode */
    videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
    videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
    videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

    /* This checks to see if surfaces can be stored in memory */
    if ( videoInfo->hw_available )
    videoFlags |= SDL_HWSURFACE;
    else
    videoFlags |= SDL_SWSURFACE;

    /* This checks if hardware blits can be done */
    if ( videoInfo->blit_hw )
    videoFlags |= SDL_HWACCEL;

    /* Sets up OpenGL double buffering */
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    /* get a SDL surface */
    surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
                videoFlags );

    /* Verify there is a surface */
    if ( !surface )
    {
        fprintf( stderr,  "Video mode set failed: %s\n", SDL_GetError( ) );
        Quit( 1 );
    }

    /* initialize OpenGL */
    initGL( );

    /* resize the initial window */
    resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );

    /* wait for events */
    while ( !done )
    {
        /* handle the events in the queue */

        while ( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
            case SDL_ACTIVEEVENT:
                /* Something's happend with our focus
                 * If we lost focus or we are iconified, we
                 * shouldn't draw the screen
                 */
                if ( event.active.gain == 0 )
                isActive = FALSE;
                else
                isActive = TRUE;
                break;
            case SDL_VIDEORESIZE:
                /* handle resize event */
                surface = SDL_SetVideoMode( event.resize.w,
                            event.resize.h,
                            16, videoFlags );
                if ( !surface )
                {
                    fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
                    Quit( 1 );
                }
                resizeWindow( event.resize.w, event.resize.h );
                break;
            case SDL_KEYDOWN:
                /* handle key presses */
                handleKeyPress( &event.key.keysym );
                isActive = TRUE;
                break;
            case SDL_MOUSEBUTTONDOWN:
                {
                    int x = event.motion.x;
                    int y = event.motion.y;
                    GLdouble ox=0.0,oy=0.0,oz=0.0;
                    GLint viewport[4];
                    GLdouble modelview[16],projection[16];
                    GLfloat wx=x,wy,wz;
                    glGetIntegerv(GL_VIEWPORT,viewport);
                    y=viewport[3]-y;
                    wy=y;
                    glGetDoublev(GL_MODELVIEW_MATRIX,modelview);
                    glGetDoublev(GL_PROJECTION_MATRIX,projection);
                    glReadPixels(x, y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&wz);
                    gluUnProject(wx,wy,wz,modelview,projection,viewport,&ox,&oy,&oz);


                    if (event.button.button == SDL_BUTTON_LEFT) {
                        GLfloat dist = 99999.0f;
                        uint32_t nearest = 0;

                        for (uint32_t i = 0; i < tdata->n_stops; i++) {
                            GLfloat cnt1 = lon2x_d(tdata->stop_coords[i].lon);
                            GLfloat cnt2 = lat2y_d(tdata->stop_coords[i].lat);

                            GLfloat cur_dist = ((ox - cnt1) * (ox - cnt1)) + ((oy - cnt2) * (oy - cnt2));

                            if (cur_dist < dist) {
                                dist = cur_dist;
                                nearest = i;
                            }
                        }

                        req->from = nearest;
                    } else if (event.button.button == 4) {

                        printf("%f %f %f %f\n", oy, y_offset, y2lat_d(oy), deltay);
                        x_offset = x2lon_d(ox);
                        y_offset = y2lat_d(oy);

                        zoom_level++;
                        zoom = pow(2, zoom_level);
                        perspective();
                    } else if (event.button.button == 5) {
                        if (zoom > 1) {
                            x_offset = x2lon_d(ox);
                            y_offset = y2lat_d(oy);

                            zoom_level--;
                            zoom = pow(2, zoom_level);
                            perspective();
                        }
                    }
                    break;
            }
            case SDL_QUIT:
                /* handle quit requests */
                done = TRUE;
                break;
            default:
                break;
            }
        }

        /* draw the scene */
        if ( isActive ) {
            router_request_next (req);

            router_route (router, req);
            //uint32_t n_reversals = req->arrive_by ? 1 : 2;
            //if (req->start_trip_trip != NONE) n_reversals = 0;
            //for (uint32_t i = 0; i < n_reversals; ++i) {
            //    router_request_reverse (router, req);
            //    router_route (router, req);
            //}

            drawGLScene( );
        }
    }

    /* clean ourselves up and exit */
    Quit( 0 );

    /* Should never get here */
    return( 0 );
}
Example #5
0
double addLat(double current, double inc) { return y2lat_d(lat2y_d(current) + inc); }