Former-commit-id: 6ea8b3be1ff479c52f11d7547e5d026578416ae7
Former-commit-id: 3e1c0fae85d5670b55bc0fad147095dd3fc90d98
This commit is contained in:
Nathan 2017-09-17 09:46:48 -05:00
parent 37282b4d76
commit 0dd0cbc13c
17 changed files with 312 additions and 55 deletions

23
sdl1090/GL_edit.svf Normal file

File diff suppressed because one or more lines are too long

View file

@ -25,8 +25,8 @@ all: view1090
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) $(EXTRACFLAGS) -c $< $(CC) $(CFLAGS) $(EXTRACFLAGS) -c $<
view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o view1090: view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o mapdata.o
$(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o $(LIBS) $(LDFLAGS) $(CC) -g -o view1090 view1090.o anet.o interactive.o mode_ac.o mode_s.o net_io.o input.o draw.o font.o init.o maps.o mapdata.o $(LIBS) $(LDFLAGS)
clean: clean:
rm -f *.o view1090 rm -f *.o view1090

View file

@ -4,6 +4,7 @@
#include <unistd.h> #include <unistd.h>
#include "SDL/SDL.h" #include "SDL/SDL.h"
#include "SDL/SDL_ttf.h" #include "SDL/SDL_ttf.h"
#include "mapdata.h"
#ifdef RPI #ifdef RPI
#include <wiringPi.h> #include <wiringPi.h>

View file

@ -1,6 +1,7 @@
#include "dump1090.h" #include "dump1090.h"
#include "draw.h" #include "draw.h"
#include "parula.h" #include "parula.h"
#include "magma.h"
#include "SDL/SDL_gfxPrimitives.h" #include "SDL/SDL_gfxPrimitives.h"
#define LOGMAXDIST 1000.0 #define LOGMAXDIST 1000.0
@ -8,6 +9,8 @@
#define AA 0 #define AA 0
#define MAGMA 0
void CROSSVP(double *v, double *u, double *w) void CROSSVP(double *v, double *u, double *w)
{ {
v[0] = u[1]*w[2] - u[2]*(w)[1]; v[0] = u[1]*w[2] - u[2]*(w)[1];
@ -23,6 +26,26 @@ SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
return out; return out;
} }
SDL_Color signalToColor(int signal) {
SDL_Color planeColor;
if(signal > 127) {
signal = 127;
}
if(signal < 0) {
planeColor = setColor(96, 96, 96);
} else {
if(MAGMA) {
planeColor = setColor(magma[signal][0], magma[signal][1], magma[signal][2]);
} else {
planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
}
}
return planeColor;
}
int screenDist(double d) { int screenDist(double d) {
if(Modes.mapLogDist) { if(Modes.mapLogDist) {
return round((double)SCREEN_WIDTH * 0.5 * log(1.0+fabs(d)) / log(1.0+LOGMAXDIST)); return round((double)SCREEN_WIDTH * 0.5 * log(1.0+fabs(d)) / log(1.0+LOGMAXDIST));
@ -53,17 +76,7 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
return; return;
} }
if(signal > 127) { SDL_Color planeColor = signalToColor(signal);
signal = 127;
}
SDL_Color planeColor;
if(signal < 0) {
planeColor = setColor(96, 96, 96);
} else {
planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
}
double body = 8.0; double body = 8.0;
double wing = 6.0; double wing = 6.0;
@ -83,7 +96,6 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
int x1, x2, y1, y2; int x1, x2, y1, y2;
//body //body
x1 = x + round(-body*vec[0]); x1 = x + round(-body*vec[0]);
y1 = y + round(-body*vec[1]); y1 = y + round(-body*vec[1]);
x2 = x + round(body*vec[0]); x2 = x + round(body*vec[0]);
@ -91,40 +103,35 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
if(AA) { if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
aatrigonRGBA(game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
aacircleRGBA(game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else { } else {
thickLineRGBA(game.screen,x,y,x2,y2,2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); thickLineRGBA(game.screen,x,y,x2,y2,2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledTrigonRGBA (game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x1, y1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledCircleRGBA(game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//filledTrigonRGBA (game.screen, x + round(-wing*.35*out[0]), y + round(-wing*.35*out[1]), x + round(wing*.35*out[0]), y + round(wing*.35*out[1]), x2, y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledCircleRGBA (game.screen, x2,y2,1,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} }
//wing //wing
x1 = x + round(-wing*out[0]); x1 = x + round(-wing*out[0]);
y1 = y + round(-wing*out[1]); y1 = y + round(-wing*out[1]);
x2 = x + round(wing*out[0]); x2 = x + round(wing*out[0]);
y2 = y + round(wing*out[1]); y2 = y + round(wing*out[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
if(AA) { if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); aatrigonRGBA(game.screen, x1, y1, x2, y2, x+round(body*.35*vec[0]), y+round(body*.35*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else { } else {
filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(body*.35*vec[0]), y+round(body*.35*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA(game.screen, x1, y1, x2, y2, x+round(body*.35*vec[0]), y+round(body*.35*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} }
//tail
//tail
x1 = x + round(-body*.75*vec[0]) + round(-tail*out[0]); x1 = x + round(-body*.75*vec[0]) + round(-tail*out[0]);
y1 = y + round(-body*.75*vec[1]) + round(-tail*out[1]); y1 = y + round(-body*.75*vec[1]) + round(-tail*out[1]);
x2 = x + round(-body*.75*vec[0]) + round(tail*out[0]); x2 = x + round(-body*.75*vec[0]) + round(tail*out[0]);
y2 = y + round(-body*.75*vec[1]) + round(tail*out[1]); y2 = y + round(-body*.75*vec[1]) + round(tail*out[1]);
//thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
if(AA) { if(AA) {
aalineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); aatrigonRGBA (game.screen, x1, y1, x2, y2, x+round(-body*.5*vec[0]), y+round(-body*.5*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} else { } else {
//lineRGBA(game.screen,x1,y1,x2,y2,planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(-body*.5*vec[0]), y+round(-body*.5*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE); filledTrigonRGBA (game.screen, x1, y1, x2, y2, x+round(-body*.5*vec[0]), y+round(-body*.5*vec[1]),planeColor.r,planeColor.g,planeColor.b,SDL_ALPHA_OPAQUE);
} }
@ -143,17 +150,7 @@ void drawPlane(double dx, double dy, int signal)
return; return;
} }
if(signal > 127) { SDL_Color planeColor = signalToColor(signal);
signal = 127;
}
SDL_Color planeColor;
if(signal < 0) {
planeColor = setColor(96, 96, 96);
} else {
planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
}
int length = 3.0; int length = 3.0;
@ -204,10 +201,9 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
uint8_t colorVal = (uint8_t)floor(127.0 * age); uint8_t colorVal = (uint8_t)floor(127.0 * age);
if(AA) { if(AA) {
aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
} else { } else {
//lineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 2, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
thickLineRGBA(game.screen, prevX, prevY, currentX, currentY, 1, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
} }
} }
} }
@ -222,15 +218,62 @@ void drawGrid()
hlineRGBA (game.screen, 0, SCREEN_WIDTH, SCREEN_HEIGHT>>1, 127, 127, 127, SDL_ALPHA_OPAQUE); hlineRGBA (game.screen, 0, SCREEN_WIDTH, SCREEN_HEIGHT>>1, 127, 127, 127, SDL_ALPHA_OPAQUE);
vlineRGBA (game.screen, SCREEN_WIDTH>>1, 0, SCREEN_HEIGHT, 127, 127, 127, SDL_ALPHA_OPAQUE); vlineRGBA (game.screen, SCREEN_WIDTH>>1, 0, SCREEN_HEIGHT, 127, 127, 127, SDL_ALPHA_OPAQUE);
aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p1km, 64, 64, 64, SDL_ALPHA_OPAQUE); if(AA) {
aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p10km, 64, 64, 64, SDL_ALPHA_OPAQUE); aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p1km, 249,38,114, SDL_ALPHA_OPAQUE);
aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p100km, 64, 64, 64, SDL_ALPHA_OPAQUE); aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p10km, 249,38,114, 196);
aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p100km, 249,38,114, 127);
} else {
circleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p1km, 249,38,114, SDL_ALPHA_OPAQUE);
circleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p10km, 249,38,114, 196);
circleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p100km, 249,38,114, 127);
}
drawString("1km", (SCREEN_WIDTH>>1) + p1km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64)); drawString("1km", (SCREEN_WIDTH>>1) + p1km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64));
drawString("10km", (SCREEN_WIDTH>>1) + p10km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64)); drawString("10km", (SCREEN_WIDTH>>1) + p10km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64));
drawString("100km", (SCREEN_WIDTH>>1) + p100km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64)); drawString("100km", (SCREEN_WIDTH>>1) + p100km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64));
} }
void drawGeography() {
int x1, y1, x2, y2;
for(int i=1; i<mapPoints_count/2; i++) {
if(!mapPoints_relative[i * 2] || !mapPoints_relative[(i - 1) * 2 + 1] || !mapPoints_relative[i * 2] || !mapPoints_relative[i * 2 + 1]) {
continue;
}
screenCoords(&x1, &y1, mapPoints_relative[(i - 1) * 2], -mapPoints_relative[(i - 1) * 2 + 1]);
screenCoords(&x2, &y2, mapPoints_relative[i * 2], -mapPoints_relative[i * 2 + 1]);
if(outOfBounds(x1,y1) && outOfBounds(x2,y2)) {
continue;
}
SDL_Color geoColor;
// double x1d = (double) abs(x1 - (SCREEN_WIDTH>>1));
// double y1d = (double) abs(y1 - (SCREEN_HEIGHT>>1));
// double colorDist = sqrt(x1d * x1d + y1d * y1d) / (double) SCREEN_HEIGHT;
// colorDist = (colorDist < 0.0) ? 0.0 : colorDist;
// colorDist = (colorDist > 1.0) ? 1.0 : colorDist;
// geoColor.r = (uint8_t) (colorDist * 114.0 + (1.0 - colorDist) * 166.0);
// geoColor.g = (uint8_t) (colorDist * 29.0 + (1.0 - colorDist) * 266.0);
// geoColor.b = (uint8_t) (colorDist * 240.0 + (1.0 - colorDist) * 16.0);
geoColor.r = 114;
geoColor.g = 129;
geoColor.b = 255;
if(AA) {
aalineRGBA(game.screen, x1, y1, x2, y2,geoColor.r,geoColor.g,geoColor.b, SDL_ALPHA_OPAQUE);
} else {
lineRGBA(game.screen, x1, y1, x2, y2,geoColor.r,geoColor.g,geoColor.b, SDL_ALPHA_OPAQUE);
}
}
}
void delay(unsigned int frameLimit) void delay(unsigned int frameLimit)
{ {

View file

@ -31,7 +31,7 @@ void drawString(char * text, int x, int y, TTF_Font *font, SDL_Color color)
SDL_Surface *surface; SDL_Surface *surface;
SDL_Rect dest; SDL_Rect dest;
surface = TTF_RenderUTF8_Solid(font, text, color); surface = TTF_RenderUTF8_Blended(font, text, color);
if (surface == NULL) if (surface == NULL)
{ {

View file

@ -52,6 +52,8 @@ void init(char *title)
/* Set the screen title */ /* Set the screen title */
SDL_WM_SetCaption(title, NULL); SDL_WM_SetCaption(title, NULL);
initMaps();
} }
void cleanup() void cleanup()

View file

@ -379,10 +379,10 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
mm->fLat = a->lat; mm->fLat = a->lat;
mm->fLon = a->lon; mm->fLon = a->lon;
double dLon = a->lon+87.6651033; double dLon = a->lon - Modes.fUserLon;
double dLat = a->lat-***REMOVED***; double dLat = a->lat - Modes.fUserLat;
a->dx = 6371.0 * dLon * M_PI / 180.0f * cos(((a->lat+***REMOVED***)/2.0f) * M_PI / 180.0f); a->dx = 6371.0 * dLon * M_PI / 180.0f * cos(((a->lat + Modes.fUserLat)/2.0f) * M_PI / 180.0f);
a->dy = 6371.0 * dLat * M_PI / 180.0f; a->dy = 6371.0 * dLat * M_PI / 180.0f;
if(time(NULL) - a->oldSeen[a->oldIdx] > MODES_INTERACTIVE_TRAIL_TTL_STEP) { if(time(NULL) - a->oldSeen[a->oldIdx] > MODES_INTERACTIVE_TRAIL_TTL_STEP) {
@ -528,7 +528,7 @@ void interactiveShowData(void) {
snprintf(strLat, 8,"%7.03f", a->dx); snprintf(strLat, 8,"%7.03f", a->dx);
snprintf(strLon, 9,"%8.03f", a->dy); snprintf(strLon, 9,"%8.03f", a->dy);
} }
if (a->bFlags & MODES_ACFLAGS_AOG) { if (a->bFlags & MODES_ACFLAGS_AOG) {

130
sdl1090/magma.h Normal file
View file

@ -0,0 +1,130 @@
int magma[128][3] = {
{0, 0, 4},
{1, 0, 7},
{1, 1, 11},
{2, 2, 16},
{4, 3, 20},
{5, 4, 24},
{7, 5, 29},
{9, 6, 33},
{11, 7, 37},
{14, 8, 42},
{16, 9, 47},
{19, 10, 52},
{22, 11, 56},
{24, 11, 61},
{27, 12, 66},
{31, 12, 71},
{34, 11, 76},
{37, 11, 79},
{40, 11, 83},
{44, 10, 87},
{47, 10, 91},
{51, 9, 94},
{54, 9, 97},
{58, 9, 99},
{61, 9, 102},
{65, 9, 103},
{68, 10, 104},
{71, 10, 105},
{74, 11, 106},
{78, 13, 108},
{81, 13, 108},
{84, 14, 109},
{87, 15, 109},
{90, 17, 110},
{94, 18, 110},
{97, 19, 110},
{99, 20, 110},
{103, 22, 110},
{106, 23, 110},
{109, 24, 110},
{112, 25, 110},
{115, 26, 109},
{119, 27, 109},
{122, 28, 109},
{125, 29, 108},
{128, 31, 107},
{131, 32, 107},
{134, 33, 106},
{137, 34, 105},
{141, 35, 105},
{143, 36, 104},
{147, 37, 103},
{150, 38, 102},
{153, 40, 100},
{156, 41, 99},
{160, 42, 98},
{163, 43, 97},
{165, 44, 95},
{168, 46, 94},
{172, 47, 92},
{175, 49, 91},
{178, 50, 89},
{181, 51, 87},
{183, 53, 86},
{187, 55, 84},
{190, 56, 82},
{192, 57, 81},
{195, 60, 78},
{198, 61, 76},
{201, 63, 75},
{203, 64, 73},
{206, 67, 71},
{208, 69, 68},
{211, 71, 66},
{213, 73, 64},
{216, 76, 62},
{218, 78, 59},
{220, 81, 57},
{222, 83, 55},
{225, 86, 52},
{227, 88, 50},
{229, 91, 47},
{230, 94, 45},
{232, 97, 43},
{234, 100, 40},
{236, 103, 38},
{237, 106, 35},
{239, 109, 33},
{240, 112, 30},
{242, 116, 28},
{243, 119, 25},
{244, 122, 22},
{245, 126, 20},
{246, 129, 17},
{247, 133, 15},
{248, 136, 12},
{249, 140, 9},
{249, 143, 8},
{250, 146, 6},
{250, 151, 6},
{251, 155, 6},
{251, 158, 7},
{251, 161, 8},
{251, 165, 11},
{251, 169, 14},
{251, 173, 17},
{251, 177, 21},
{251, 180, 25},
{251, 184, 29},
{250, 188, 34},
{250, 192, 38},
{249, 196, 43},
{249, 200, 48},
{248, 204, 53},
{247, 208, 59},
{246, 212, 64},
{245, 216, 70},
{244, 219, 76},
{243, 223, 83},
{243, 226, 90},
{242, 230, 97},
{241, 234, 105},
{241, 237, 113},
{241, 240, 122},
{242, 243, 130},
{243, 246, 137},
{245, 249, 145},
{247, 251, 154}
};

View file

@ -0,0 +1 @@
cef8f740e8ef23f03d0d46f43348d73f1ca76c8e

45
sdl1090/mapdata.c Normal file

File diff suppressed because one or more lines are too long

2
sdl1090/mapdata.h Normal file
View file

@ -0,0 +1,2 @@
double *mapPoints_relative;
int mapPoints_count;

View file

@ -4,11 +4,6 @@
Game game; Game game;
extern void drawPlaneHeading(double , double , double, int, char *);
extern void drawPlane(double , double, int);
extern void drawTrail(double *, double *, time_t *, int);
extern void drawGrid();
// //
// ============================= Utility functions ========================== // ============================= Utility functions ==========================
// //
@ -35,6 +30,8 @@ void drawMap(void) {
SDL_FillRect(game.screen, NULL, 0); SDL_FillRect(game.screen, NULL, 0);
drawGeography();
drawGrid(); drawGrid();
while(a) { while(a) {

View file

@ -0,0 +1 @@
e0401e269cca0eea688090bd3b3254ca87db9834

View file

@ -21,3 +21,11 @@ void cleanup(void);
void getInput(void); void getInput(void);
//draw.c //draw.c
void drawGeography();
void drawPlaneHeading(double , double , double, int, char *);
void drawPlane(double , double, int);
void drawTrail(double *, double *, time_t *, int);
void drawGrid();
//mapdata.c
void initMaps();

View file

@ -1 +1 @@
820af17a48d07a090ce0b0bfc9738429489fb0eb 5a960086a7570a50a9f1c694d7fccf5b246c727b

View file

@ -164,6 +164,10 @@ int setupConnection(struct client *c) {
c->service = c->service =
Modes.bis = fd; Modes.bis = fd;
Modes.clients = c; Modes.clients = c;
// replace with gps
Modes.fUserLat = ***REMOVED***;
Modes.fUserLon = ***REMOVED***;
} }
return fd; return fd;
} }

Binary file not shown.