2017-09-14 16:39:56 +02:00
|
|
|
#include "dump1090.h"
|
2017-09-14 05:21:36 +02:00
|
|
|
#include "draw.h"
|
|
|
|
#include "parula.h"
|
|
|
|
|
|
|
|
extern void drawString(char *, int, int, TTF_Font *, SDL_Color);
|
|
|
|
|
|
|
|
void CROSSVP(double *v, double *u, double *w)
|
|
|
|
{
|
|
|
|
v[0] = u[1]*w[2] - u[2]*(w)[1];
|
|
|
|
v[1] = u[2]*w[0] - u[0]*(w)[2];
|
|
|
|
v[2] = u[0]*w[1] - u[1]*(w)[0];
|
|
|
|
}
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
|
|
|
|
SDL_Point screenCoords(double dx, double dy) {
|
|
|
|
SDL_Point out;
|
|
|
|
out.x = round(320.0 * (0.5 + (dx / 64.0)));
|
|
|
|
out.y = round(240.0 * (0.5 + (dy / 48.0)));
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight)
|
2017-09-14 05:21:36 +02:00
|
|
|
{
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
SDL_Point center = screenCoords(dx,dy);
|
|
|
|
|
|
|
|
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-14 05:21:36 +02:00
|
|
|
if(signal > 127) {
|
|
|
|
signal = 127;
|
|
|
|
}
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
if(signal < 0) {
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, 96, 96, 96, SDL_ALPHA_OPAQUE);
|
|
|
|
} else {
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, parula[signal][0], parula[signal][1], parula[signal][2], SDL_ALPHA_OPAQUE);
|
|
|
|
}
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
double body = 8.0;
|
|
|
|
double wing = 6.0;
|
|
|
|
double tail = 3.0;
|
|
|
|
|
|
|
|
double vec[3];
|
|
|
|
vec[0] = sin(heading * M_PI / 180);
|
|
|
|
vec[1] = cos(heading * M_PI / 180);
|
|
|
|
vec[2] = 0;
|
|
|
|
|
|
|
|
double up[] = {0,0,1};
|
|
|
|
|
|
|
|
double out[3];
|
|
|
|
|
|
|
|
CROSSVP(out,vec,up);
|
|
|
|
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
|
|
|
|
//body
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
x1 = center.x + round(-body*vec[0]);
|
|
|
|
y1 = center.y + round(-body*vec[1]);
|
|
|
|
x2 = center.x + round(body*vec[0]);
|
|
|
|
y2 = center.y + round(body*vec[1]);
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
//wing
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
x1 = center.x + round(-wing*out[0]);
|
|
|
|
y1 = center.y + round(-wing*out[1]);
|
|
|
|
x2 = center.x + round(wing*out[0]);
|
|
|
|
y2 = center.y + round(wing*out[1]);
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2);
|
|
|
|
|
|
|
|
//tail
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
x1 = center.x + round(-body*vec[0]) + round(-tail*out[0]);
|
|
|
|
y1 = center.y + round(-body*vec[1]) + round(-tail*out[1]);
|
|
|
|
x2 = center.x + round(-body*vec[0]) + round(tail*out[0]);
|
|
|
|
y2 = center.y + round(-body*vec[1]) + round(tail*out[1]);
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2);
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
if(flight) {
|
|
|
|
SDL_Color color = { 200, 200, 200 , 255};
|
|
|
|
drawString(flight, center.x + 10, center.y + 10, game.font, color);
|
|
|
|
}
|
2017-09-14 05:21:36 +02:00
|
|
|
}
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
void drawPlane(double dx, double dy, int signal)
|
2017-09-14 05:21:36 +02:00
|
|
|
{
|
2017-09-14 07:08:22 +02:00
|
|
|
|
|
|
|
SDL_Point center = screenCoords(dx,dy);
|
|
|
|
|
|
|
|
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(signal > 127) {
|
|
|
|
signal = 127;
|
|
|
|
}
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
if(signal < 0) {
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, 96, 96, 96, SDL_ALPHA_OPAQUE);
|
|
|
|
} else {
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, parula[signal][0], parula[signal][1], parula[signal][2], SDL_ALPHA_OPAQUE);
|
|
|
|
}
|
2017-09-14 05:21:36 +02:00
|
|
|
|
|
|
|
int length = 3.0;
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
SDL_RenderDrawLine(game.renderer, center.x-length , center.y , center.x+length , center.y );
|
|
|
|
SDL_RenderDrawLine(game.renderer, center.x , center.y-length , center.x , center.y+length );
|
|
|
|
}
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
|
|
|
|
int currentIdx, prevIdx;
|
2017-09-14 07:08:22 +02:00
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
SDL_Point current, prev;
|
2017-09-14 07:08:22 +02:00
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
time_t now = time(NULL);
|
2017-09-14 07:08:22 +02:00
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
for(int i=0; i < (MODES_INTERACTIVE_TRAIL_LENGTH - 1); i++) {
|
|
|
|
currentIdx = (idx - i) % MODES_INTERACTIVE_TRAIL_LENGTH;
|
|
|
|
currentIdx = currentIdx < 0 ? currentIdx + MODES_INTERACTIVE_TRAIL_LENGTH : currentIdx;
|
|
|
|
prevIdx = (idx - (i + 1)) % MODES_INTERACTIVE_TRAIL_LENGTH;
|
|
|
|
prevIdx = prevIdx < 0 ? prevIdx + MODES_INTERACTIVE_TRAIL_LENGTH : prevIdx;
|
|
|
|
|
|
|
|
if(oldDx[currentIdx] == 0 || oldDy[currentIdx] == 0) {
|
2017-09-14 07:08:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
2017-09-14 05:21:36 +02:00
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
if(oldDx[prevIdx] == 0 || oldDy[prevIdx] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-14 07:08:22 +02:00
|
|
|
|
|
|
|
current = screenCoords(oldDx[currentIdx], oldDy[currentIdx]);
|
|
|
|
prev = screenCoords(oldDx[prevIdx], oldDy[prevIdx]);
|
|
|
|
|
|
|
|
if(current.x < 0 || current.x >= 320 || current.y < 0 || current.y >= 240 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(prev.x < 0 || prev.x >= 320 || prev.y < 0 || prev.y >= 240 ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
|
|
|
|
double age = 1.0 - (double)(now - oldSeen[currentIdx]) / MODES_INTERACTIVE_TRAIL_TTL;
|
|
|
|
|
|
|
|
if(age < 0) {
|
|
|
|
age = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t colorVal = (uint8_t)floor(127.0 * age);
|
|
|
|
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
|
|
|
|
|
2017-09-14 07:08:22 +02:00
|
|
|
SDL_RenderDrawLine(game.renderer, prev.x, prev.y, current.x, current.y);
|
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
// SDL_SetRenderDrawColor(game.renderer, 255,0,0, SDL_ALPHA_OPAQUE);
|
2017-09-14 07:08:22 +02:00
|
|
|
|
2017-09-14 16:39:56 +02:00
|
|
|
// SDL_Rect spot = {.x = current.x-1, .y = current.y-1, .w = 2, .h = 2};
|
|
|
|
// SDL_RenderFillRect(game.renderer, &spot);
|
2017-09-14 07:08:22 +02:00
|
|
|
}
|
2017-09-14 05:21:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void drawGrid()
|
|
|
|
{
|
|
|
|
SDL_SetRenderDrawColor(game.renderer, 40, 40, 40, SDL_ALPHA_OPAQUE);
|
|
|
|
|
|
|
|
SDL_RenderDrawLine(game.renderer, 0, 120, 320, 120);
|
|
|
|
SDL_RenderDrawLine(game.renderer, 160, 0, 160, 240);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void delay(unsigned int frameLimit)
|
|
|
|
{
|
|
|
|
unsigned int ticks = SDL_GetTicks();
|
|
|
|
|
|
|
|
if (frameLimit < ticks)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frameLimit > ticks + 16)
|
|
|
|
{
|
|
|
|
SDL_Delay(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SDL_Delay(frameLimit - ticks);
|
|
|
|
}
|
|
|
|
}
|