From dcfb59ca99b9c6e4e2aab1eef3ecd68240ec21e2 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 20 Oct 2018 00:17:25 -0500 Subject: [PATCH] out-of-bounds arrows in progress Former-commit-id: 2c82837c3b8f80978c93d5e7c568e6138a0829ba Former-commit-id: d6b7e05106a43c0cf35d683325cb7251b748b183 --- sdl1090/dump1090.h | 2 +- sdl1090/maps.c | 172 +++++++++++++++++++++++++------- sdl1090/status.c | 4 +- sdl1090/view1090.REMOVED.git-id | 2 +- sdl1090/view1090.c | 2 +- 5 files changed, 143 insertions(+), 39 deletions(-) diff --git a/sdl1090/dump1090.h b/sdl1090/dump1090.h index 1fa0e6c..f1208d7 100644 --- a/sdl1090/dump1090.h +++ b/sdl1090/dump1090.h @@ -160,7 +160,7 @@ // at least greater than a given level for us to dump the signal. #define MODES_DEBUG_NOPREAMBLE_LEVEL 25 -#define MODES_INTERACTIVE_REFRESH_TIME 33 // Milliseconds +#define MODES_INTERACTIVE_REFRESH_TIME 250 // Milliseconds #define MODES_INTERACTIVE_ROWS 22 // Rows on screen #define MODES_INTERACTIVE_DELETE_TTL 300 // Delete from the list after 300 seconds #define MODES_INTERACTIVE_DISPLAY_TTL 60 // Delete from display after 60 seconds diff --git a/sdl1090/maps.c b/sdl1090/maps.c index 1885370..7b11306 100644 --- a/sdl1090/maps.c +++ b/sdl1090/maps.c @@ -77,12 +77,66 @@ int outOfBounds(int x, int y) { } } -void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) -{ - if(outOfBounds(x,y)) { - return; +void drawPlaneOffMap(int x, int y, int *returnx, int *returny, SDL_Color planeColor) { + + double arrowWidth = 6.0 * Modes.screen_uiscale; + + float inx = x - (Modes.screen_width>>1); + float iny = y - Modes.screen_height * CENTEROFFSET; + + float outx, outy; + outx = inx; + outy = iny; + + if(abs(inx) > abs(y - (Modes.screen_height>>1)) * (float)(Modes.screen_width>>1) / (float)(Modes.screen_height * CENTEROFFSET)) { //left / right quadrants + outx = (Modes.screen_width>>1) * ((inx > 0) ? 1.0 : -1.0); + outy = (outx) * iny / (inx); + } else { // up / down quadrants + outy = Modes.screen_height * ((iny > 0) ? 1.0-CENTEROFFSET : -CENTEROFFSET ); + outx = (outy) * inx / (iny); } + // circleRGBA (game.screen,(Modes.screen_width>>1) + outx, Modes.screen_height * CENTEROFFSET + outy,50,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + // thickLineRGBA(game.screen,Modes.screen_width>>1,Modes.screen_height * CENTEROFFSET, (Modes.screen_width>>1) + outx, Modes.screen_height * CENTEROFFSET + outy,arrowWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + + double inmag = sqrt(inx *inx + iny*iny); + double vec[3]; + vec[0] = inx / inmag; + vec[1] = iny /inmag; + vec[2] = 0; + + double up[] = {0,0,1}; + + double out[3]; + + CROSSVP(out,vec,up); + + int x1, x2, x3, y1, y2, y3; + + // arrow 1 + x1 = (Modes.screen_width>>1) + outx - 2.0 * arrowWidth * vec[0] + round(-arrowWidth*out[0]); + y1 = (Modes.screen_height * CENTEROFFSET) + outy - 2.0 * arrowWidth * vec[1] + round(-arrowWidth*out[1]); + x2 = (Modes.screen_width>>1) + outx - 2.0 * arrowWidth * vec[0] + round(arrowWidth*out[0]); + y2 = (Modes.screen_height * CENTEROFFSET) + outy - 2.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]); + x3 = (Modes.screen_width>>1) + outx - arrowWidth * vec[0]; + y3 = (Modes.screen_height * CENTEROFFSET) + outy - arrowWidth * vec[1]; + filledTrigonRGBA(game.screen, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + + // arrow 2 + x1 = (Modes.screen_width>>1) + outx - 3.0 * arrowWidth * vec[0] + round(-arrowWidth*out[0]); + y1 = (Modes.screen_height * CENTEROFFSET) + outy - 3.0 * arrowWidth * vec[1] + round(-arrowWidth*out[1]); + x2 = (Modes.screen_width>>1) + outx - 3.0 * arrowWidth * vec[0] + round(arrowWidth*out[0]); + y2 = (Modes.screen_height * CENTEROFFSET) + outy - 3.0 * arrowWidth * vec[1] + round(arrowWidth*out[1]); + x3 = (Modes.screen_width>>1) + outx - 2.0 * arrowWidth * vec[0]; + y3 = (Modes.screen_height * CENTEROFFSET) + outy - 2.0 * arrowWidth * vec[1]; + filledTrigonRGBA(game.screen, x1, y1, x2, y2, x3, y3, planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); + + *returnx = x3; + *returny = y3; +} + +void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) +{ double body = 8.0 * Modes.screen_uiscale; double wing = 6.0 * Modes.screen_uiscale; double tail = 3.0 * Modes.screen_uiscale; @@ -101,6 +155,11 @@ void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) int x1, x2, y1, y2; + + // tempCenter + + // circleRGBA(game.screen, x, y, 10, 255, 0, 0, 255); + //body x1 = x + round(-body*vec[0]); y1 = y + round(-body*vec[1]); @@ -144,18 +203,12 @@ void drawPlaneHeading(int x, int y, double heading, SDL_Color planeColor) void drawPlane(int x, int y, SDL_Color planeColor) { - if(outOfBounds(x,y)) { - // - // Draw oob arrow here - // - return; - } - int length = 3.0; rectangleRGBA (game.screen, x - length, y - length, x+length, y + length, planeColor.r, planeColor.g, planeColor.b, SDL_ALPHA_OPAQUE); } + void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { @@ -208,7 +261,6 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { } } - void drawGrid() { int p1km = screenDist(1.0); @@ -302,6 +354,25 @@ void drawMap(void) { int x, y; screenCoords(&x, &y, a->dx, a->dy); + + if(outOfBounds(x,y)) { + int outx, outy; + drawPlaneOffMap(x, y, &outx, &outy, planeColor); + + drawStringBG(a->flight, outx + 5, outy + game.mapFontHeight, game.mapBoldFont, white, black); + + char alt[10] = " "; + snprintf(alt,10,"%dm", a->altitude); + drawStringBG(alt, outx + 5, outy + 2*game.mapFontHeight, game.mapFont, grey, black); + + char speed[10] = " "; + snprintf(speed,10,"%dkm/h", a->speed); + drawStringBG(speed, outx + 5, outy + 3*game.mapFontHeight, game.mapFont, grey, black); + + continue; + } + + if(a->created == 0) { a->created = mstime(); } @@ -309,33 +380,66 @@ void drawMap(void) { double age_ms = (double)(mstime() - a->created); if(age_ms < 500) { circleRGBA(game.screen, x, y, 500 - age_ms, 255,255, 255, (uint8_t)(255.0 * age_ms / 500.0)); - break; - } - - if(MODES_ACFLAGS_HEADING_VALID) { - drawPlaneHeading(x, y,a->track, planeColor); - - //char flight[11] = " "; - //snprintf(flight,11," %s ", a->flight); - //drawStringBG(flight, x, y + game.mapFontHeight, game.mapBoldFont, black, planeColor); - drawStringBG(a->flight, x + 5, y + game.mapFontHeight, game.mapBoldFont, white, black); - - char alt[10] = " "; - snprintf(alt,10,"%dm", a->altitude); - drawStringBG(alt, x + 5, y + 2*game.mapFontHeight, game.mapFont, grey, black); - - char speed[10] = " "; - snprintf(speed,10,"%dkm/h", a->speed); - drawStringBG(speed, x + 5, y + 3*game.mapFontHeight, game.mapFont, grey, black); - - lineRGBA(game.screen, x, y, x, y + 4*game.mapFontHeight, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); } else { - drawPlane(x, y, planeColor); - } + if(MODES_ACFLAGS_HEADING_VALID) { + drawPlaneHeading(x, y,a->track, planeColor); + + //char flight[11] = " "; + //snprintf(flight,11," %s ", a->flight); + //drawStringBG(flight, x, y + game.mapFontHeight, game.mapBoldFont, black, planeColor); + drawStringBG(a->flight, x + 5, y + game.mapFontHeight, game.mapBoldFont, white, black); + + char alt[10] = " "; + snprintf(alt,10,"%dm", a->altitude); + drawStringBG(alt, x + 5, y + 2*game.mapFontHeight, game.mapFont, grey, black); + + char speed[10] = " "; + snprintf(speed,10,"%dkm/h", a->speed); + drawStringBG(speed, x + 5, y + 3*game.mapFontHeight, game.mapFont, grey, black); + + lineRGBA(game.screen, x, y, x, y + 4*game.mapFontHeight, grey.r, grey.g, grey.b, SDL_ALPHA_OPAQUE); + } else { + drawPlane(x, y, planeColor); + } + } } } a = a->next; } + + // int mx, my; + // SDL_GetMouseState(&mx, &my); + // mx /= Modes.screen_upscale; + // my /= Modes.screen_upscale; + + // char mousepos[10] = " "; + // snprintf(mousepos,10,"%d %d", mx, my); + + // int outx, outy; + // drawPlaneOffMap(mx, my, &outx, &outy, white); + + + // char linepos[10] = " "; + // snprintf(linepos,10,"%2.2f %2.2f", outx, outy); + // int shiftedx, shiftedy; + // if(outx > (Modes.screen_width>>1)) { + // shiftedx = outx - 5 * game.mapFontHeight; + // } else { + // shiftedx = outx + game.mapFontHeight; + // } + + // if(outy > (Modes.screen_height>>1)) { + // shiftedy = outy - game.mapFontHeight; + // } else { + // shiftedy = outy + game.mapFontHeight; + // } + + + // drawStringBG(linepos, shiftedx, shiftedy, game.mapBoldFont, white, black); + + // // drawPlane(mx, my, signalToColor(100)); + // drawStringBG(mousepos, mx + 5, my - game.mapFontHeight, game.mapBoldFont, white, black); + } // void initializeMap(short *screen_x, short *screen_y) { diff --git a/sdl1090/status.c b/sdl1090/status.c index 8ffb0a3..4048527 100644 --- a/sdl1090/status.c +++ b/sdl1090/status.c @@ -139,7 +139,7 @@ void drawStatus() { snprintf(strLoc, 20, "%3.3fN %3.3f%c", Modes.fUserLat, fabs(Modes.fUserLon),(Modes.fUserLon > 0) ? 'E' : 'W'); drawStatusBox(&left, &top, "GPS", strLoc, pink); - drawBattery(&left, &top, 0.85); + // drawBattery(&left, &top, 0.85); char strPlaneCount[10] = " "; snprintf(strPlaneCount, 10,"%d/%d", Status.numVisiblePlanes, Status.numPlanes); @@ -157,7 +157,7 @@ void drawStatus() { snprintf(strSig, 18, "%.0f%%", 100.0 * Status.avgSig / 1024.0); drawStatusBox(&left, &top, "sAvg", strSig, green); - drawStatusBox(&left, &top, "||||", "MENU", grey); + // drawStatusBox(&left, &top, "||||", "MENU", grey); if(Status.closeCall != NULL) { drawStatusBox(&left, &top, "", "", black); //this is effectively a newline diff --git a/sdl1090/view1090.REMOVED.git-id b/sdl1090/view1090.REMOVED.git-id index 98b1431..a22d717 100644 --- a/sdl1090/view1090.REMOVED.git-id +++ b/sdl1090/view1090.REMOVED.git-id @@ -1 +1 @@ -d29ca545170e5498144b5f10fa17976c4f51eab5 \ No newline at end of file +dd693b5b8dd3325857fe2e5c6feea4ac62989202 \ No newline at end of file diff --git a/sdl1090/view1090.c b/sdl1090/view1090.c index 6a958ab..d3b47d0 100644 --- a/sdl1090/view1090.c +++ b/sdl1090/view1090.c @@ -87,7 +87,7 @@ void view1090InitConfig(void) { // Map options Modes.map = 1; - Modes.mapLogDist = 1; + Modes.mapLogDist = 0; // Display options Modes.screen_upscale = UPSCALE;