conversion to sdl 1.2 + sdl_gfx

Former-commit-id: e2b7459153ed30b7d5ab0174c69b00cb25c83061
Former-commit-id: 5cc1c9ad482572a942c2609c24676106abdedfbb
This commit is contained in:
Nathan 2017-09-15 09:57:20 -05:00
parent 8fb50efe7b
commit 43283e175e
2 changed files with 97 additions and 63 deletions

View file

@ -5,6 +5,10 @@
extern void drawString(char *, int, int, TTF_Font *, SDL_Color); extern void drawString(char *, int, int, TTF_Font *, SDL_Color);
#define LOGPROJECTION 1
#define MAXDIST 1000.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];
@ -12,22 +16,43 @@ void CROSSVP(double *v, double *u, double *w)
v[2] = u[0]*w[1] - u[1]*(w)[0]; v[2] = u[0]*w[1] - u[1]*(w)[0];
} }
/* SDL_Color setColor(uint8_t r, uint8_t g, uint8_t b) {
SDL_Point screenCoords(double dx, double dy) { SDL_Color out;
SDL_Point out; out.r = r;
out.x = round(320.0 * (0.5 + (dx / 64.0))); out.g = g;
out.y = round(240.0 * (0.5 + (dy / 48.0))); out.b = b;
return out;
return out;
} }
*/
int screenDist(double d) {
if(LOGPROJECTION) {
return round((double)SCREEN_WIDTH * 0.5 * log(1.0+d) / log(1.0+MAXDIST));
} else {
return round((double)SCREEN_WIDTH * 0.5 * d / MAXDIST);
}
}
void screenCoords(int *outX, int *outY, double dx, double dy) {
*outX = (SCREEN_WIDTH>>1) + screenDist(dx);
*outY = (SCREEN_HEIGHT>>1) + screenDist(dy);
}
int outOfBounds(int x, int y) {
if(x < 0 || x >= SCREEN_WIDTH || y < 0 || y >= SCREEN_HEIGHT ) {
return 1;
} else {
return 0;
}
}
void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight) void drawPlaneHeading(double dx, double dy, double heading, int signal, char *flight)
{ {
/* //int planeWidth = 2;
SDL_Point center = screenCoords(dx,dy); int x, y;
screenCoords(&x, &y, dx, dy);
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { if(outOfBounds(x,y)) {
return; return;
} }
@ -35,10 +60,12 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
signal = 127; signal = 127;
} }
SDL_Color planeColor;
if(signal < 0) { if(signal < 0) {
SDL_SetRenderDrawColor(game.renderer, 96, 96, 96, SDL_ALPHA_OPAQUE); planeColor = setColor(96, 96, 96);
} else { } else {
SDL_SetRenderDrawColor(game.renderer, parula[signal][0], parula[signal][1], parula[signal][2], SDL_ALPHA_OPAQUE); planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
} }
double body = 8.0; double body = 8.0;
@ -60,44 +87,46 @@ void drawPlaneHeading(double dx, double dy, double heading, int signal, char *fl
//body //body
x1 = center.x + round(-body*vec[0]); x1 = x + round(-body*vec[0]);
y1 = center.y + round(-body*vec[1]); y1 = y + round(-body*vec[1]);
x2 = center.x + round(body*vec[0]); x2 = x + round(body*vec[0]);
y2 = center.y + round(body*vec[1]); y2 = y + round(body*vec[1]);
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2); //thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,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);
//wing //wing
x1 = center.x + round(-wing*out[0]); x1 = x + round(-wing*out[0]);
y1 = center.y + round(-wing*out[1]); y1 = y + round(-wing*out[1]);
x2 = center.x + round(wing*out[0]); x2 = x + round(wing*out[0]);
y2 = center.y + round(wing*out[1]); y2 = y + round(wing*out[1]);
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2); //thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,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);
//tail //tail
x1 = center.x + round(-body*vec[0]) + round(-tail*out[0]); x1 = x + round(-body*vec[0]) + round(-tail*out[0]);
y1 = center.y + round(-body*vec[1]) + round(-tail*out[1]); y1 = y + round(-body*vec[1]) + round(-tail*out[1]);
x2 = center.x + round(-body*vec[0]) + round(tail*out[0]); x2 = x + round(-body*vec[0]) + round(tail*out[0]);
y2 = center.y + round(-body*vec[1]) + round(tail*out[1]); y2 = y + round(-body*vec[1]) + round(tail*out[1]);
SDL_RenderDrawLine(game.renderer, x1, y1, x2, y2); //thickLineRGBA(game.screen,x1,y1,x2,y2,planeWidth,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);
if(flight) { if(strlen(flight)) {
SDL_Color color = { 200, 200, 200 , 255}; drawString(flight, x + 10, y + 10, game.font, planeColor);
drawString(flight, center.x + 10, center.y + 10, game.font, color); }
}
*/
} }
void drawPlane(double dx, double dy, int signal) void drawPlane(double dx, double dy, int signal)
{ {
/*
SDL_Point center = screenCoords(dx,dy);
if(center.x < 0 || center.x >= 320 || center.y < 0 || center.y >= 240 ) { int x, y;
screenCoords(&x, &y, dx, dy);
if(outOfBounds(x,y)) {
return; return;
} }
@ -105,25 +134,25 @@ void drawPlane(double dx, double dy, int signal)
signal = 127; signal = 127;
} }
SDL_Color planeColor;
if(signal < 0) { if(signal < 0) {
SDL_SetRenderDrawColor(game.renderer, 96, 96, 96, SDL_ALPHA_OPAQUE); planeColor = setColor(96, 96, 96);
} else { } else {
SDL_SetRenderDrawColor(game.renderer, parula[signal][0], parula[signal][1], parula[signal][2], SDL_ALPHA_OPAQUE); planeColor = setColor(parula[signal][0], parula[signal][1], parula[signal][2]);
} }
int length = 3.0; int length = 3.0;
SDL_RenderDrawLine(game.renderer, center.x-length , center.y , center.x+length , center.y ); rectangleRGBA (game.screen, x - length, y - length, x+length, y + length, planeColor.r, planeColor.g, planeColor.b, SDL_ALPHA_OPAQUE);
SDL_RenderDrawLine(game.renderer, center.x , center.y-length , center.x , center.y+length );
*/
} }
void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) { void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
/*
int currentIdx, prevIdx; int currentIdx, prevIdx;
SDL_Point current, prev; int currentX, currentY, prevX, prevY;
time_t now = time(NULL); time_t now = time(NULL);
@ -141,17 +170,17 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
continue; continue;
} }
current = screenCoords(oldDx[currentIdx], oldDy[currentIdx]); screenCoords(&currentX, &currentY, oldDx[currentIdx], oldDy[currentIdx]);
prev = screenCoords(oldDx[prevIdx], oldDy[prevIdx]);
if(current.x < 0 || current.x >= 320 || current.y < 0 || current.y >= 240 ) { screenCoords(&prevX, &prevY, oldDx[prevIdx], oldDy[prevIdx]);
continue;
if(outOfBounds(currentX,currentY)) {
return;
} }
if(prev.x < 0 || prev.x >= 320 || prev.y < 0 || prev.y >= 240 ) { if(outOfBounds(prevX,prevY)) {
continue; return;
} }
double age = 1.0 - (double)(now - oldSeen[currentIdx]) / MODES_INTERACTIVE_TRAIL_TTL; double age = 1.0 - (double)(now - oldSeen[currentIdx]) / MODES_INTERACTIVE_TRAIL_TTL;
@ -161,22 +190,27 @@ 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);
SDL_SetRenderDrawColor(game.renderer, colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE); aalineRGBA(game.screen, prevX, prevY, currentX, currentY,colorVal, colorVal, colorVal, SDL_ALPHA_OPAQUE);
}
SDL_RenderDrawLine(game.renderer, prev.x, prev.y, current.x, current.y);
// SDL_SetRenderDrawColor(game.renderer, 255,0,0, SDL_ALPHA_OPAQUE);
// SDL_Rect spot = {.x = current.x-1, .y = current.y-1, .w = 2, .h = 2};
// SDL_RenderFillRect(game.renderer, &spot);
}*/
} }
void drawGrid() void drawGrid()
{ {
hlineRGBA (game.screen, 0, 320, 120, 40, 40, 40, SDL_ALPHA_OPAQUE); int p1km = screenDist(1.0);
vlineRGBA (game.screen, 160, 0, 240, 40, 40, 40, SDL_ALPHA_OPAQUE); int p10km = screenDist(10.0);
int p100km = screenDist(100.0);
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);
aacircleRGBA (game.screen, SCREEN_WIDTH>>1, SCREEN_HEIGHT>>1, p1km, 64, 64, 64, SDL_ALPHA_OPAQUE);
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, p100km, 64, 64, 64, SDL_ALPHA_OPAQUE);
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("100km", (SCREEN_WIDTH>>1) + p100km + 5, (SCREEN_HEIGHT>>1) + 5, game.font, setColor(64,64,64));
} }

View file

@ -1 +1 @@
16533af5cceadbea2c10e6425e91d0560cabdbd8 dd9da3d4441175ab67ca8209c4dc330f48cf6590