Ejemplo n.º 1
0
QImage Viewport::draw(GeoLayer *&layer, int a = 255)
{
    double range = lat2y_d(cornerLU.y) - lat2y_d(cornerRB.y);
    for (int i = 0; i < sizeX; i++)
    {
        double lat = cornerLU.x + (i * incX);
        for (int j = 0; j < sizeY; j++)
        {
            double lon = ((lat2y_d(cornerLU.y - (j * incY)) - lat2y_d(cornerRB.y))/range) * (cornerLU.y - cornerRB.y) + cornerRB.y;
            double opacity = double(a) / 255.0;
            //double lon = cornerLU.y - (j * incY);
            QColor colorA = layer->getPixel(lat, lon);
            if (colorA.alpha() != 0)
            {
                QColor colorB = QColor(image->pixel(i, j));
                QColor colorFinal = QColor(
                            (colorA.red() * opacity) + (colorB.red() * (1-opacity)),
                            (colorA.green() * opacity) + (colorB.green() * (1-opacity)),
                            (colorA.blue() * opacity) + (colorB.blue() * (1-opacity)),
                            255
                            );
                image->setPixel(i, j, colorFinal.rgb());
            }
        }
    }
    return *image;
}
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
GeoLayer::point Viewport::getLatLon(QPoint point)
{
    double range = lat2y_d(cornerLU.y) - lat2y_d(cornerRB.y);
    GeoLayer::point latLonPoint;
    latLonPoint.x = cornerLU.x + (point.x() * incX);
    latLonPoint.y = ((lat2y_d(cornerLU.y - (point.y() * incY)) - lat2y_d(cornerRB.y))/range) * (cornerLU.y - cornerRB.y) + cornerRB.y;
    qDebug() << "Point:" << latLonPoint.x << latLonPoint.y;
    return latLonPoint;
}
Ejemplo n.º 4
0
static void show_gtfsrt (uint8_t *buf, size_t len) {
    TransitRealtime__FeedMessage *msg;
    msg = transit_realtime__feed_message__unpack (NULL, len, buf);
    if (msg == NULL) {
        fprintf (stderr, "error unpacking incoming gtfs-rt message\n");
        return;
    }
    printf("Received feed message with %lu entities.\n", msg->n_entity);
    for (int e = 0; e < msg->n_entity; ++e) {
        TransitRealtime__FeedEntity *entity = msg->entity[e];
        printf("  entity %d has id %s\n", e, entity->id);
	if (entity->has_is_deleted && entity->is_deleted) {
		delete_vehicle(entity->id);
	} else {
		if (entity->vehicle && entity->vehicle->vehicle && entity->vehicle->position) {
			int32_t delay = 0;
			if (entity->vehicle->ovapi_vehicle_position) {
				delay = entity->vehicle->ovapi_vehicle_position->delay;
			}

			printf("    vehicle id: %s at %.4f, %.4f delay %d\n",
				entity->vehicle->vehicle->id,
				entity->vehicle->position->latitude,
				entity->vehicle->position->longitude,
				delay);
			update_vehicle(lon2x_d((GLfloat) entity->vehicle->position->longitude),
				       lat2y_d((GLfloat) entity->vehicle->position->latitude),
				       delay,
				       entity->id);
		}
	}
    }
    transit_realtime__feed_message__free_unpacked (msg, NULL);
}
Ejemplo n.º 5
0
void perspective() {
    /* change to the projection matrix and set our viewing volume. */
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );

    /* Height / width ration */
    GLfloat ratio = ( GLfloat ) current_width / ( GLfloat ) current_height;
    /* Set our perspective */
    if (ratio < 1.3333) {
        // padding on y, full width
    deltax = 2.850 / zoom;
    deltay = (deltax / ratio) / 1.5;
    } else {
        // padding on x, full height
    deltay = 1.425 / zoom;
    deltax = deltay * ratio * 1.5;
    }
    glOrtho( lon2x_d(x_offset - deltax), lon2x_d(x_offset + deltax), lat2y_d(y_offset - deltay), lat2y_d(y_offset + deltay), -1.0, 1.0 );
    /* Make sure we're chaning the model view and not the projection */
    glMatrixMode( GL_MODELVIEW );

    /* Reset The View */
    glLoadIdentity( );


}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
/* Here goes our drawing code */
int drawGLScene( GLvoid )
{
        if(hSHP && hSHP->nShapeType == SHPT_POLYGON) {
                SHPObject *psShape;
                glColor3f(.4f,.4f,.4f);
                for(int i=0;i<hSHP->nRecords;i++)
                {
                        psShape = SHPReadObject(hSHP, i);
                        if (psShape->nParts > 1) {
                                for (int z=0; z<(psShape->nParts - 1);z++)
                                {
                                        glBegin(GL_LINE_STRIP);
                                        for(int j=psShape->panPartStart[z];j<psShape->panPartStart[z+1];j++)
                                        {
                                                glVertex2f(lon2x_d((GLfloat) psShape->padfX[j]), lat2y_d( (GLfloat) psShape->padfY[j] ));
                                        }
                                        glEnd();
                                }

                                        glEnd();
                        }
                        glBegin(GL_LINE_STRIP);
                        for(int j=psShape->panPartStart[psShape->nParts - 1];j<psShape->nVertices;j++)
                        {
                                glVertex2f(lon2x_d((GLfloat) psShape->padfX[j]), lat2y_d( (GLfloat) psShape->padfY[j] ) );
                        }
                        glEnd();

                        SHPDestroyObject(psShape);
                }
        }

        for (int i = 0; i < active; i++) {
                if (vehicles[i].id[0] != '\0') {
        		glBegin(GL_LINES);
			if (vehicles[i].delay < 0) {
				glColor3f(1.0f,0.0f,0.0f);
			} else if (vehicles[i].delay < 120) {
				glColor3f(0.0f,1.0f,0.0f);
			} else {
				glColor3f(1.0f,0.5f,0.0f);
			}

                        glVertex2f(vehicles[i].x1,vehicles[i].y1);
                        glVertex2f(vehicles[i].x2,vehicles[i].y2);
        		glEnd();
                }
        }

    /* Draw it to the screen */
    SDL_GL_SwapBuffers( );

    return( TRUE );
}
Ejemplo n.º 8
0
void Viewport::getBoundingBox(int *leftUpperX, int *leftUpperY, int *rightBottomX, int *rightBootomY)
{
    double range = lat2y_d(cornerMaxLU.y) - lat2y_d(cornerMaxRB.y);
    *leftUpperX = (int)((cornerLU.x - cornerMaxLU.x)/zoom[0] * 255);
    *rightBottomX = (int)((cornerLU.x - cornerMaxLU.x + zoom[currentZoom])/zoom[0] * 255);
    *leftUpperY = (int)((lat2y_d(cornerMaxLU.y) - lat2y_d(cornerLU.y))/range * 255);
    *rightBootomY = (int)((lat2y_d(cornerMaxLU.y) - lat2y_d(cornerLU.y) + zoom[currentZoom])/range * 255);
}
Ejemplo n.º 9
0
/* function to reset our viewport after a window resize */
int resizeWindow( int width, int height )
{
    /* Height / width ration */
    GLfloat ratio;

    /* Protect against a divide by zero */
    if ( height == 0 )
        height = 1;

    current_height = height;
    current_height = height;

    ratio = ( GLfloat )width / ( GLfloat )height;

    /* Setup our viewport. */
    glViewport( 0, 0, ( GLsizei )width, ( GLsizei )height );

    /* change to the projection matrix and set our viewing volume. */
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );

    /* Set our perspective */
    /* glOrtho( lon2x_d(3.175), lon2x_d(7.295), lat2y_d(50.700), lat2y_d(53.570), -1.0, 1.0 ); */
    GLfloat deltax, deltay;
    if (ratio < 1.3333) {
    	// padding on y, full width
	deltax = 2.850 / zoom;
	deltay = (deltax / ratio) / 1.5;
    } else {
        // padding on x, full height
	deltay = 1.425 / zoom;
	deltax = deltay * ratio * 1.5;
    }
    glOrtho( lon2x_d(x_offset + 5.235 - deltax), lon2x_d(x_offset + 5.235 + deltax), lat2y_d(y_offset + 52.135 - deltay), lat2y_d(y_offset + 52.135 + deltay), -1.0, 1.0 );

    /* Make sure we're chaning the model view and not the projection */
    glMatrixMode( GL_MODELVIEW );

    /* Reset The View */
    glLoadIdentity( );

    return( TRUE );
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
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 );
}
Ejemplo n.º 12
0
/* Here goes our drawing code */
int drawGLScene( GLvoid )
{
    /* These are to calculate our fps */
    static GLint T0     = 0;
    static GLint Frames = 0;

    /* Clear The Screen And The Depth Buffer */
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity( );

    /* Move into the screen 1 unit */
    // glTranslatef( 0.0f, 0.0f, -1.0f );


    router_state_t (*states)[router->tdata->n_stops] = (router_state_t(*)[]) (router->states);

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

            int8_t round = RRRR_MAX_ROUNDS;
            do {
                round--;
                /* fan-out transfer locations */
                /*
                if (states[round][i].time != UNREACHED && states[round][i].back_stop != NONE) {
                    glBegin(GL_LINES);
                    glVertex2f(cnt1,cnt2);
                    GLfloat x = lon2x_d(tdata->stop_coords[states[round][i].back_stop].lon);
                    GLfloat y = lat2y_d(tdata->stop_coords[states[round][i].back_stop].lat);
                    glVertex2f(x,y);
                    glEnd();
                    break;
                }
                */

                /* visualise the transfers taken by feet */
                if (states[round][i].walk_time != UNREACHED && states[round][i].walk_from != NONE && states[round][i].time > states[round][i].walk_time) {
                    glColor3f(0.4f, 0.4f, 0.4f);
                    glBegin(GL_LINES);
                    glVertex2f(cnt1,cnt2);
                    GLfloat x = lon2x_d(tdata->stop_coords[states[round][i].walk_from].lon);
                    GLfloat y = lat2y_d(tdata->stop_coords[states[round][i].walk_from].lat);
                    glVertex2f(x,y);
                    glEnd();
                    break;
                }

            } while (round > 0);
        }
    }


    glBegin(GL_POINTS);
    for (uint32_t i = 0; i < tdata->n_stops; i++) {
        if (router->best_time[i] != UNREACHED) {
            GLfloat cnt1 = lon2x_d(tdata->stop_coords[i].lon);
            GLfloat cnt2 = lat2y_d(tdata->stop_coords[i].lat);

            /* Pulsing Colors Based On Text Position */
            // glColor3f( 1.0f *( float )cos( cnt1 ),
            //    1.0f *( float )sin( cnt2 ),
            //    1.0f - 0.5f * ( float )cos( cnt1 + cnt2 ) );

            // http://krazydad.com/tutorials/makecolors.php
            GLfloat frequency = (M_PI * 2) / 6400;
            GLfloat center = 0.5f;
            GLfloat width = 0.5f;
            GLint phase = 0;

            GLint delta = router->best_time[i] - req->time;

            glColor3f( 1.0f * ( float )sin(frequency * delta + 2 + phase) * width + center,
                       1.0f * ( float )sin(frequency * delta + 0 + phase) * width + center,
                       1.0f * ( float )sin(frequency * delta + 4 + phase) * width + center );

            glVertex2f(cnt1, cnt2);
        }
    }

    glEnd();

    /* Print text to the screen */
    if (zoom_level >= 6) {
        glColor3f(0.4f, 0.4f, 0.4f);
        for (uint32_t i = 0; i < tdata->n_stops; i++) {
            if (router->best_time[i] != UNREACHED) {
                GLfloat cnt1 = lon2x_d(tdata->stop_coords[i].lon);
                GLfloat cnt2 = lat2y_d(tdata->stop_coords[i].lat);
                glPrint( cnt1, cnt2, "%.2d:%.2d", router->best_time[i] / 900, (router->best_time[i] - ((router->best_time[i] / 900) * 900) ) / 15 ); // still in r_time
            }
        }
    }

    glColor3f(1.0f, 1.0f, 1.0f);
    glBegin(GL_LINE_LOOP);
    for(int i =0; i <= 300; i++){
    double angle = 2 * M_PI * i / 300;
    double x = (0.12f * cos(angle)) + lon2x_d(tdata->stop_coords[req->from].lon);
    double y = (0.12f * sin(angle)) + lat2y_d(tdata->stop_coords[req->from].lat);
    glVertex2d(x,y);
    }
    glEnd();

    // glPrint(lon2x_d(3.0f), lat2y_d(52.135f), "%.2d:%.2d", req->time / 900, (req->time - ((req->time / 900) * 900) ) / 15 ); // still in r_time
    glPrint(lon2x_d(tdata->stop_coords[req->from].lon), lat2y_d(tdata->stop_coords[req->from].lat), "%.2d:%.2d", req->time / 900, (req->time - ((req->time / 900) * 900) ) / 15 ); // still in r_time

    /* Draw it to the screen */
    SDL_GL_SwapBuffers( );

    /* Gather our frames per second */
    Frames++;
    {
    GLint t = SDL_GetTicks();
    if (t - T0 >= 5000) {
        GLfloat seconds = (t - T0) / 1000.0;
        GLfloat fps = Frames / seconds;
        printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
        T0 = t;
        Frames = 0;
    }
    }

    return( TRUE );
}
Ejemplo n.º 13
0
double addLat(double current, double inc) { return y2lat_d(lat2y_d(current) + inc); }