]> Pileus Git - grits/commitdiff
Fix rendering at the poles
authorAndy Spencer <andy753421@gmail.com>
Tue, 26 Jan 2010 01:05:09 +0000 (01:05 +0000)
committerAndy Spencer <andy753421@gmail.com>
Tue, 26 Jan 2010 01:05:09 +0000 (01:05 +0000)
src/gis-opengl.c
src/gis-tile.c
src/plugins/srtm.c

index bf6086204778f1977cf9177f5a5c980f058f25c8..0fff2bf4a57dfd2460363cac5f42841d718822bc 100644 (file)
@@ -481,12 +481,30 @@ static void gis_opengl_render_tile(GisViewer *_self, GisTile *tile)
                gdouble londist = e - w;
                gdouble latdist = n - s;
 
-               gdouble xy[][3] = {
+               gdouble xy[3][2] = {
                        {(lon[0]-w)/londist, 1-(lat[0]-s)/latdist},
                        {(lon[1]-w)/londist, 1-(lat[1]-s)/latdist},
                        {(lon[2]-w)/londist, 1-(lat[2]-s)/latdist},
                };
 
+               //if ((lat[0] == 90 && (xy[0][0] < 0 || xy[0][0] > 1)) ||
+               //    (lat[1] == 90 && (xy[1][0] < 0 || xy[1][0] > 1)) ||
+               //    (lat[2] == 90 && (xy[2][0] < 0 || xy[2][0] > 1)))
+               //      g_message("w,e=%4.f,%4.f   "
+               //                "lat,lon,x,y="
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   "
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   "
+               //                "%4.1f,%4.0f,%4.2f,%4.2f   ",
+               //              w,e,
+               //              lat[0], lon[0], xy[0][0], xy[0][1],
+               //              lat[1], lon[1], xy[1][0], xy[1][1],
+               //              lat[2], lon[2], xy[2][0], xy[2][1]);
+
+               /* Fix poles */
+               if (lat[0] == 90 || lat[0] == -90) xy[0][0] = 0.5;
+               if (lat[1] == 90 || lat[1] == -90) xy[1][0] = 0.5;
+               if (lat[2] == 90 || lat[2] == -90) xy[2][0] = 0.5;
+
                glEnable(GL_TEXTURE_2D);
                glBindTexture(GL_TEXTURE_2D, *(guint*)tile->data);
                glBegin(GL_TRIANGLES);
index e265e05342b12c1bb2d8d07d60a4ccf30e4edfb3..61403347d83567a78b614c1c2913f9a44a89c4f9 100644 (file)
@@ -142,6 +142,13 @@ GisTile *gis_tile_find(GisTile *self, gdouble lat, gdouble lon)
        gint    row = lat_offset / lat_step;
        gint    col = lon_offset / lon_step;
 
+       if (lon == 180) col--;
+       if (lat == -90) row--;
+
+       //if (lon == 180 || lon == -180)
+       //      g_message("lat=%f,lon=%f step=%f,%f off=%f,%f row=%d/%d,col=%d/%d",
+       //              lat,lon, lat_step,lon_step, lat_offset,lon_offset, row,rows,col,cols);
+
        if (row < 0 || row >= rows || col < 0 || col >= cols)
                return NULL;
        else if (self->children[row][col] && self->children[row][col]->data)
index 6e07a80b9a2930834b60e01562e7ce79e52c3a86..058f54d00ff3c6055931f696f5285a032834afa5 100644 (file)
@@ -65,6 +65,10 @@ static gdouble _height_func(gdouble lat, gdouble lon, gpointer _self)
        guint x_flr = (int)x;
        guint y_flr = (int)y;
 
+       //if (lon == 180 || lon == -180)
+       //      g_message("lon=%f w=%d min=%f max=%f dist=%f x=%f rem=%f flr=%d",
+       //                 lon,   w,  xmin,  xmax,  xdist,   x, x_rem, x_flr);
+
        /* TODO: Fix interpolation at edges:
         *   - Pad these at the edges instead of wrapping/truncating
         *   - Figure out which pixels to index (is 0,0 edge, center, etc) */