static void output_super(index_t node,double latitude,double longitude) { Node *nodep=LookupNode(OSMNodes,node,1); Segment *segment; if(!IsSuperNode(nodep)) return; printf("%.6f %.6f n\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); segment=FirstSegment(OSMSegments,nodep,1); do { if(IsSuperSegment(segment)) { index_t othernode=OtherNode(segment,node); double lat,lon; GetLatLong(OSMNodes,othernode,&lat,&lon); if(node>othernode || (lat<LatMin || lat>LatMax || lon<LonMin || lon>LonMax)) printf("%.6f %.6f s\n",radians_to_degrees(lat),radians_to_degrees(lon)); } segment=NextSegment(OSMSegments,segment,node); } while(segment); }
static void output_junctions(index_t node,double latitude,double longitude) { Node *nodep=LookupNode(OSMNodes,node,1); Segment *segment; Way *firstway; int count=0,difference=0; segment=FirstSegment(OSMSegments,nodep,1); firstway=LookupWay(OSMWays,segment->way,1); do { Way *way=LookupWay(OSMWays,segment->way,2); if(IsNormalSegment(segment)) count++; if(WaysCompare(firstway,way)) difference=1; segment=NextSegment(OSMSegments,segment,node); } while(segment); if(count!=2 || difference) printf("%.6f %.6f %d\n",radians_to_degrees(latitude),radians_to_degrees(longitude),count); }
static void output_oneway(index_t node,double latitude,double longitude) { Node *nodep=LookupNode(OSMNodes,node,1); Segment *segment; segment=FirstSegment(OSMSegments,nodep,1); do { if(IsNormalSegment(segment)) { index_t othernode=OtherNode(segment,node); if(node>othernode) { double lat,lon; GetLatLong(OSMNodes,othernode,&lat,&lon); if(IsOnewayFrom(segment,node)) printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude),radians_to_degrees(lat),radians_to_degrees(lon)); else if(IsOnewayFrom(segment,othernode)) printf("%.6f %.6f %.6f %.6f\n",radians_to_degrees(lat),radians_to_degrees(lon),radians_to_degrees(latitude),radians_to_degrees(longitude)); } } segment=NextSegment(OSMSegments,segment,node); } while(segment); }
// advance camera to next point void Pointfile_Next (void) { if(!s_pointfile.shown()) return; if (s_check_point+2 == s_pointfile.end()) { globalOutputStream() << "End of pointfile\n"; return; } CPointfile::const_iterator i = ++s_check_point; CamWnd& camwnd = *g_pParentWnd->GetCamWnd(); Camera_setOrigin(camwnd, *i); g_pParentWnd->GetXYWnd()->SetOrigin(*i); { Vector3 dir(vector3_normalised(vector3_subtracted(*(++i), Camera_getOrigin(camwnd)))); Vector3 angles(Camera_getAngles(camwnd)); angles[CAMERA_YAW] = static_cast<float>(radians_to_degrees(atan2(dir[1], dir[0]))); angles[CAMERA_PITCH] = static_cast<float>(radians_to_degrees(asin(dir[2]))); Camera_setAngles(camwnd, angles); } }
double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node) { double lat1,lat2; double lon1,lon2; double angle; index_t node1,node2; node1=node; node2=OtherNode(segmentp,node); if(IsFakeNode(node1)) GetFakeLatLong(node1,&lat1,&lon1); else GetLatLong(nodes,node1,NULL,&lat1,&lon1); if(IsFakeNode(node2)) GetFakeLatLong(node2,&lat2,&lon2); else GetLatLong(nodes,node2,NULL,&lat2,&lon2); angle=atan2((lat2-lat1),(lon2-lon1)*cos(lat1)); angle=radians_to_degrees(angle); angle=270-angle; if(angle< 0) angle+=360; if(angle>360) angle-=360; return(angle); }
void test002 ( ) /******************************************************************************/ /* Purpose: TEST002 tests ANGLE_DEG_2D and ANGLE_RAD_ND. Licensing: This code is distributed under the GNU LGPL license. Modified: 14 April 2013 Author: John Burkardt */ { int angle_num = 12; int i; double temp1; double temp2; double temp3; double thetad; double thetar; double v1[2] = { 1.0, 0.0 }; double v2[2]; double v3[2] = { 0.0, 0.0 }; printf ( "\n" ); printf ( "TEST002\n" ); printf ( " ANGLE_DEG_2D computes an angle,\n" ); printf ( " ANGLE_RAD_ND computes an angle.\n" ); printf ( "\n" ); printf ( " X Y Theta ATAN2(y, x), ANGLE_RAD_ND, ANGLE_DEG_2D\n" ); printf ( "\n" ); for ( i = 0; i <= angle_num; i++ ) { thetad = ( double ) ( i ) * 360.0 / ( double ) ( angle_num ); thetar = degrees_to_radians ( thetad ); v2[0] = cos ( thetar ); v2[1] = sin ( thetar ); temp1 = radians_to_degrees ( atan2 ( v2[1], v2[0] ) ); temp2 = angle_rad_nd ( 2, v1, v2 ); temp3 = angle_deg_2d ( v1, v3, v2 ); printf ( " %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", v2[0], v2[1], thetad, temp1, temp2, temp3 ); } return; }
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames // TODO make output into point void futile_coord_to_lnglat(futile_coord_s *coord, double *out_lng_deg, double *out_lat_deg) { double n = pow(2, coord->z); double lng_deg = coord->x / n * 360.0 - 180.0; double lat_rad = atan(sinh(M_PI * (1 - 2 * coord->y / n))); double lat_deg = radians_to_degrees(lat_rad); *out_lng_deg = lng_deg; *out_lat_deg = lat_deg; }
double arc_cosine(double x, enum angle_type out_type) { switch (out_type) { case RAD: return acos(x); break; case DEG: return radians_to_degrees(acos(x)); break; case GRAD: return radians_to_grade(acos(x)); } }
double hyperbolic_arc_tangent(double x, enum angle_type out_type) { switch (out_type) { case RAD: return atanh(x); break; case DEG: return radians_to_degrees(atanh(x)); break; case GRAD: return radians_to_grade(atanh(x)); } }
uint32_t calculateBearing(geo_location& geo_location_ref) { float startLat = degree_to_radians(gps_data_dec.latitude); float startLong = degree_to_radians(gps_data_dec.longitude); float endLat = degree_to_radians(geo_location_ref.latitude); float endLong = degree_to_radians(geo_location_ref.longitude); float dLong = endLong - startLong; float y = sin(dLong) * cos(endLat); float x = cos(startLat) * sin(endLat) - sin(startLat)* cos(endLat) * cos(dLong); float brng = atan2(y,x); int32_t true1 = radians_to_degrees(brng); // printf("\nAngle: %d, gps data: %f , %f\n", true1, geo_location_ref.latitude, geo_location_ref.longitude); if( true1 < 0) { true1 = 360 + true1; } return true1; }
Vector::Vector(double x1, double y1, double x2, double y2) { x_component_ = std::abs(x2 - x1); y_component_ = std::abs(y2 - y1); int quadrant = determine_quadrant(x1, y1, x2, y2); magnitude_ = sqrt(pow(x_component_, 2) + pow(y_component_, 2)); double theta = radians_to_degrees(acos(x_component_ / magnitude_)); direction_ = determine_direction(quadrant, theta); set_component_signs(direction_); Logger::write(Logger::string_stream << "creating vector:"); Logger::write(Logger::string_stream << "\t\tmagnitude: " << magnitude_); Logger::write(Logger::string_stream << "\t\tdirection: " << direction_); Logger::write(Logger::string_stream << "\t\tx_component: " << x_component_); Logger::write(Logger::string_stream << "\t\ty_component: " << y_component_); Logger::write(Logger::string_stream << "\t\tquadrant: " << quadrant); Logger::write(Logger::string_stream << "\t\t(" << x1 << "," << y1 << ") & (" << x2 << "," << y2 << ")"); }
/* Note: Accelerometer is more accurate at small angles. When close to 90 degrees, a change of 0.01 can cause 5 degrees difference. Compared to ~ -+1 degree at 12deg. This is direct result of the asin function. Triangulation of readings with gravity (vertical down) INPUT : Scaled OUTPUT: AccelAngularPosition */ void calc_stationary_angles( struct fXYZ* mRaw ) { /* We'll use .rx as Roll and .ry as pitch */ /* To find which quadrants - always use z sign +-. However to get the angle, instead of x & z. Which works as long as y=0; we should work with the vector sum of y+z: x & <y+z> use atan2( x, y+z ) ??? */ // GET ELEVATION (PITCH): yz projection AccelAngularPosition.rx = atan2( mRaw->x, mRaw->z ); // GET ROLL: xz projection AccelAngularPosition.ry = atan2( mRaw->y, mRaw->z ); /* Accel cannot compute the Yaw! This only thru the gyro & magnet Z axis is only good for a) Linear accel in Z (quad copter) b) if sensor is tipped so Z is near horizon. ( or even 45 degrees, it would supplement the Y or X axis ) */ radians_to_degrees( &AccelAngularPosition, &AccelAngularPosition ); }
double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node) { double lat1,latm,lat2; double lon1,lonm,lon2; double angle1,angle2,angle; index_t node1,node2; node1=OtherNode(segment1p,node); node2=OtherNode(segment2p,node); if(IsFakeNode(node1)) GetFakeLatLong(node1,&lat1,&lon1); else GetLatLong(nodes,node1,NULL,&lat1,&lon1); if(IsFakeNode(node)) GetFakeLatLong(node,&latm,&lonm); else GetLatLong(nodes,node,NULL,&latm,&lonm); if(IsFakeNode(node2)) GetFakeLatLong(node2,&lat2,&lon2); else GetLatLong(nodes,node2,NULL,&lat2,&lon2); angle1=atan2((lonm-lon1)*cos(latm),(latm-lat1)); angle2=atan2((lon2-lonm)*cos(latm),(lat2-latm)); angle=angle2-angle1; angle=radians_to_degrees(angle); if(angle<-180) angle+=360; if(angle> 180) angle-=360; return(angle); }
static void output_turnrestriction(index_t node,double latitude,double longitude) { Node *nodep=LookupNode(OSMNodes,node,1); index_t turnrelation=NO_RELATION; if(!IsTurnRestrictedNode(nodep)) return; turnrelation=FindFirstTurnRelation1(OSMRelations,node); do { TurnRelation *relation; Segment *from_segment,*to_segment; index_t from_node,to_node; double from_lat,from_lon,to_lat,to_lon; relation=LookupTurnRelation(OSMRelations,turnrelation,1); from_segment=LookupSegment(OSMSegments,relation->from,1); to_segment =LookupSegment(OSMSegments,relation->to ,2); from_node=OtherNode(from_segment,node); to_node=OtherNode(to_segment,node); GetLatLong(OSMNodes,from_node,&from_lat,&from_lon); GetLatLong(OSMNodes,to_node,&to_lat,&to_lon); printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",radians_to_degrees(from_lat),radians_to_degrees(from_lon), radians_to_degrees(latitude),radians_to_degrees(longitude), radians_to_degrees(to_lat),radians_to_degrees(to_lon)); turnrelation=FindNextTurnRelation1(OSMRelations,turnrelation); } while(turnrelation!=NO_RELATION); }
double Angle::degrees() const { return radians_to_degrees(_angle); }
static void output_limits(index_t node,double latitude,double longitude) { Node *nodep=LookupNode(OSMNodes,node,1); Segment *segment,segments[MAX_SEG_PER_NODE]; int limits[MAX_SEG_PER_NODE]; int count=0; int i,j,same=0; segment=FirstSegment(OSMSegments,nodep,1); do { if(IsNormalSegment(segment) && count<MAX_SEG_PER_NODE) { Way *way=LookupWay(OSMWays,segment->way,1); segments[count]=*segment; switch(limit_type) { case SPEED_LIMIT: limits[count]=way->speed; break; case WEIGHT_LIMIT: limits[count]=way->weight; break; case HEIGHT_LIMIT: limits[count]=way->height; break; case WIDTH_LIMIT: limits[count]=way->width; break; case LENGTH_LIMIT: limits[count]=way->length; break; } if(limits[count] || HIGHWAY(way->type)<Way_Track) count++; } segment=NextSegment(OSMSegments,segment,node); } while(segment); /* Nodes with only one limit are not interesting */ if(count==1) return; /* Nodes with all segments the same limit are not interesting */ same=0; for(j=0;j<count;j++) if(limits[0]==limits[j]) same++; if(same==count) return; /* Display the interesting limits */ printf("%.6f %.6f\n",radians_to_degrees(latitude),radians_to_degrees(longitude)); for(i=0;i<count;i++) { same=0; for(j=0;j<count;j++) if(limits[i]==limits[j]) same++; if(count==2 || same!=(count-1)) { double lat,lon; GetLatLong(OSMNodes,OtherNode(&segments[i],node),&lat,&lon); switch(limit_type) { case SPEED_LIMIT: printf("%.6f %.6f %d\n",radians_to_degrees(lat),radians_to_degrees(lon),speed_to_kph(limits[i])); break; case WEIGHT_LIMIT: printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),weight_to_tonnes(limits[i])); break; case HEIGHT_LIMIT: printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),height_to_metres(limits[i])); break; case WIDTH_LIMIT: printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),width_to_metres(limits[i])); break; case LENGTH_LIMIT: printf("%.6f %.6f %.1f\n",radians_to_degrees(lat),radians_to_degrees(lon),length_to_metres(limits[i])); break; } } } }
void PrintRoute(Results **results,int nresults,Nodes *nodes,Segments *segments,Ways *ways,Profile *profile) { FILE *htmlfile=NULL,*gpxtrackfile=NULL,*gpxroutefile=NULL,*textfile=NULL,*textallfile=NULL; char *prev_bearing=NULL,*prev_wayname=NULL; distance_t cum_distance=0; duration_t cum_duration=0; int point=1; int segment_count=0,route_count=0; int point_count=0; int roundabout=0; /* Open the files */ if(option_quickest==0) { /* Print the result for the shortest route */ if(option_html) htmlfile =fopen("shortest.html","w"); if(option_gpx_track) gpxtrackfile=fopen("shortest-track.gpx","w"); if(option_gpx_route) gpxroutefile=fopen("shortest-route.gpx","w"); if(option_text) textfile =fopen("shortest.txt","w"); if(option_text_all) textallfile =fopen("shortest-all.txt","w"); if(option_html && !htmlfile) fprintf(stderr,"Warning: Cannot open file 'shortest.html' for writing [%s].\n",strerror(errno)); if(option_gpx_track && !gpxtrackfile) fprintf(stderr,"Warning: Cannot open file 'shortest-track.gpx' for writing [%s].\n",strerror(errno)); if(option_gpx_route && !gpxroutefile) fprintf(stderr,"Warning: Cannot open file 'shortest-route.gpx' for writing [%s].\n",strerror(errno)); if(option_text && !textfile) fprintf(stderr,"Warning: Cannot open file 'shortest.txt' for writing [%s].\n",strerror(errno)); if(option_text_all && !textallfile) fprintf(stderr,"Warning: Cannot open file 'shortest-all.txt' for writing [%s].\n",strerror(errno)); } else { /* Print the result for the quickest route */ if(option_html) htmlfile =fopen("quickest.html","w"); if(option_gpx_track) gpxtrackfile=fopen("quickest-track.gpx","w"); if(option_gpx_route) gpxroutefile=fopen("quickest-route.gpx","w"); if(option_text) textfile =fopen("quickest.txt","w"); if(option_text_all) textallfile =fopen("quickest-all.txt","w"); if(option_html && !htmlfile) fprintf(stderr,"Warning: Cannot open file 'quickest.html' for writing [%s].\n",strerror(errno)); if(option_gpx_track && !gpxtrackfile) fprintf(stderr,"Warning: Cannot open file 'quickest-track.gpx' for writing [%s].\n",strerror(errno)); if(option_gpx_route && !gpxroutefile) fprintf(stderr,"Warning: Cannot open file 'quickest-route.gpx' for writing [%s].\n",strerror(errno)); if(option_text && !textfile) fprintf(stderr,"Warning: Cannot open file 'quickest.txt' for writing [%s].\n",strerror(errno)); if(option_text_all && !textallfile) fprintf(stderr,"Warning: Cannot open file 'quickest-all.txt' for writing [%s].\n",strerror(errno)); } /* Print the head of the files */ if(htmlfile) { fprintf(htmlfile,"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"); fprintf(htmlfile,"<HTML>\n"); if(translate_xml_copyright_creator[0] && translate_xml_copyright_creator[1]) fprintf(htmlfile,"<!-- %s : %s -->\n",translate_xml_copyright_creator[0],translate_xml_copyright_creator[1]); if(translate_xml_copyright_source[0] && translate_xml_copyright_source[1]) fprintf(htmlfile,"<!-- %s : %s -->\n",translate_xml_copyright_source[0],translate_xml_copyright_source[1]); if(translate_xml_copyright_license[0] && translate_xml_copyright_license[1]) fprintf(htmlfile,"<!-- %s : %s -->\n",translate_xml_copyright_license[0],translate_xml_copyright_license[1]); fprintf(htmlfile,"<HEAD>\n"); fprintf(htmlfile,"<TITLE>"); fprintf(htmlfile,translate_html_title,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(htmlfile,"</TITLE>\n"); fprintf(htmlfile,"<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"); fprintf(htmlfile,"<STYLE type=\"text/css\">\n"); fprintf(htmlfile,"<!--\n"); fprintf(htmlfile," table {table-layout: fixed; border: none; border-collapse: collapse;}\n"); fprintf(htmlfile," table.c {color: grey; font-size: x-small;} /* copyright */\n"); fprintf(htmlfile," tr {border: 0px;}\n"); fprintf(htmlfile," tr.c {display: none;} /* coords */\n"); fprintf(htmlfile," tr.n {} /* node */\n"); fprintf(htmlfile," tr.s {} /* segment */\n"); fprintf(htmlfile," tr.t {font-weight: bold;} /* total */\n"); fprintf(htmlfile," td.l {font-weight: bold;}\n"); fprintf(htmlfile," td.r {}\n"); fprintf(htmlfile," span.w {font-weight: bold;} /* waypoint */\n"); fprintf(htmlfile," span.h {text-decoration: underline;} /* highway */\n"); fprintf(htmlfile," span.d {} /* segment distance */\n"); fprintf(htmlfile," span.j {font-style: italic;} /* total journey distance */\n"); fprintf(htmlfile," span.t {font-variant: small-caps;} /* turn */\n"); fprintf(htmlfile," span.b {font-variant: small-caps;} /* bearing */\n"); fprintf(htmlfile,"-->\n"); fprintf(htmlfile,"</STYLE>\n"); fprintf(htmlfile,"</HEAD>\n"); fprintf(htmlfile,"<BODY>\n"); fprintf(htmlfile,"<H1>"); fprintf(htmlfile,translate_html_title,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(htmlfile,"</H1>\n"); fprintf(htmlfile,"<table>\n"); } if(gpxtrackfile) { fprintf(gpxtrackfile,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(gpxtrackfile,"<gpx version=\"1.1\" creator=\"Routino\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"); fprintf(gpxtrackfile,"<metadata>\n"); fprintf(gpxtrackfile,"<desc>%s : %s</desc>\n",translate_xml_copyright_creator[0],translate_xml_copyright_creator[1]); if(translate_xml_copyright_source[1]) { fprintf(gpxtrackfile,"<copyright author=\"%s\">\n",translate_xml_copyright_source[1]); if(translate_xml_copyright_license[1]) fprintf(gpxtrackfile,"<license>%s</license>\n",translate_xml_copyright_license[1]); fprintf(gpxtrackfile,"</copyright>\n"); } fprintf(gpxtrackfile,"</metadata>\n"); fprintf(gpxtrackfile,"<trk>\n"); fprintf(gpxtrackfile,"<name>"); fprintf(gpxtrackfile,translate_gpx_name,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(gpxtrackfile,"</name>\n"); fprintf(gpxtrackfile,"<desc>"); fprintf(gpxtrackfile,translate_gpx_desc,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(gpxtrackfile,"</desc>\n"); } if(gpxroutefile) { fprintf(gpxroutefile,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); fprintf(gpxroutefile,"<gpx version=\"1.1\" creator=\"Routino\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.topografix.com/GPX/1/1\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n"); fprintf(gpxroutefile,"<metadata>\n"); fprintf(gpxroutefile,"<desc>%s : %s</desc>\n",translate_xml_copyright_creator[0],translate_xml_copyright_creator[1]); if(translate_xml_copyright_source[1]) { fprintf(gpxroutefile,"<copyright author=\"%s\">\n",translate_xml_copyright_source[1]); if(translate_xml_copyright_license[1]) fprintf(gpxroutefile,"<license>%s</license>\n",translate_xml_copyright_license[1]); fprintf(gpxroutefile,"</copyright>\n"); } fprintf(gpxroutefile,"</metadata>\n"); fprintf(gpxroutefile,"<rte>\n"); fprintf(gpxroutefile,"<name>"); fprintf(gpxroutefile,translate_gpx_name,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(gpxroutefile,"</name>\n"); fprintf(gpxroutefile,"<desc>"); fprintf(gpxroutefile,translate_gpx_desc,option_quickest?translate_xml_route_quickest:translate_xml_route_shortest); fprintf(gpxroutefile,"</desc>\n"); } if(textfile) { if(translate_raw_copyright_creator[0] && translate_raw_copyright_creator[1]) fprintf(textfile,"# %s : %s\n",translate_raw_copyright_creator[0],translate_raw_copyright_creator[1]); if(translate_raw_copyright_source[0] && translate_raw_copyright_source[1]) fprintf(textfile,"# %s : %s\n",translate_raw_copyright_source[0],translate_raw_copyright_source[1]); if(translate_raw_copyright_license[0] && translate_raw_copyright_license[1]) fprintf(textfile,"# %s : %s\n",translate_raw_copyright_license[0],translate_raw_copyright_license[1]); if((translate_raw_copyright_creator[0] && translate_raw_copyright_creator[1]) || (translate_raw_copyright_source[0] && translate_raw_copyright_source[1]) || (translate_raw_copyright_license[0] && translate_raw_copyright_license[1])) fprintf(textfile,"#\n"); fprintf(textfile,"#Latitude\tLongitude\tSection \tSection \tTotal \tTotal \tPoint\tTurn\tBearing\tHighway\n"); fprintf(textfile,"# \t \tDistance\tDuration\tDistance\tDuration\tType \t \t \t \n"); /* "%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t %+d\t %+d\t%s\n" */ } if(textallfile) { if(translate_raw_copyright_creator[0] && translate_raw_copyright_creator[1]) fprintf(textallfile,"# %s : %s\n",translate_raw_copyright_creator[0],translate_raw_copyright_creator[1]); if(translate_raw_copyright_source[0] && translate_raw_copyright_source[1]) fprintf(textallfile,"# %s : %s\n",translate_raw_copyright_source[0],translate_raw_copyright_source[1]); if(translate_raw_copyright_license[0] && translate_raw_copyright_license[1]) fprintf(textallfile,"# %s : %s\n",translate_raw_copyright_license[0],translate_raw_copyright_license[1]); if((translate_raw_copyright_creator[0] && translate_raw_copyright_creator[1]) || (translate_raw_copyright_source[0] && translate_raw_copyright_source[1]) || (translate_raw_copyright_license[0] && translate_raw_copyright_license[1])) fprintf(textallfile,"#\n"); fprintf(textallfile,"#Latitude\tLongitude\t Node\tType\tSegment\tSegment\tTotal\tTotal \tSpeed\tBearing\tHighway\n"); fprintf(textallfile,"# \t \t \t \tDist \tDurat'n\tDist \tDurat'n\t \t \t \n"); /* "%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t%3d\t%4d\t%s\n" */ } /* Loop through all the sections of the route and print them */ while(!results[point]) point++; while(point<=nresults) { int next_point=point; distance_t junc_distance=0; duration_t junc_duration=0; Result *result; result=FindResult(results[point],results[point]->start_node,results[point]->prev_segment); /* Print the start of the segment */ if(gpxtrackfile) fprintf(gpxtrackfile,"<trkseg>\n"); /* Loop through all the points within a section of the route and print them */ do { double latitude,longitude; Node *resultnode=NULL; index_t realsegment=NO_SEGMENT,next_realsegment=NO_SEGMENT; Segment *resultsegment=NULL,*next_resultsegment=NULL; Way *resultway=NULL,*next_resultway=NULL; Result *next_result; int important=IMP_UNIMPORTANT; distance_t seg_distance=0; duration_t seg_duration=0; speed_t seg_speed=0; char *waynameraw=NULL,*wayname=NULL,*next_waynameraw=NULL,*next_wayname=NULL; int bearing_int=0,turn_int=0,next_bearing_int=0; char *turn=NULL,*next_bearing=NULL; /* Calculate the information about this point */ if(IsFakeNode(result->node)) GetFakeLatLong(result->node,&latitude,&longitude); else GetLatLong(nodes,result->node,&latitude,&longitude); if(!IsFakeNode(result->node)) resultnode=LookupNode(nodes,result->node,6); /* Calculate the next result */ next_result=result->next; if(!next_result) for(next_point=point+1; next_point<=nresults; next_point++) if(results[next_point]) { next_result=FindResult(results[next_point],results[next_point]->start_node,results[next_point]->prev_segment); next_result=next_result->next; break; } /* Calculate the information about this segment */ if(result->node!=results[point]->start_node) /* not first point of a section of the route */ { if(IsFakeSegment(result->segment)) { resultsegment=LookupFakeSegment(result->segment); realsegment=IndexRealSegment(result->segment); } else { resultsegment=LookupSegment(segments,result->segment,2); realsegment=result->segment; } resultway=LookupWay(ways,resultsegment->way,1); seg_distance+=DISTANCE(resultsegment->distance); seg_duration+=Duration(resultsegment,resultway,profile); /* Calculate the cumulative distance/duration */ junc_distance+=seg_distance; junc_duration+=seg_duration; cum_distance+=seg_distance; cum_duration+=seg_duration; } /* Calculate the information about the next segment */ if(next_result) { if(IsFakeSegment(next_result->segment)) { next_resultsegment=LookupFakeSegment(next_result->segment); next_realsegment=IndexRealSegment(next_result->segment); } else { next_resultsegment=LookupSegment(segments,next_result->segment,1); next_realsegment=next_result->segment; } } /* Decide if this is a roundabout */ if(next_result) { next_resultway=LookupWay(ways,next_resultsegment->way,2); if(next_resultway->type&Way_Roundabout) { if(roundabout==0) { roundabout++; important=IMP_RB_ENTRY; } else { Segment *segment=FirstSegment(segments,resultnode,3); do { index_t othernode=OtherNode(segment,result->node); if(othernode!=result->prev->node && IndexSegment(segments,segment)!=realsegment) if(IsNormalSegment(segment) && (!profile->oneway || !IsOnewayTo(segment,result->node))) { Way *way=LookupWay(ways,segment->way,3); if(!(way->type&Way_Roundabout)) if(othernode!=next_result->node) { roundabout++; important=IMP_RB_NOT_EXIT; } } segment=NextSegment(segments,segment,result->node); } while(segment); } } else if(roundabout) { roundabout++; important=IMP_RB_EXIT; } } /* Decide if this is an important junction */ if(roundabout) /* roundabout */ ; else if(point_count==0) /* first point overall = Waypoint */ important=IMP_WAYPOINT; else if(result->node==results[point]->finish_node) /* Waypoint */ important=IMP_WAYPOINT; else if(result->node==results[point]->start_node) /* first point of a section of the route */ important=IMP_IGNORE; else if(realsegment==next_realsegment) /* U-turn */ important=IMP_UTURN; else if(resultnode && (resultnode->flags&NODE_MINIRNDBT)) important=IMP_MINI_RB; /* mini-roundabout */ else { Segment *segment=FirstSegment(segments,resultnode,3); do { index_t othernode=OtherNode(segment,result->node); if(othernode!=result->prev->node && IndexSegment(segments,segment)!=realsegment) if(IsNormalSegment(segment) && (!profile->oneway || !IsOnewayTo(segment,result->node))) { Way *way=LookupWay(ways,segment->way,3); if(othernode==next_result->node) /* the next segment that we follow */ { if(HIGHWAY(way->type)!=HIGHWAY(resultway->type)) if(important<IMP_CHANGE) important=IMP_CHANGE; } else if(IsFakeNode(next_result->node)) ; else /* a segment that we don't follow */ { if(junction_other_way[HIGHWAY(resultway->type)-1][HIGHWAY(way->type)-1]) if(important<IMP_JUNCT_IMPORT) important=IMP_JUNCT_IMPORT; if(important<IMP_JUNCT_CONT) important=IMP_JUNCT_CONT; } } segment=NextSegment(segments,segment,result->node); } while(segment); } /* Calculate the strings to be used */ if(resultway && textallfile) { waynameraw=WayName(ways,resultway); if(!*waynameraw) waynameraw=translate_raw_highway[HIGHWAY(resultway->type)]; bearing_int=(int)BearingAngle(nodes,resultsegment,result->node); seg_speed=profile->speed[HIGHWAY(resultway->type)]; } if(next_result && important>IMP_JUNCT_CONT) { if(resultsegment && (htmlfile || textfile)) { turn_int=(int)TurnAngle(nodes,resultsegment,next_resultsegment,result->node); turn=translate_xml_turn[((202+turn_int)/45)%8]; } if(gpxroutefile || htmlfile) { next_waynameraw=WayName(ways,next_resultway); if(!*next_waynameraw) next_waynameraw=translate_raw_highway[HIGHWAY(next_resultway->type)]; next_wayname=ParseXML_Encode_Safe_XML(next_waynameraw); } if(htmlfile || gpxroutefile || textfile) { next_bearing_int=(int)BearingAngle(nodes,next_resultsegment,next_result->node); next_bearing=translate_xml_heading[(4+(22+next_bearing_int)/45)%8]; } } /* Print out the important points (junctions / waypoints) */ if(important>IMP_JUNCT_CONT) { if(htmlfile) { char *type; if(important==IMP_WAYPOINT) type=translate_html_waypoint; else if(important==IMP_MINI_RB) type=translate_html_roundabout; else type=translate_html_junction; if(point_count>0) /* not the first point */ { /* <tr class='s'><td class='l'>Follow:<td class='r'><span class='h'>*highway name*</span> for <span class='d'>*distance* km, *time* min</span> [<span class='j'>*distance* km, *time* minutes</span>] */ fprintf(htmlfile,"<tr class='s'><td class='l'>%s:<td class='r'>",translate_html_segment[0]); fprintf(htmlfile,translate_html_segment[1], (roundabout>1?translate_html_roundabout:prev_wayname), distance_to_km(junc_distance),duration_to_minutes(junc_duration)); fprintf(htmlfile," [<span class='j'>"); fprintf(htmlfile,translate_html_total[1], distance_to_km(cum_distance),duration_to_minutes(cum_duration)); fprintf(htmlfile,"</span>]\n"); } /* <tr class='c'><td class='l'>*N*:<td class='r'>*latitude* *longitude* */ fprintf(htmlfile,"<tr class='c'><td class='l'>%d:<td class='r'>%.6f %.6f\n", point_count+1, radians_to_degrees(latitude),radians_to_degrees(longitude)); if(point_count==0) /* first point */ { /* <tr class='n'><td class='l'>Start:<td class='r'>At <span class='w'>Waypoint</span>, head <span class='b'>*heading*</span> */ fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_start[0]); fprintf(htmlfile,translate_html_start[1], translate_html_waypoint, next_bearing); fprintf(htmlfile,"\n"); } else if(next_result) /* middle point */ { if(roundabout>1) { /* <tr class='n'><td class='l'>At:<td class='r'>Roundabout, take <span class='t'>the *Nth* exit</span> heading <span class='b'>*heading*</span> */ fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_rbnode[0]); fprintf(htmlfile,translate_html_rbnode[1], translate_html_roundabout, translate_xml_ordinal[roundabout-2], next_bearing); fprintf(htmlfile,"\n"); } else { /* <tr class='n'><td class='l'>At:<td class='r'>Junction, go <span class='t'>*direction*</span> heading <span class='b'>*heading*</span> */ fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_node[0]); fprintf(htmlfile,translate_html_node[1], type, turn, next_bearing); fprintf(htmlfile,"\n"); } } else /* end point */ { /* <tr class='n'><td class='l'>Stop:<td class='r'>At <span class='w'>Waypoint</span> */ fprintf(htmlfile,"<tr class='n'><td class='l'>%s:<td class='r'>",translate_html_stop[0]); fprintf(htmlfile,translate_html_stop[1], translate_html_waypoint); fprintf(htmlfile,"\n"); /* <tr class='t'><td class='l'>Total:<td class='r'><span class='j'>*distance* km, *time* minutes</span> */ fprintf(htmlfile,"<tr class='t'><td class='l'>%s:<td class='r'><span class='j'>",translate_html_total[0]); fprintf(htmlfile,translate_html_total[1], distance_to_km(cum_distance),duration_to_minutes(cum_duration)); fprintf(htmlfile,"</span>\n"); } } if(gpxroutefile) { if(point_count>0) /* not first point */ { fprintf(gpxroutefile,"<desc>"); fprintf(gpxroutefile,translate_gpx_step, prev_bearing, prev_wayname, distance_to_km(junc_distance),duration_to_minutes(junc_duration)); fprintf(gpxroutefile,"</desc></rtept>\n"); } if(point_count==0) /* first point */ { fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n", radians_to_degrees(latitude),radians_to_degrees(longitude), translate_gpx_start); } else if(!next_result) /* end point */ { fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s</name>\n", radians_to_degrees(latitude),radians_to_degrees(longitude), translate_gpx_finish); fprintf(gpxroutefile,"<desc>"); fprintf(gpxroutefile,translate_gpx_final, distance_to_km(cum_distance),duration_to_minutes(cum_duration)); fprintf(gpxroutefile,"</desc></rtept>\n"); } else /* middle point */ { if(important==IMP_WAYPOINT) fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%d</name>\n", radians_to_degrees(latitude),radians_to_degrees(longitude), translate_gpx_inter,++segment_count); else fprintf(gpxroutefile,"<rtept lat=\"%.6f\" lon=\"%.6f\"><name>%s%03d</name>\n", radians_to_degrees(latitude),radians_to_degrees(longitude), translate_gpx_trip,++route_count); } } if(textfile) { char *type; if(important==IMP_WAYPOINT) type="Waypt"; else type="Junct"; if(point_count==0) /* first point */ { fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t\t %+d\t%s\n", radians_to_degrees(latitude),radians_to_degrees(longitude), 0.0,0.0,0.0,0.0, type, ((22+next_bearing_int)/45+4)%8-4, next_waynameraw); } else if(!next_result) /* end point */ { fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t\t\t\n", radians_to_degrees(latitude),radians_to_degrees(longitude), distance_to_km(junc_distance),duration_to_minutes(junc_duration), distance_to_km(cum_distance),duration_to_minutes(cum_duration), type); } else /* middle point */ { fprintf(textfile,"%10.6f\t%11.6f\t%6.3f km\t%4.1f min\t%5.1f km\t%4.0f min\t%s\t %+d\t %+d\t%s\n", radians_to_degrees(latitude),radians_to_degrees(longitude), distance_to_km(junc_distance),duration_to_minutes(junc_duration), distance_to_km(cum_distance),duration_to_minutes(cum_duration), type, (22+turn_int)/45, ((22+next_bearing_int)/45+4)%8-4, next_waynameraw); } } junc_distance=0; junc_duration=0; if(htmlfile || gpxroutefile) { if(prev_wayname) free(prev_wayname); if(next_wayname) prev_wayname=strcpy((char*)malloc(strlen(next_wayname)+1),next_wayname); else prev_wayname=NULL; if(next_wayname && next_wayname!=next_waynameraw) free(next_wayname); } if(gpxroutefile) prev_bearing=next_bearing; if(roundabout>1) roundabout=0; } /* Print out all of the results */ if(gpxtrackfile) fprintf(gpxtrackfile,"<trkpt lat=\"%.6f\" lon=\"%.6f\"/>\n", radians_to_degrees(latitude),radians_to_degrees(longitude)); if(important>IMP_IGNORE) { if(textallfile) { char *type; if(important==IMP_WAYPOINT) type="Waypt"; else if(important==IMP_UTURN) type="U-turn"; else if(important==IMP_MINI_RB) type="Mini-RB"; else if(important==IMP_CHANGE) type="Change"; else if(important==IMP_UNIMPORTANT) type="Inter"; else type="Junct"; if(point_count==0) /* first point */ { fprintf(textallfile,"%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t\t\t\n", radians_to_degrees(latitude),radians_to_degrees(longitude), IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node, (resultnode && IsSuperNode(resultnode))?'*':' ',type, 0.0,0.0,0.0,0.0); } else /* not the first point */ { fprintf(textallfile,"%10.6f\t%11.6f\t%8d%c\t%s\t%5.3f\t%5.2f\t%5.2f\t%5.1f\t%3d\t%4d\t%s\n", radians_to_degrees(latitude),radians_to_degrees(longitude), IsFakeNode(result->node)?(NODE_FAKE-result->node):result->node, (resultnode && IsSuperNode(resultnode))?'*':' ',type, distance_to_km(seg_distance),duration_to_minutes(seg_duration), distance_to_km(cum_distance),duration_to_minutes(cum_duration), speed_to_kph(seg_speed), bearing_int, waynameraw); } } } if(wayname && wayname!=waynameraw) free(wayname); result=next_result; if(important>IMP_JUNCT_CONT) point_count++; } while(point==next_point); /* Print the end of the segment */ if(gpxtrackfile) fprintf(gpxtrackfile,"</trkseg>\n"); point=next_point; } /* Print the tail of the files */ if(htmlfile) { fprintf(htmlfile,"</table>\n"); if((translate_xml_copyright_creator[0] && translate_xml_copyright_creator[1]) || (translate_xml_copyright_source[0] && translate_xml_copyright_source[1]) || (translate_xml_copyright_license[0] && translate_xml_copyright_license[1])) { fprintf(htmlfile,"<p>\n"); fprintf(htmlfile,"<table class='c'>\n"); if(translate_xml_copyright_creator[0] && translate_xml_copyright_creator[1]) fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_xml_copyright_creator[0],translate_xml_copyright_creator[1]); if(translate_xml_copyright_source[0] && translate_xml_copyright_source[1]) fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_xml_copyright_source[0],translate_xml_copyright_source[1]); if(translate_xml_copyright_license[0] && translate_xml_copyright_license[1]) fprintf(htmlfile,"<tr><td class='l'>%s:<td class='r'>%s\n",translate_xml_copyright_license[0],translate_xml_copyright_license[1]); fprintf(htmlfile,"</table>\n"); } fprintf(htmlfile,"</BODY>\n"); fprintf(htmlfile,"</HTML>\n"); } if(gpxtrackfile) { fprintf(gpxtrackfile,"</trk>\n"); fprintf(gpxtrackfile,"</gpx>\n"); } if(gpxroutefile) { fprintf(gpxroutefile,"</rte>\n"); fprintf(gpxroutefile,"</gpx>\n"); } /* Close the files */ if(htmlfile) fclose(htmlfile); if(gpxtrackfile) fclose(gpxtrackfile); if(gpxroutefile) fclose(gpxroutefile); if(textfile) fclose(textfile); if(textallfile) fclose(textallfile); }
void Player::render(double dt) { texture_colors[1]=1; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glTranslatef(pos.x, pos.y, 0); glRotatef(radians_to_degrees(angle+PI/2.0), 0, 0, 1.0); glTranslatef(-PLAYER_W*0.5,-PLAYER_H*0.5, 0); //Draw textures: textures[TEXTURE_BASE].render(dt); textures[TEXTURE_TAIL].render(dt); if(current_base_texture != TEXTURE_BASE) textures[current_base_texture].render(dt); if(fire) textures[TEXTURE_DISPENCER].render(dt); glPopMatrix(); glMatrixMode(GL_PROJECTION); if(!fire) { glPushMatrix(); glTranslatef(pos.x-shield->width()/2, pos.y-shield->height()/2,0); shield->bind(); if(full_shield) { glBegin(GL_QUADS); glTexCoord2f(0,1.0); glVertex2f(0,200.0); glTexCoord2f(0,0); glVertex2f(0,0); glTexCoord2f(1.0,0); glVertex2f(200.0,0); glTexCoord2f(1.0,1.0); glVertex2f(200.0,200.0); glEnd(); } else { float sx1, sy1, sx2, sy2; shield_coords(shield_angle-PI/4.0,sx1,sy1); shield_coords(shield_angle+PI/4.0,sx2,sy2); int corner = (int)floor(period(shield_angle)/(PI/2.0)); float cx, cy; switch(corner) { case 0: cx = 0; cy = 1; break; case 1: cx = 0; cy = 0; break; case 2: cx = 1; cy = 0; break; case 3: cx = 1; cy = 1; break; } glBegin(GL_TRIANGLES); glTexCoord2f(sx1,sy1); glVertex2f(200.0*sx1,200.0*sy1); glTexCoord2f(sx2,sy2); glVertex2f(200.0*sx2,200.0*sy2); glTexCoord2f(0.5, 0.5); glVertex2f(100.0, 100.0); glTexCoord2f(sx1,sy1); glVertex2f(200.0*sx1,200.0*sy1); glTexCoord2f(sx2,sy2); glVertex2f(200.0*sx2,200.0*sy2); glTexCoord2f(cx,cy); glVertex2f(200.0*cx,200.0*cy); glEnd(); } glPopMatrix(); } texture_colors[1]=0.5; }
int main(int argc,char** argv) { Nodes *OSMNodes; Segments *OSMSegments; Ways *OSMWays; Relations *OSMRelations; Results *results[NWAYPOINTS+1]={NULL}; int point_used[NWAYPOINTS+1]={0}; double point_lon[NWAYPOINTS+1],point_lat[NWAYPOINTS+1]; index_t point_node[NWAYPOINTS+1]={NO_NODE}; double heading=-999; int help_profile=0,help_profile_xml=0,help_profile_json=0,help_profile_pl=0; char *dirname=NULL,*prefix=NULL; char *profiles=NULL,*profilename=NULL; char *translations=NULL,*language=NULL; int exactnodes=0,reverse=0,loop=0; Transport transport=Transport_None; Profile *profile=NULL; Translation *translation=NULL; index_t start_node,finish_node=NO_NODE; index_t join_segment=NO_SEGMENT; int arg,nresults=0; waypoint_t start_waypoint,finish_waypoint=NO_WAYPOINT; waypoint_t first_waypoint=NWAYPOINTS,last_waypoint=1,waypoint; int inc_dec_waypoint=1; printf_program_start(); /* Parse the command line arguments */ if(argc<2) print_usage(0,NULL,NULL); /* Get the non-routing, general program options */ for(arg=1;arg<argc;arg++) { if(!strcmp(argv[arg],"--version")) print_usage(-1,NULL,NULL); else if(!strcmp(argv[arg],"--help")) print_usage(1,NULL,NULL); else if(!strcmp(argv[arg],"--help-profile")) help_profile=1; else if(!strcmp(argv[arg],"--help-profile-xml")) help_profile_xml=1; else if(!strcmp(argv[arg],"--help-profile-json")) help_profile_json=1; else if(!strcmp(argv[arg],"--help-profile-perl")) help_profile_pl=1; else if(!strncmp(argv[arg],"--dir=",6)) dirname=&argv[arg][6]; else if(!strncmp(argv[arg],"--prefix=",9)) prefix=&argv[arg][9]; else if(!strncmp(argv[arg],"--profiles=",11)) profiles=&argv[arg][11]; else if(!strncmp(argv[arg],"--translations=",15)) translations=&argv[arg][15]; else if(!strcmp(argv[arg],"--exact-nodes-only")) exactnodes=1; else if(!strncmp(argv[arg],"--reverse",9)) { if(argv[arg][9]=='=') reverse=atoi(&argv[arg][10]); else reverse=1; } else if(!strncmp(argv[arg],"--loop",6)) { if(argv[arg][6]=='=') loop=atoi(&argv[arg][7]); else loop=1; } else if(!strcmp(argv[arg],"--quiet")) option_quiet=1; else if(!strcmp(argv[arg],"--loggable")) option_loggable=1; else if(!strcmp(argv[arg],"--logtime")) option_logtime=2; else if(!strcmp(argv[arg],"--logmemory")) option_logmemory=1; else if(!strcmp(argv[arg],"--output-html")) option_file_html=1; else if(!strcmp(argv[arg],"--output-gpx-track")) option_file_gpx_track=1; else if(!strcmp(argv[arg],"--output-gpx-route")) option_file_gpx_route=1; else if(!strcmp(argv[arg],"--output-text")) option_file_text=1; else if(!strcmp(argv[arg],"--output-text-all")) option_file_text_all=1; else if(!strcmp(argv[arg],"--output-none")) option_file_none=1; else if(!strcmp(argv[arg],"--output-stdout")) { option_file_stdout=1; option_quiet=1; } else if(!strncmp(argv[arg],"--profile=",10)) profilename=&argv[arg][10]; else if(!strncmp(argv[arg],"--language=",11)) language=&argv[arg][11]; else if(!strcmp(argv[arg],"--shortest")) option_quickest=0; else if(!strcmp(argv[arg],"--quickest")) option_quickest=1; else if(!strncmp(argv[arg],"--lon",5) && isdigit(argv[arg][5])) { int point; char *p=&argv[arg][6]; while(isdigit(*p)) p++; if(*p++!='=') print_usage(0,argv[arg],NULL); point=atoi(&argv[arg][5]); if(point>NWAYPOINTS || point_used[point]&1) print_usage(0,argv[arg],NULL); point_lon[point]=degrees_to_radians(atof(p)); point_used[point]+=1; if(point<first_waypoint) first_waypoint=point; if(point>last_waypoint) last_waypoint=point; } else if(!strncmp(argv[arg],"--lat",5) && isdigit(argv[arg][5])) { int point; char *p=&argv[arg][6]; while(isdigit(*p)) p++; if(*p++!='=') print_usage(0,argv[arg],NULL); point=atoi(&argv[arg][5]); if(point>NWAYPOINTS || point_used[point]&2) print_usage(0,argv[arg],NULL); point_lat[point]=degrees_to_radians(atof(p)); point_used[point]+=2; if(point<first_waypoint) first_waypoint=point; if(point>last_waypoint) last_waypoint=point; } else if(!strncmp(argv[arg],"--heading=",10)) { double h=atof(&argv[arg][10]); if(h>=-360 && h<=360) { heading=h; if(heading<0) heading+=360; } } else if(!strncmp(argv[arg],"--transport=",12)) { transport=TransportType(&argv[arg][12]); if(transport==Transport_None) print_usage(0,argv[arg],NULL); } else continue; argv[arg]=NULL; } /* Check the specified command line options */ if(option_file_stdout && (option_file_html+option_file_gpx_track+option_file_gpx_route+option_file_text+option_file_text_all)!=1) { fprintf(stderr,"Error: The '--output-stdout' option requires exactly one other output option (but not '--output-none').\n"); exit(EXIT_FAILURE); } if(option_file_html==0 && option_file_gpx_track==0 && option_file_gpx_route==0 && option_file_text==0 && option_file_text_all==0 && option_file_none==0) option_file_html=option_file_gpx_track=option_file_gpx_route=option_file_text=option_file_text_all=1; /* Load in the selected profiles */ if(transport==Transport_None) transport=Transport_Motorcar; if(profiles) { if(!ExistsFile(profiles)) { fprintf(stderr,"Error: The '--profiles' option specifies a file '%s' that does not exist.\n",profiles); exit(EXIT_FAILURE); } } else { profiles=FileName(dirname,prefix,"profiles.xml"); if(!ExistsFile(profiles)) { char *defaultprofiles=FileName(ROUTINO_DATADIR,NULL,"profiles.xml"); if(!ExistsFile(defaultprofiles)) { fprintf(stderr,"Error: The '--profiles' option was not used and the files '%s' and '%s' do not exist.\n",profiles,defaultprofiles); exit(EXIT_FAILURE); } free(profiles); profiles=defaultprofiles; } } if(!profilename) profilename=(char*)TransportName(transport); if(ParseXMLProfiles(profiles,profilename,(help_profile_xml|help_profile_json|help_profile_pl))) { fprintf(stderr,"Error: Cannot read the profiles in the file '%s'.\n",profiles); exit(EXIT_FAILURE); } profile=GetProfile(profilename); if(!profile) { fprintf(stderr,"Error: Cannot find a profile called '%s' in the file '%s'.\n",profilename,profiles); profile=(Profile*)calloc(1,sizeof(Profile)); profile->transport=transport; } /* Parse the other command line arguments that modify the profile */ for(arg=1;arg<argc;arg++) { if(!argv[arg]) continue; else if(!strncmp(argv[arg],"--highway-",10)) { Highway highway; char *equal=strchr(argv[arg],'='); char *string; double p; if(!equal) print_usage(0,argv[arg],NULL); string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+10); string[equal-argv[arg]-10]=0; highway=HighwayType(string); if(highway==Highway_None) print_usage(0,argv[arg],NULL); p=atof(equal+1); if(p<0 || p>100) print_usage(0,argv[arg],NULL); profile->highway[highway]=(score_t)(p/100); free(string); } else if(!strncmp(argv[arg],"--speed-",8)) { Highway highway; char *equal=strchr(argv[arg],'='); char *string; double s; if(!equal) print_usage(0,argv[arg],NULL); string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+8); string[equal-argv[arg]-8]=0; highway=HighwayType(string); if(highway==Highway_None) print_usage(0,argv[arg],NULL); s=atof(equal+1); if(s<0) print_usage(0,argv[arg],NULL); profile->speed[highway]=kph_to_speed(s); free(string); } else if(!strncmp(argv[arg],"--property-",11)) { Property property; char *equal=strchr(argv[arg],'='); char *string; double p; if(!equal) print_usage(0,argv[arg],NULL); string=strcpy((char*)malloc(strlen(argv[arg])),argv[arg]+11); string[equal-argv[arg]-11]=0; property=PropertyType(string); if(property==Property_None) print_usage(0,argv[arg],NULL); p=atof(equal+1); if(p<0 || p>100) print_usage(0,argv[arg],NULL); profile->props[property]=(score_t)(p/100); free(string); } else if(!strncmp(argv[arg],"--oneway=",9)) profile->oneway=!!atoi(&argv[arg][9]); else if(!strncmp(argv[arg],"--turns=",8)) profile->turns=!!atoi(&argv[arg][8]); else if(!strncmp(argv[arg],"--weight=",9)) profile->weight=tonnes_to_weight(atof(&argv[arg][9])); else if(!strncmp(argv[arg],"--height=",9)) profile->height=metres_to_height(atof(&argv[arg][9])); else if(!strncmp(argv[arg],"--width=",8)) profile->width=metres_to_width(atof(&argv[arg][8])); else if(!strncmp(argv[arg],"--length=",9)) profile->length=metres_to_length(atof(&argv[arg][9])); else print_usage(0,argv[arg],NULL); } /* Print one of the profiles if requested */ if(help_profile) { PrintProfile(profile); exit(EXIT_SUCCESS); } else if(help_profile_xml) { PrintProfilesXML(); exit(EXIT_SUCCESS); } else if(help_profile_json) { PrintProfilesJSON(); exit(EXIT_SUCCESS); } else if(help_profile_pl) { PrintProfilesPerl(); exit(EXIT_SUCCESS); } /* Load in the selected translation */ if(option_file_html || option_file_gpx_route || option_file_gpx_track || option_file_text || option_file_text_all) { if(translations) { if(!ExistsFile(translations)) { fprintf(stderr,"Error: The '--translations' option specifies a file '%s' that does not exist.\n",translations); exit(EXIT_FAILURE); } } else { translations=FileName(dirname,prefix,"translations.xml"); if(!ExistsFile(translations)) { char *defaulttranslations=FileName(ROUTINO_DATADIR,NULL,"translations.xml"); if(!ExistsFile(defaulttranslations)) { fprintf(stderr,"Error: The '--translations' option was not used and the files '%s' and '%s' do not exist.\n",translations,defaulttranslations); exit(EXIT_FAILURE); } free(translations); translations=defaulttranslations; } } if(ParseXMLTranslations(translations,language,0)) { fprintf(stderr,"Error: Cannot read the translations in the file '%s'.\n",translations); exit(EXIT_FAILURE); } if(language) { translation=GetTranslation(language); if(!translation) { fprintf(stderr,"Warning: Cannot find a translation called '%s' in the file '%s'.\n",language,translations); exit(EXIT_FAILURE); } } else { translation=GetTranslation(""); if(!translation) { fprintf(stderr,"Warning: No translations in '%s'.\n",translations); exit(EXIT_FAILURE); } } } /* Check the waypoints are valid */ for(waypoint=1;waypoint<=NWAYPOINTS;waypoint++) if(point_used[waypoint]==1 || point_used[waypoint]==2) print_usage(0,NULL,"All waypoints must have latitude and longitude."); if(first_waypoint>=last_waypoint) print_usage(0,NULL,"At least two waypoints must be specified."); /* Load in the data - Note: No error checking because Load*List() will call exit() in case of an error. */ if(!option_quiet) printf_first("Loading Files:"); OSMNodes=LoadNodeList(FileName(dirname,prefix,"nodes.mem")); OSMSegments=LoadSegmentList(FileName(dirname,prefix,"segments.mem")); OSMWays=LoadWayList(FileName(dirname,prefix,"ways.mem")); OSMRelations=LoadRelationList(FileName(dirname,prefix,"relations.mem")); if(!option_quiet) printf_last("Loaded Files: nodes, segments, ways & relations"); /* Check the profile is valid for use with this database */ if(UpdateProfile(profile,OSMWays)) { fprintf(stderr,"Error: Profile is invalid or not compatible with database.\n"); exit(EXIT_FAILURE); } /* Find all waypoints */ for(waypoint=first_waypoint;waypoint<=last_waypoint;waypoint++) { distance_t distmax=km_to_distance(MAXSEARCH); distance_t distmin; index_t segment=NO_SEGMENT; index_t node1,node2,node=NO_NODE; if(point_used[waypoint]!=3) continue; /* Find the closest point */ if(!option_quiet) printf_first("Finding Closest Point: Waypoint %d",waypoint); if(exactnodes) node=FindClosestNode(OSMNodes,OSMSegments,OSMWays,point_lat[waypoint],point_lon[waypoint],distmax,profile,&distmin); else { distance_t dist1,dist2; segment=FindClosestSegment(OSMNodes,OSMSegments,OSMWays,point_lat[waypoint],point_lon[waypoint],distmax,profile,&distmin,&node1,&node2,&dist1,&dist2); if(segment!=NO_SEGMENT) node=CreateFakes(OSMNodes,OSMSegments,waypoint,LookupSegment(OSMSegments,segment,1),node1,node2,dist1,dist2); } if(!option_quiet) printf_last("Found Closest Point: Waypoint %d",waypoint); if(node==NO_NODE) { fprintf(stderr,"Error: Cannot find node close to specified point %d.\n",waypoint); exit(EXIT_FAILURE); } if(!option_quiet) { double lat,lon; if(IsFakeNode(node)) GetFakeLatLong(node,&lat,&lon); else GetLatLong(OSMNodes,node,NULL,&lat,&lon); if(IsFakeNode(node)) printf("Waypoint %d is segment %"Pindex_t" (node %"Pindex_t" -> %"Pindex_t"): %3.6f %4.6f = %2.3f km\n",waypoint,segment,node1,node2, radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); else printf("Waypoint %d is node %"Pindex_t": %3.6f %4.6f = %2.3f km\n",waypoint,node, radians_to_degrees(lon),radians_to_degrees(lat),distance_to_km(distmin)); } point_node[waypoint]=node; } /* Check for reverse direction */ if(reverse) { waypoint_t temp; temp=first_waypoint; first_waypoint=last_waypoint; last_waypoint=temp; inc_dec_waypoint=-1; } /* Loop through all pairs of waypoints */ if(loop && reverse) { finish_node=point_node[last_waypoint]; finish_waypoint=last_waypoint; } for(waypoint=first_waypoint;waypoint!=(last_waypoint+inc_dec_waypoint);waypoint+=inc_dec_waypoint) { if(point_used[waypoint]!=3) continue; start_node=finish_node; finish_node=point_node[waypoint]; start_waypoint=finish_waypoint; finish_waypoint=waypoint; if(start_node==NO_NODE) continue; if(heading!=-999 && join_segment==NO_SEGMENT) join_segment=FindClosestSegmentHeading(OSMNodes,OSMSegments,OSMWays,start_node,heading,profile); /* Calculate the route */ if(!option_quiet) printf("Routing from waypoint %d to waypoint %d\n",start_waypoint,finish_waypoint); results[nresults]=CalculateRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node,start_waypoint,finish_waypoint); if(!results[nresults]) exit(EXIT_FAILURE); join_segment=results[nresults]->last_segment; nresults++; } if(loop && !reverse) { start_node=finish_node; finish_node=point_node[first_waypoint]; start_waypoint=finish_waypoint; finish_waypoint=first_waypoint; /* Calculate the route */ if(!option_quiet) printf("Routing from waypoint %d to waypoint %d\n",start_waypoint,finish_waypoint); results[nresults]=CalculateRoute(OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,start_node,join_segment,finish_node,start_waypoint,finish_waypoint); if(!results[nresults]) exit(EXIT_FAILURE); nresults++; } if(!option_quiet) { printf("Routed OK\n"); fflush(stdout); } /* Print out the combined route */ if(!option_quiet) printf_first("Generating Result Outputs"); if(!option_file_none) PrintRoute(results,nresults,OSMNodes,OSMSegments,OSMWays,OSMRelations,profile,translation); if(!option_quiet) printf_last("Generated Result Outputs"); /* Destroy the remaining results lists and data structures */ #ifdef DEBUG_MEMORY_LEAK for(waypoint=0;waypoint<nresults;waypoint++) FreeResultsList(results[waypoint]); DestroyNodeList(OSMNodes); DestroySegmentList(OSMSegments); DestroyWayList(OSMWays); DestroyRelationList(OSMRelations); FreeXMLProfiles(); FreeXMLTranslations(); #endif if(!option_quiet) printf_program_end(); exit(EXIT_SUCCESS); }
result_t widget_wndproc(handle_t hwnd, const canmsg_t *msg) { bool changed = false; hsi_window_t *wnd; get_wnddata(hwnd, (void **)&wnd); switch (msg->id) { case id_magnetic_heading: { int16_t direction; get_param_int16(msg, 0, &direction); while (direction < 0) direction += 360; while (direction > 359) direction -= 360; changed = wnd->direction != direction; wnd->direction = direction; } break; case id_heading: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->heading_bug != value; wnd->heading_bug = value; } break; case id_heading_angle: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->heading != value; wnd->heading = value; } break; case id_deviation: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->deviation != value; wnd->deviation = value; // the deviation is +/- * 10 } break; case id_selected_course: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->course != value; wnd->course = value; } break; case id_track: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->track != value; wnd->track = value; } break; case id_wind_speed: { float v; get_param_float(msg, &v); int16_t value = (int16_t)meters_per_second_to_knots(v); changed = wnd->wind_speed != value; wnd->wind_speed = value; } break; case id_wind_direction: { float v; get_param_float(msg, &v); int16_t value = (int16_t)radians_to_degrees(v); changed = wnd->wind_direction != value; wnd->wind_direction != value; } break; case id_distance_to_next: { float v; get_param_float(msg, &v); int16_t value = (int16_t)meters_to_nm(v); changed = wnd->distance_to_waypoint != value; wnd->distance_to_waypoint = value; } break; case id_magnetic_variation: { float v; get_param_float(msg, &v); int16_t value = (int16_t)radians_to_degrees(v); changed = wnd->magnetic_variation != value; wnd->magnetic_variation = value; } break; case id_estimated_time_to_next: { int16_t value; get_param_int16(msg, 0, &value); changed = wnd->time_to_waypoint != value; wnd->time_to_waypoint = value; } break; case id_paint: begin_paint(hwnd); update_window(hwnd, wnd); end_paint(hwnd); break; default: return defwndproc(hwnd, msg); } if (changed) invalidate_rect(hwnd, 0); return s_ok; }