From 37170f3b0fe9625d75a294eeef1b4442fa63a7f1 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Tue, 26 Jan 2010 01:05:09 +0000 Subject: [PATCH] Fix rendering at the poles --- src/gis-opengl.c | 20 +++++++++++++++++++- src/gis-tile.c | 7 +++++++ src/plugins/srtm.c | 4 ++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/gis-opengl.c b/src/gis-opengl.c index bf60862..0fff2bf 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -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); diff --git a/src/gis-tile.c b/src/gis-tile.c index e265e05..6140334 100644 --- a/src/gis-tile.c +++ b/src/gis-tile.c @@ -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) diff --git a/src/plugins/srtm.c b/src/plugins/srtm.c index 6e07a80..058f54d 100644 --- a/src/plugins/srtm.c +++ b/src/plugins/srtm.c @@ -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) */ -- 2.43.2