X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fgis-opengl.c;h=8b711426e123c7e76c60bc0b8d4c01af0de3662d;hp=dc32fa8de4e4f188e77d19399ce0b7dd342a84e2;hb=2be8bbde8f465947d364b28c5e156631caed6d25;hpb=ea8ac9ebb3309b84bed137bb3ff59926c23216ce diff --git a/src/gis-opengl.c b/src/gis-opengl.c index dc32fa8..8b71142 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -41,6 +41,7 @@ #include "roam.h" #include "objects/gis-object.h" +#include "objects/gis-tile.h" #include "objects/gis-marker.h" #include "objects/gis-callback.h" @@ -133,6 +134,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 +157,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 +181,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); @@ -187,7 +197,6 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles) glNormal3dv(tri->p.l->norm); glTexCoord2dv(xy[2]); glVertex3dv((double*)tri->p.l); glEnd(); } - g_list_free(triangles); } static void _draw_tiles(GisOpenGL *opengl, GisTile *tile) @@ -218,7 +227,8 @@ static void _draw_tiles(GisOpenGL *opengl, GisTile *tile) const gdouble s = tile->edge.n-(lat_step*(row+1)); const gdouble e = tile->edge.w+(lon_step*(col+1)); const gdouble w = tile->edge.w+(lon_step*(col+0)); - GList *these = roam_sphere_get_intersect(opengl->sphere, FALSE, n, s, e, w); + GList *these = roam_sphere_get_intersect(opengl->sphere, + FALSE, n, s, e, w); triangles = g_list_concat(triangles, these); } } @@ -228,6 +238,7 @@ static void _draw_tiles(GisOpenGL *opengl, GisTile *tile) } if (triangles) _draw_tile(opengl, tile, triangles); + g_list_free(triangles); } static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) @@ -278,6 +289,10 @@ static void _draw_callback(GisOpenGL *opengl, GisCallback *callback) static void _draw_object(GisOpenGL *opengl, GisObject *object) { //g_debug("GisOpenGL: draw_object"); + /* Skip hidden objects */ + if (object->hidden) + return; + /* Skip out of range objects */ if (object->lod > 0) { /* LOD test */ @@ -321,7 +336,7 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object) static void _load_object(GisOpenGL *opengl, GisObject *object) { - g_debug("GisOpenGL: load_object"); + //g_debug("GisOpenGL: load_object"); if (GIS_IS_MARKER(object)) { GisMarker *marker = GIS_MARKER(object); cairo_surface_t *surface = cairo_get_target(marker->cairo); @@ -338,13 +353,13 @@ static void _load_object(GisOpenGL *opengl, GisObject *object) cairo_image_surface_get_data(surface)); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - g_debug("load_texture: %d", marker->tex); + //g_debug("load_texture: %d", marker->tex); } } static void _unload_object(GisOpenGL *opengl, GisObject *object) { - g_debug("GisOpenGL: unload_object"); + //g_debug("GisOpenGL: unload_object"); if (GIS_IS_MARKER(object)) { GisMarker *marker = GIS_MARKER(object); glDeleteTextures(1, &marker->tex); @@ -534,7 +549,6 @@ GisViewer *gis_opengl_new(GisPlugins *plugins, GisPrefs *prefs) static void gis_opengl_center_position(GisViewer *_opengl, gdouble lat, gdouble lon, gdouble elev) { - GisOpenGL *opengl = GIS_OPENGL(_opengl); glRotatef(lon, 0, 1, 0); glRotatef(-lat, 1, 0, 0); glTranslatef(0, 0, elev2rad(elev)); @@ -554,22 +568,20 @@ static void gis_opengl_project(GisViewer *_opengl, px, py, pz); } -static void gis_opengl_set_height_func(GisViewer *_opengl, GisTile *tile, +static void gis_opengl_set_height_func(GisViewer *_opengl, GisBounds *bounds, RoamHeightFunc height_func, gpointer user_data, gboolean update) { GisOpenGL *opengl = GIS_OPENGL(_opengl); - if (!tile) - return; /* TODO: get points? */ g_mutex_lock(opengl->sphere_lock); GList *triangles = roam_sphere_get_intersect(opengl->sphere, TRUE, - tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); + bounds->n, bounds->s, bounds->e, bounds->w); for (GList *cur = triangles; cur; cur = cur->next) { RoamTriangle *tri = cur->data; RoamPoint *points[] = {tri->p.l, tri->p.m, tri->p.r, tri->split}; for (int i = 0; i < G_N_ELEMENTS(points); i++) { - if (tile->edge.n >= points[i]->lat && points[i]->lat >= tile->edge.s && - tile->edge.e >= points[i]->lon && points[i]->lon >= tile->edge.w) { + if (bounds->n >= points[i]->lat && points[i]->lat >= bounds->s && + bounds->e >= points[i]->lon && points[i]->lon >= bounds->w) { points[i]->height_func = height_func; points[i]->height_data = user_data; roam_point_update_height(points[i]);