quadtree working, poly drawing
Former-commit-id: f56b05b892922905cad6aeb8dcee279f130fa2f8 Former-commit-id: 55da641509850e377a9cce46253ee5dcb8cb4a7c
This commit is contained in:
parent
c10fb0ad10
commit
3097d6fdb3
138
draw.c
138
draw.c
|
@ -373,70 +373,144 @@ void drawGrid()
|
||||||
|
|
||||||
void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, double screen_lon_min, double screen_lon_max) {
|
void drawPolys(QuadTree *tree, double screen_lat_min, double screen_lat_max, double screen_lon_min, double screen_lon_max) {
|
||||||
|
|
||||||
|
// int skip = (int)(appData.maxDist / 25.0f);
|
||||||
|
// if(skip < 2) {
|
||||||
|
// skip = 2;
|
||||||
|
// }
|
||||||
|
int skip = 1;
|
||||||
|
|
||||||
|
|
||||||
if(tree == NULL) {
|
if(tree == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tree->lat_min > screen_lat_max || screen_lat_min > tree->lat_max) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tree->lon_min > screen_lon_max || screen_lon_min > tree->lon_max)
|
||||||
|
return;
|
||||||
|
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
||||||
if (!(tree->lat_min < screen_lat_min &&
|
drawPolys(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
tree->lat_max > screen_lat_max &&
|
drawPolys(tree->sw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
tree->lon_min < screen_lon_min &&
|
drawPolys(tree->ne, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
tree->lon_max > screen_lon_max)) {
|
drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
return;
|
|
||||||
}
|
// if(!(tree->lat_min > screen_lat_min &&
|
||||||
|
// tree->lat_max < screen_lat_max &&
|
||||||
|
// tree->lon_min > screen_lon_min &&
|
||||||
|
// tree->lon_max < screen_lon_max)){
|
||||||
|
// //printf("%f %f\n", tree->lat_min, screen_lat_min);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//Draw quadtree bounds
|
||||||
|
// pxFromLonLat(&dx, &dy, tree->lon_min, tree->lat_min);
|
||||||
|
// screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
|
// int top = y;
|
||||||
|
// int left = x;
|
||||||
|
|
||||||
|
// pxFromLonLat(&dx, &dy, tree->lon_max, tree->lat_max);
|
||||||
|
// screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
|
// int bottom = y;
|
||||||
|
// int right = x;
|
||||||
|
|
||||||
|
// rectangleRGBA(appData.renderer, left, top, right, bottom, red.r, red.g, red.b, 255);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Polygon *currentPolygon = tree->polygons;
|
Polygon *currentPolygon = tree->polygons;
|
||||||
|
|
||||||
while(currentPolygon != NULL) {
|
while(currentPolygon != NULL) {
|
||||||
// Sint16 *px = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
|
|
||||||
// Sint16 *py = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
|
|
||||||
|
|
||||||
// for(int i=0; i<currentPolygon->numPoints; i++) {
|
|
||||||
|
|
||||||
// pxFromLonLat(&dx, &dy, currentPolygon->points[i].lat, currentPolygon->points[i].lon);
|
Sint16 *px = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
|
||||||
// screenCoords(&x, &y, dx, dy);
|
Sint16 *py = (Sint16*)malloc(sizeof(Sint16*)*currentPolygon->numPoints);
|
||||||
|
|
||||||
// px[i] = x;
|
Point *currentPoint = currentPolygon->points;
|
||||||
// py[i] = y;
|
|
||||||
|
int i = 0;
|
||||||
|
while(currentPoint != NULL){
|
||||||
|
pxFromLonLat(&dx, &dy, currentPoint->lon, currentPoint->lat);
|
||||||
|
screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
|
px[i] = x;
|
||||||
|
py[i] = y;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
for(int k = 0; k < skip; k++) {
|
||||||
|
currentPoint = currentPoint->next;
|
||||||
|
if(currentPoint == NULL)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double alpha = 1.0;
|
||||||
|
//filledPolygonRGBA (appData.renderer, px, py, i, 0, 0, 0, 255);
|
||||||
|
|
||||||
|
polygonRGBA (appData.renderer, px, py, i, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha);
|
||||||
|
|
||||||
|
|
||||||
|
//// line version
|
||||||
|
|
||||||
|
// int x1,y1,x2,y2;
|
||||||
|
|
||||||
|
// if(currentPolygon->points == NULL)
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
// Point *prevPoint = currentPolygon->points;
|
||||||
|
// Point *currentPoint = prevPoint->next;
|
||||||
|
|
||||||
|
// while(currentPoint != NULL){
|
||||||
|
// pxFromLonLat(&dx, &dy, prevPoint->lon, prevPoint->lat);
|
||||||
|
// screenCoords(&x1, &y1, dx, dy);
|
||||||
|
|
||||||
|
// pxFromLonLat(&dx, &dy, currentPoint->lon, currentPoint->lat);
|
||||||
|
// screenCoords(&x2, &y2, dx, dy);
|
||||||
|
|
||||||
|
// double alpha = 1.0;
|
||||||
|
// thickLineRGBA(appData.renderer, x1, y1, x2, y2, appData.screen_uiscale, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha);
|
||||||
|
|
||||||
|
// prevPoint = currentPoint;
|
||||||
|
// currentPoint = currentPoint->next;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// double alpha = 1.0;
|
////bounding boxes
|
||||||
|
|
||||||
pxFromLonLat(&dx, &dy, currentPolygon->lat_min, currentPolygon->lon_min);
|
// pxFromLonLat(&dx, &dy, currentPolygon->lon_min, currentPolygon->lat_min);
|
||||||
screenCoords(&x, &y, dx, dy);
|
// screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
int top = y;
|
// int top = y;
|
||||||
int left = x;
|
// int left = x;
|
||||||
|
|
||||||
pxFromLonLat(&dx, &dy, currentPolygon->lat_max, currentPolygon->lon_max);
|
// pxFromLonLat(&dx, &dy, currentPolygon->lon_max, currentPolygon->lat_max);
|
||||||
screenCoords(&x, &y, dx, dy);
|
// screenCoords(&x, &y, dx, dy);
|
||||||
|
|
||||||
int bottom = y;
|
// int bottom = y;
|
||||||
int right = x;
|
// int right = x;
|
||||||
|
|
||||||
//polygonRGBA (appData.renderer, px, py, currentPolygon->numPoints, alpha * purple.r + (1.0-alpha) * blue.r, alpha * purple.g + (1.0-alpha) * blue.g, alpha * purple.b + (1.0-alpha) * blue.b, 255 * alpha);
|
|
||||||
|
|
||||||
rectangleRGBA(appData.renderer, left, top, right, bottom, purple.r, purple.g, purple.b, 255);
|
// rectangleRGBA(appData.renderer, left, top, right, bottom, purple.r, purple.g, purple.b, 255);
|
||||||
|
|
||||||
|
|
||||||
currentPolygon = currentPolygon->next;
|
currentPolygon = currentPolygon->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
//drawPolys(tree->nw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
|
||||||
//drawPolys(tree->sw, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
|
||||||
//drawPolys(tree->ne, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
|
||||||
//drawPolys(tree->se, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawGeography() {
|
void drawGeography() {
|
||||||
|
|
||||||
double screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max;
|
double screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max;
|
||||||
|
|
||||||
latLonFromScreenCoords(&screen_lon_min, &screen_lat_min, 0, 0);
|
latLonFromScreenCoords(&screen_lat_min, &screen_lon_min, 0, 0);
|
||||||
latLonFromScreenCoords(&screen_lon_max, &screen_lat_max, appData.screen_width, appData.screen_height);
|
latLonFromScreenCoords(&screen_lat_max, &screen_lon_max, appData.screen_width, appData.screen_height);
|
||||||
|
|
||||||
|
//printf("lat_min: %f, lat_max: %f, lon_min: %f, lon_max: %f\n", screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
drawPolys(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
drawPolys(&root, screen_lat_min, screen_lat_max, screen_lon_min, screen_lon_max);
|
||||||
|
|
||||||
|
@ -911,7 +985,7 @@ void draw() {
|
||||||
|
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
SDL_SetRenderDrawColor( appData.renderer, 0, 0, 0, 0);
|
SDL_SetRenderDrawColor( appData.renderer, 0, 15, 30, 0);
|
||||||
|
|
||||||
SDL_RenderClear(appData.renderer);
|
SDL_RenderClear(appData.renderer);
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
737abac0c33061fb6e1c86993e1b329d8a451dcd
|
b44aeb09f69d729d671d17f19bfd669b615a3702
|
|
@ -1 +1 @@
|
||||||
212d4fb6e7ea7b3c502081037abbac1fbdd9fccf
|
1392d6dd9fcc07ddac1768bd620a3355a2f836eb
|
|
@ -1 +1 @@
|
||||||
1c1e7d6bdf081956022b7592b8d59a929da2f463
|
76782b1a281904545022bc5880c90dcc50d20ec5
|
|
@ -1 +1 @@
|
||||||
59d9fddeaaf6bf38d20131f49c0ce5c67d56749c
|
4a7d01d6e64697656eef39194bc58105fdcba550
|
Loading…
Reference in a new issue