1209 |
|
|
1210 |
#ifdef OSD_NAV |
#ifdef OSD_NAV |
1211 |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1212 |
#define OSD_NAV_H (150) |
#define OSD_NAV_H (130) |
1213 |
|
|
1214 |
|
/* http://mathforum.org/library/drmath/view/55417.html */ |
1215 |
|
static float get_bearing(float lat1, float lon1, float lat2, float lon2) { |
1216 |
|
return atan2( sin(lon2 - lon1) * cos(lat2), |
1217 |
|
cos(lat1) * sin(lat2) - |
1218 |
|
sin(lat1) * cos(lat2) * cos(lon2 - lon1)); |
1219 |
|
} |
1220 |
|
|
1221 |
|
/* http://mathforum.org/library/drmath/view/51722.html */ |
1222 |
|
static float get_distance(float lat1, float lon1, float lat2, float lon2) { |
1223 |
|
float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) + |
1224 |
|
sin(lat1) * sin(lat2)); |
1225 |
|
|
1226 |
|
// return(aob * 3959.0); /* great circle radius in miles */ |
1227 |
|
|
1228 |
|
return(aob * 6371000.0); /* great circle radius in meters */ |
1229 |
|
} |
1230 |
|
|
1231 |
static void |
static void |
1232 |
osd_render_nav(osm_gps_map_osd_t *osd) |
osd_render_nav(osm_gps_map_osd_t *osd) |
1239 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1240 |
cairo_t *cr = cairo_create(priv->nav.surface); |
cairo_t *cr = cairo_create(priv->nav.surface); |
1241 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1242 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1243 |
cairo_paint(cr); |
cairo_paint(cr); |
1244 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1245 |
|
|
1281 |
#define ARROW_WIDTH 0.3 |
#define ARROW_WIDTH 0.3 |
1282 |
#define ARROW_LENGTH 0.7 |
#define ARROW_LENGTH 0.7 |
1283 |
|
|
1284 |
float arot = deg2rad(45); |
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1285 |
|
if(gps) { |
1286 |
cairo_move_to(cr, |
float arot = get_bearing(gps->rlat, gps->rlon, |
1287 |
x + radius * ARROW_LENGTH * sin(arot), |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1288 |
y + radius * ARROW_LENGTH * -cos(arot)); |
|
1289 |
|
cairo_move_to(cr, |
1290 |
cairo_line_to(cr, |
x + radius * ARROW_LENGTH * sin(arot), |
1291 |
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
y + radius * ARROW_LENGTH * -cos(arot)); |
1292 |
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
|
1293 |
|
cairo_line_to(cr, |
1294 |
cairo_line_to(cr, |
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1295 |
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1296 |
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
|
1297 |
|
cairo_line_to(cr, |
1298 |
cairo_line_to(cr, |
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1299 |
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1300 |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
|
1301 |
|
cairo_line_to(cr, |
1302 |
cairo_close_path(cr); |
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1303 |
cairo_set_source_rgb (cr, 0, 0, 0); |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1304 |
cairo_fill (cr); |
|
1305 |
|
cairo_close_path(cr); |
1306 |
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
cairo_set_source_rgb (cr, 0, 0, 0); |
1307 |
y = osd_render_centered_text(cr, y, OSD_NAV_W, "xx,xx km"); |
cairo_fill (cr); |
1308 |
|
|
1309 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1310 |
|
|
1311 |
|
float dist = get_distance(gps->rlat, gps->rlon, |
1312 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1313 |
|
|
1314 |
|
char *dist_str = NULL; |
1315 |
|
if(dist<1000) |
1316 |
|
dist_str = g_strdup_printf("%u m", (int)dist); |
1317 |
|
else |
1318 |
|
dist_str = g_strdup_printf("%.1f km", dist/1000); |
1319 |
|
|
1320 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str); |
1321 |
|
g_free(dist_str); |
1322 |
|
} |
1323 |
|
|
1324 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1325 |
} |
} |