added basic touch gestures
Former-commit-id: c9ec6d0e324c384603d216881ebdd7bd25ebab29 Former-commit-id: ac1418b52b5781b6d93dcfd1d50fa5544c3742d1
This commit is contained in:
parent
7d078324f2
commit
4acb3633e8
|
@ -27,9 +27,8 @@ void draw() {
|
||||||
SDL_RenderClear(game.renderer);
|
SDL_RenderClear(game.renderer);
|
||||||
|
|
||||||
if (Modes.map) {
|
if (Modes.map) {
|
||||||
drawStatus();
|
|
||||||
// SDL_RenderCopy(game.renderer,game.texture,NULL,NULL);
|
|
||||||
drawMap();
|
drawMap();
|
||||||
|
drawStatus();
|
||||||
} else {
|
} else {
|
||||||
drawList(10,0);
|
drawList(10,0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,30 @@ void getInput()
|
||||||
|
|
||||||
Modes.maxDist *= 1.0 + event.wheel.y / 10.0;
|
Modes.maxDist *= 1.0 + event.wheel.y / 10.0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_MULTIGESTURE:
|
||||||
|
Modes.maxDist /=1.0 + 4.0*event.mgesture.dDist;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_FINGERMOTION:;
|
||||||
|
|
||||||
|
//
|
||||||
|
// need to make lonlat to screen conversion class - this is just the inverse of the stuff in draw.c, without offsets
|
||||||
|
//
|
||||||
|
|
||||||
|
double scale_factor = (Modes.screen_width > Modes.screen_height) ? Modes.screen_width : Modes.screen_height;
|
||||||
|
|
||||||
|
double dx = -1.0 * (0.75*(double)Modes.screen_width / (double)Modes.screen_height) * Modes.screen_width * event.tfinger.dx * Modes.maxDist / (0.95 * scale_factor * 0.5);
|
||||||
|
double dy = -1.0 * Modes.screen_height * event.tfinger.dy * Modes.maxDist / (0.95 * scale_factor * 0.5);
|
||||||
|
|
||||||
|
double outLat = dy * (1.0/6371.0) * (180.0f / M_PI);
|
||||||
|
|
||||||
|
double outLon = dx * (1.0/6371.0) * (180.0f / M_PI) / cos(((Modes.fUserLat)/2.0f) * M_PI / 180.0f);
|
||||||
|
|
||||||
|
|
||||||
|
Modes.fUserLon += outLon;
|
||||||
|
Modes.fUserLat += outLat;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,11 +396,14 @@ 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 - Modes.fUserLon;
|
// double dLon = a->lon;// - Modes.fUserLon;
|
||||||
double dLat = a->lat - Modes.fUserLat;
|
// double dLat = a->lat;// - Modes.fUserLat;
|
||||||
|
|
||||||
a->dx = 6371.0 * dLon * M_PI / 180.0f * cos(((a->lat + Modes.fUserLat)/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;
|
||||||
|
|
||||||
|
a->dx = a->lon;
|
||||||
|
a->dy = a->lat;
|
||||||
|
|
||||||
if(time(NULL) - a->oldSeen[a->oldIdx] > MODES_INTERACTIVE_TRAIL_TTL_STEP) {
|
if(time(NULL) - a->oldSeen[a->oldIdx] > MODES_INTERACTIVE_TRAIL_TTL_STEP) {
|
||||||
a->oldIdx = (a->oldIdx+1) % 32;
|
a->oldIdx = (a->oldIdx+1) % 32;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
c1ba33fa01b0542b5be9bdef8df2078491847af5
|
7ed2e5c3d762695e6aaf4111584830b537a549a0
|
|
@ -64,6 +64,18 @@ int screenDist(double d) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pxFromLonLat(double *dx, double *dy, double lon, double lat) {
|
||||||
|
if(!lon || !lat) {
|
||||||
|
*dx = 0;
|
||||||
|
*dy = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
*dx = 6371.0 * (lon - Modes.fUserLon) * M_PI / 180.0f * cos(((lat + Modes.fUserLat)/2.0f) * M_PI / 180.0f);
|
||||||
|
*dy = 6371.0 * (lat - Modes.fUserLat) * M_PI / 180.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void screenCoords(int *outX, int *outY, double dx, double dy) {
|
void screenCoords(int *outX, int *outY, double dx, double dy) {
|
||||||
*outX = (Modes.screen_width>>1) + ((dx>0) ? 1 : -1) * screenDist(dx);
|
*outX = (Modes.screen_width>>1) + ((dx>0) ? 1 : -1) * screenDist(dx);
|
||||||
*outY = (Modes.screen_height * CENTEROFFSET) + ((dy>0) ? 1 : -1) * screenDist(dy);
|
*outY = (Modes.screen_height * CENTEROFFSET) + ((dy>0) ? 1 : -1) * screenDist(dy);
|
||||||
|
@ -211,7 +223,6 @@ void drawPlane(int x, int y, SDL_Color planeColor)
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
int currentX, currentY, prevX, prevY;
|
int currentX, currentY, prevX, prevY;
|
||||||
|
@ -232,9 +243,15 @@ void drawTrail(double *oldDx, double *oldDy, time_t * oldSeen, int idx) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
screenCoords(¤tX, ¤tY, oldDx[currentIdx], oldDy[currentIdx]);
|
double dx, dy;
|
||||||
|
|
||||||
screenCoords(&prevX, &prevY, oldDx[prevIdx], oldDy[prevIdx]);
|
pxFromLonLat(&dx, &dy, oldDx[currentIdx], oldDy[currentIdx]);
|
||||||
|
|
||||||
|
screenCoords(¤tX, ¤tY, dx, dy);
|
||||||
|
|
||||||
|
pxFromLonLat(&dx, &dy, oldDx[prevIdx], oldDy[prevIdx]);
|
||||||
|
|
||||||
|
screenCoords(&prevX, &prevY, dx, dy);
|
||||||
|
|
||||||
if(outOfBounds(currentX,currentY)) {
|
if(outOfBounds(currentX,currentY)) {
|
||||||
return;
|
return;
|
||||||
|
@ -287,26 +304,45 @@ void drawGrid()
|
||||||
|
|
||||||
void drawGeography() {
|
void drawGeography() {
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
|
|
||||||
for(int i=1; i<mapPoints_count/2; i++) {
|
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]) {
|
double dx, dy;
|
||||||
|
|
||||||
|
pxFromLonLat(&dx, &dy, mapPoints_relative[(i - 1) * 2], mapPoints_relative[(i - 1) * 2 + 1]);
|
||||||
|
|
||||||
|
if(!dx || !dy) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
screenCoords(&x1, &y1, mapPoints_relative[(i - 1) * 2], -mapPoints_relative[(i - 1) * 2 + 1]);
|
screenCoords(&x1, &y1, dx, dy);
|
||||||
screenCoords(&x2, &y2, mapPoints_relative[i * 2], -mapPoints_relative[i * 2 + 1]);
|
|
||||||
|
|
||||||
if(outOfBounds(x1,y1) && outOfBounds(x2,y2)) {
|
if(outOfBounds(x1,y1)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
double d1 = sqrt(mapPoints_relative[(i - 1) * 2] * mapPoints_relative[(i - 1) * 2] + mapPoints_relative[(i - 1) * 2 + 1] * mapPoints_relative[(i - 1) * 2 + 1]);
|
double d1 = sqrt(dx * dx + dy * dy);
|
||||||
double d2 = sqrt(mapPoints_relative[i * 2]* mapPoints_relative[i * 2] + mapPoints_relative[i * 2 + 1] * mapPoints_relative[i * 2 + 1]);
|
|
||||||
|
pxFromLonLat(&dx, &dy, mapPoints_relative[i * 2], mapPoints_relative[i * 2 + 1]);
|
||||||
|
|
||||||
|
if(!dx || !dy) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
screenCoords(&x2, &y2, dx, dy);
|
||||||
|
|
||||||
|
if(outOfBounds(x2,y2)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double d2 = sqrt(dx* dx + dy * dy);
|
||||||
|
|
||||||
|
|
||||||
//double alpha = 255.0 * (d1+d2) / 2;
|
//double alpha = 255.0 * (d1+d2) / 2;
|
||||||
//alpha = 255.0 - alpha / Modes.maxDist;
|
//alpha = 255.0 - alpha / Modes.maxDist;
|
||||||
double alpha = 1.0 - (d1+d2) / (2 * Modes.maxDist);
|
double alpha = 1.0 - (d1+d2) / (2 * Modes.maxDist);
|
||||||
|
|
||||||
|
|
||||||
alpha = (alpha < 0) ? 0 : alpha;
|
alpha = (alpha < 0) ? 0 : alpha;
|
||||||
|
|
||||||
if(AA) {
|
if(AA) {
|
||||||
|
@ -332,7 +368,7 @@ void drawMap(void) {
|
||||||
|
|
||||||
drawGeography();
|
drawGeography();
|
||||||
|
|
||||||
drawGrid();
|
//drawGrid();
|
||||||
|
|
||||||
while(a) {
|
while(a) {
|
||||||
if ((now - a->seen) < Modes.interactive_display_ttl) {
|
if ((now - a->seen) < Modes.interactive_display_ttl) {
|
||||||
|
@ -353,8 +389,11 @@ void drawMap(void) {
|
||||||
|
|
||||||
SDL_Color planeColor = signalToColor(colorIdx);
|
SDL_Color planeColor = signalToColor(colorIdx);
|
||||||
int x, y;
|
int x, y;
|
||||||
screenCoords(&x, &y, a->dx, a->dy);
|
//screenCoords(&x, &y, a->dx, a->dy);
|
||||||
|
|
||||||
|
double dx, dy;
|
||||||
|
pxFromLonLat(&dx, &dy, a->lon, a->lat);
|
||||||
|
screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
if(outOfBounds(x,y)) {
|
if(outOfBounds(x,y)) {
|
||||||
int outx, outy;
|
int outx, outy;
|
||||||
|
@ -468,4 +507,6 @@ void drawMap(void) {
|
||||||
// screen_x[i] = out_x;
|
// screen_x[i] = out_x;
|
||||||
// screen_y[i] = out_y;
|
// screen_y[i] = out_y;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0199e60b8c42340f3cf63513ca0753fdc71eb190
|
2056de76ba9dff16057865185ffa2eb99617235e
|
Loading…
Reference in a new issue