From baa66631f142b36581761e0248593d789b2d0840 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 7 Feb 2020 23:04:52 -0800 Subject: [PATCH] added padding on quadtree culling, scale bars Former-commit-id: 17ff9f3ef5107c35bf0fc7c5c065e845fb647662 [formerly 694324d663b143ec236604d7e984d9cab00233f8] [formerly b1bbf4581a8b1e3c0c46d7337b971786d86d050a] Former-commit-id: 0cb2f95464af5e4f55078ce0478fa8a608b60e80 Former-commit-id: 319c4c3339587f803f5b4a4372eb8aa83c4a6759 --- draw.c | 148 +++++++++++++++------------------------- draw.o.REMOVED.git-id | 2 +- view1090.REMOVED.git-id | 2 +- 3 files changed, 56 insertions(+), 96 deletions(-) diff --git a/draw.c b/draw.c index 43414bc..8b2a369 100644 --- a/draw.c +++ b/draw.c @@ -356,23 +356,50 @@ void drawTrail(double *oldDx, double *oldDy, double *oldHeading, time_t * oldSee } } -void drawGrid() +void drawScaleBars() { - int p1km = screenDist(1.0); - int p10km = screenDist(10.0); - int p100km = screenDist(100.0); + int scalePower = 0; + int scaleBarDist = screenDist((float)pow(10,scalePower)); - circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p1km, pink.r, pink.g, pink.b, 255); - circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p10km, pink.r, pink.g, pink.b, 195); - circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p100km, pink.r, pink.g, pink.b, 127); + char scaleLabel[8] = ""; + + thickLineRGBA(appData.renderer,10,10,10,10*appData.screen_uiscale,2,pink.r, pink.g, pink.b, 255); - drawString("1km", (appData.screen_width>>1) + (0.707 * p1km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p1km) + 5, appData.mapFont, pink); - drawString("10km", (appData.screen_width>>1) + (0.707 * p10km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p10km) + 5, appData.mapFont, pink); - drawString("100km", (appData.screen_width>>1) + (0.707 * p100km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, appData.mapFont, pink); + while(scaleBarDist < appData.screen_width) { + thickLineRGBA(appData.renderer,10+scaleBarDist,10,10+scaleBarDist,10*appData.screen_uiscale,2,pink.r, pink.g, pink.b, 255); + + if (Modes.metric) { + snprintf(scaleLabel,8,"%dkm", (int)pow(10,scalePower)); + } else { + snprintf(scaleLabel,8,"%dmi", (int)pow(10,scalePower)); + } + + drawString(scaleLabel, 10+scaleBarDist, 10*appData.screen_uiscale, appData.mapFont, pink); + + scalePower++; + scaleBarDist = screenDist((float)pow(10,scalePower)); + } + + scalePower--; + scaleBarDist = screenDist((float)pow(10,scalePower)); + + thickLineRGBA(appData.renderer,10,10+5*appData.screen_uiscale,10+scaleBarDist,10+5*appData.screen_uiscale,2,pink.r, pink.g, pink.b, 255); + + + // int p1km = screenDist(1.0); + // int p10km = screenDist(10.0); + // int p100km = screenDist(100.0); + + // circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p1km, pink.r, pink.g, pink.b, 255); + // circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p10km, pink.r, pink.g, pink.b, 195); + // circleRGBA (appData.renderer, appData.screen_width>>1, appData.screen_height * CENTEROFFSET, p100km, pink.r, pink.g, pink.b, 127); + + // drawString("1km", (appData.screen_width>>1) + (0.707 * p1km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p1km) + 5, appData.mapFont, pink); + // drawString("10km", (appData.screen_width>>1) + (0.707 * p10km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p10km) + 5, appData.mapFont, pink); + // drawString("100km", (appData.screen_width>>1) + (0.707 * p100km) + 5, (appData.screen_height * CENTEROFFSET) + (0.707 * p100km) + 5, appData.mapFont, pink); } void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, double screen_lon_min, double screen_lon_max) { - if(tree == NULL) { return; } @@ -381,17 +408,16 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou return; } - if (tree->lon_min > screen_lon_max || screen_lon_min > tree->lon_max) + if (tree->lon_min > screen_lon_max || screen_lon_min > tree->lon_max) { return; - - double dx, dy; - int x, y; + } drawPolys(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); drawPolys(tree->sw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); drawPolys(tree->ne, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); + double dx, dy; // if(!(tree->lat_min > screen_lat_min && // tree->lat_max < screen_lat_max && // tree->lon_min > screen_lon_min && @@ -401,6 +427,9 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou // } //Draw quadtree bounds + // + // int x, y; + // pxFromLonLat(&dx, &dy, tree->lon_min, tree->lat_min); // screenCoords(&x, &y, dx, dy); @@ -413,7 +442,7 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou // int bottom = y; // int right = x; -// rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255); + // rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255); @@ -522,83 +551,12 @@ void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, dou } void drawGeography() { - double screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max; - latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, 0, 0); - latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, appData.screen_width, appData.screen_height); - - //printf("lat_min: %f, lat_max: %f, lon_min: %f, lon_max: %f\n", screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); + latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, 0, appData.screen_height * -0.2); + latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, appData.screen_width, appData.screen_height * 1.2); drawPolys(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max); - - - return; - int x1, y1, x2, y2; - - int skip = (int)(appData.maxDist / 25.0f); - if(skip < 1) { - skip = 1; - } - - for(int i=skip; ix - 5 * appData.screen_uiscale; p_right = p->x + 5 * appData.screen_uiscale; p_top = p->y - 5 * appData.screen_uiscale; @@ -820,22 +780,22 @@ void resolveLabelConflicts() { //left collision if(check_left > p_left && check_left < p_right) { - check_p->ddox -= 0.04f * (float)(check_left - p_right); + check_p->ddox -= plane_force * (float)(check_left - p_right); } //right collision if(check_right > p_left && check_right < p_right) { - check_p->ddox -= 0.04f * (float)(check_right - p_left); + check_p->ddox -= plane_force * (float)(check_right - p_left); } //top collision if(check_top > p_top && check_top < p_bottom) { - check_p->ddoy -= 0.04f * (float)(check_top - p_bottom); + check_p->ddoy -= plane_force * (float)(check_top - p_bottom); } //bottom collision if(check_bottom > p_top && check_bottom < p_bottom) { - check_p->ddoy -= 0.04f * (float)(check_bottom - p_top); + check_p->ddoy -= plane_force * (float)(check_bottom - p_top); } check_p = check_p -> next; @@ -892,7 +852,7 @@ void drawMap() { SDL_Color planeColor; drawGeography(); - drawGrid(); + drawScaleBars(); for(int i = 0; i < 4; i++) { resolveLabelConflicts(); diff --git a/draw.o.REMOVED.git-id b/draw.o.REMOVED.git-id index e4b7902..b9c3d03 100644 --- a/draw.o.REMOVED.git-id +++ b/draw.o.REMOVED.git-id @@ -1 +1 @@ -876851c7cb19383223314e1599b55727c8695ce2 \ No newline at end of file +4dc33d9f8be5dcade60c5ce4a92e98d0da98849c \ No newline at end of file diff --git a/view1090.REMOVED.git-id b/view1090.REMOVED.git-id index 93377fb..cc7ce57 100644 --- a/view1090.REMOVED.git-id +++ b/view1090.REMOVED.git-id @@ -1 +1 @@ -53b830e927a180703148d0394461fe22fe54dc54 \ No newline at end of file +f2546650b9e09d0840df7238dbb42cac66e1f5e9 \ No newline at end of file