From 07cebdd8475eeaf5f9cd155ff0424e937aa5c6d8 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 3 May 2010 04:38:28 +0000 Subject: [PATCH] Add texture coords to tiles --- src/gis-opengl.c | 25 +++++++++++++++++-------- src/objects/gis-tile.c | 1 + src/objects/gis-tile.h | 5 ++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/gis-opengl.c b/src/gis-opengl.c index fc0c55e..d01a23c 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -133,6 +133,17 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles) tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); //g_message("drawing %4d triangles for tile edges=%7.2f,%7.2f,%7.2f,%7.2f", // g_list_length(triangles), tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); + gdouble n = tile->edge.n; + gdouble s = tile->edge.s; + gdouble e = tile->edge.e; + gdouble w = tile->edge.w; + + gdouble londist = e - w; + gdouble latdist = n - s; + + gdouble xscale = tile->coords.e - tile->coords.w; + gdouble yscale = tile->coords.s - tile->coords.n; + for (GList *cur = triangles; cur; cur = cur->next) { RoamTriangle *tri = cur->data; @@ -145,14 +156,6 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles) if (lon[2] > 90) lon[2] -= 360; } - gdouble n = tile->edge.n; - gdouble s = tile->edge.s; - gdouble e = tile->edge.e; - gdouble w = tile->edge.w; - - gdouble londist = e - w; - gdouble latdist = n - s; - gdouble xy[3][2] = { {(lon[0]-w)/londist, 1-(lat[0]-s)/latdist}, {(lon[1]-w)/londist, 1-(lat[1]-s)/latdist}, @@ -177,6 +180,12 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles) if (lat[1] == 90 || lat[1] == -90) xy[1][0] = 0.5; if (lat[2] == 90 || lat[2] == -90) xy[2][0] = 0.5; + /* Scale to tile coords */ + for (int i = 0; i < 3; i++) { + xy[i][0] = tile->coords.w + xy[i][0]*xscale; + xy[i][1] = tile->coords.n + xy[i][1]*yscale; + } + glEnable(GL_TEXTURE_2D); glEnable(GL_POLYGON_OFFSET_FILL); glBindTexture(GL_TEXTURE_2D, *(guint*)tile->data); diff --git a/src/objects/gis-tile.c b/src/objects/gis-tile.c index 24214ad..fbffd6f 100644 --- a/src/objects/gis-tile.c +++ b/src/objects/gis-tile.c @@ -58,6 +58,7 @@ GisTile *gis_tile_new(GisTile *parent, GisTile *tile = g_object_new(GIS_TYPE_TILE, NULL); tile->parent = parent; tile->atime = time(NULL); + gis_bbox_set_bounds(&tile->coords, 0, 1, 1, 0); gis_bbox_set_bounds(&tile->edge, n, s, e, w); return tile; } diff --git a/src/objects/gis-tile.h b/src/objects/gis-tile.h index e2b7252..c912b5a 100644 --- a/src/objects/gis-tile.h +++ b/src/objects/gis-tile.h @@ -38,12 +38,15 @@ struct _GisTile { /* Pointer to the tile data */ gpointer data; - /* Pointer to the tile data */ + /* Drawing order */ gint zindex; /* North,South,East,West limits */ GisBBox edge; + /* Texture mapping coordinates */ + GisBBox coords; + /* Pointers to parent/child nodes */ GisTile *parent; GisTile *children[2][2]; -- 2.43.2