From ad940f5d65ed4c95f72cac825244cae53dd6c78d Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Fri, 13 Nov 2009 23:54:06 +0000 Subject: [PATCH] Add preliminary support for points/markers --- HACKING | 3 + src/gis-opengl.c | 15 +++++ src/gis-opengl.h | 4 ++ src/gis_test.c | 3 +- src/plugins/Makefile.am | 3 +- src/plugins/test.c | 138 ++++++++++++++++++++++++++++++++++++++++ src/plugins/test.h | 50 +++++++++++++++ src/roam.c | 28 ++++---- src/roam.h | 1 + 9 files changed, 226 insertions(+), 19 deletions(-) create mode 100644 src/plugins/test.c create mode 100644 src/plugins/test.h diff --git a/HACKING b/HACKING index e69de29..4c6f0e8 100644 --- a/HACKING +++ b/HACKING @@ -0,0 +1,3 @@ +http://www.opengl.org/sdk/docs/man/ +http://www.glprogramming.com/red/ +http://www.glprogramming.com/blue/ diff --git a/src/gis-opengl.c b/src/gis-opengl.c index 31e1f39..0352fce 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -105,6 +105,8 @@ static void set_visuals(GisOpenGL *self) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //glShadeModel(GL_FLAT); + + roam_sphere_update_view(self->sphere); } @@ -286,6 +288,19 @@ void gis_opengl_center_position(GisOpenGL *self, gdouble lat, gdouble lon, gdoub glTranslatef(0, 0, elev2rad(elev)); } +void gis_opengl_project(GisOpenGL *self, + gdouble lat, gdouble lon, gdouble elev, + gdouble *px, gdouble *py, gdouble *pz) +{ + gdouble x, y, z; + lle2xyz(lat, lon, elev, &x, &y, &z); + gluProject(x, y, z, + self->sphere->view->model, + self->sphere->view->proj, + self->sphere->view->view, + px, py, pz); +} + void gis_opengl_render_tile(GisOpenGL *self, GisTile *tile) { if (!tile || !tile->data) diff --git a/src/gis-opengl.h b/src/gis-opengl.h index d55254f..2e80d07 100644 --- a/src/gis-opengl.h +++ b/src/gis-opengl.h @@ -67,6 +67,10 @@ GisOpenGL *gis_opengl_new(GisWorld *world, GisView *view, GisPlugins *plugins); void gis_opengl_center_position(GisOpenGL *opengl, gdouble lat, gdouble lon, gdouble elev); +void gis_opengl_project(GisOpenGL *opengl, + gdouble lat, gdouble lon, gdouble elev, + gdouble *px, gdouble *py, gdouble *pz); + void gis_opengl_render_tile(GisOpenGL *opengl, GisTile *tile); void gis_opengl_render_tiles(GisOpenGL *opengl, GisTile *root); diff --git a/src/gis_test.c b/src/gis_test.c index efd9218..ead9d99 100644 --- a/src/gis_test.c +++ b/src/gis_test.c @@ -60,7 +60,8 @@ int main(int argc, char **argv) gdk_threads_leave(); gis_plugins_load(plugins, "bmng", world, view, opengl, prefs); - gis_plugins_load(plugins, "srtm", world, view, opengl, prefs); + //gis_plugins_load(plugins, "srtm", world, view, opengl, prefs); + gis_plugins_load(plugins, "test", world, view, opengl, prefs); gis_view_set_site(view, "KLSX"); diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index e97bf6f..7d27bc6 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -7,9 +7,10 @@ LIBS = $(top_srcdir)/src/libgis.la pluginsdir = "$(libdir)/gis" -plugins_LTLIBRARIES = bmng.la srtm.la +plugins_LTLIBRARIES = bmng.la srtm.la test.la bmng_la_SOURCES = bmng.c bmng.h srtm_la_SOURCES = srtm.c srtm.h +test_la_SOURCES = test.c test.h test: ( cd ../; make test ) diff --git a/src/plugins/test.c b/src/plugins/test.c new file mode 100644 index 0000000..4d1af53 --- /dev/null +++ b/src/plugins/test.c @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2009 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include + +#include "test.h" + +/*********** + * Methods * + ***********/ +GisPluginTest *gis_plugin_test_new(GisWorld *world, GisView *view, GisOpenGL *opengl) +{ + g_debug("GisPluginTest: new"); + GisPluginTest *self = g_object_new(GIS_TYPE_PLUGIN_TEST, NULL); + self->view = view; + self->opengl = opengl; + return self; +} + +static void gis_plugin_test_expose(GisPlugin *_self) +{ + GisPluginTest *self = GIS_PLUGIN_TEST(_self); + g_debug("GisPluginTest: expose"); + + double width = GTK_WIDGET(self->opengl)->allocation.width; + double height = GTK_WIDGET(self->opengl)->allocation.height; + + // St. Charles + // lat = 38.841847 + // lon = -90.491982 + gdouble px, py, pz; + gis_opengl_project(self->opengl, + 38.841847, -90.491982, 0, &px, &py, &pz); + py = height-py; + + //cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + //cairo_t *cairo = cairo_create(surface); + //cairo_set_source_rgba(cairo, 1, 1, 1, 1); + //cairo_arc(cairo, px, py, 4, 0, 2*G_PI); + //cairo_fill(cairo); + //cairo_move_to(cairo, px+4, py-8); + //cairo_set_font_size(cairo, 10); + //cairo_show_text(cairo, "Marker!"); + + //guint tex; + //glEnable(GL_TEXTURE_2D); + //glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + //glPixelStorei(GL_PACK_ALIGNMENT, 1); + //glGenTextures(1, &tex); + //glBindTexture(GL_TEXTURE_2D, tex); + //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + // 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); + + //glMatrixMode(GL_PROJECTION); + //glLoadIdentity(); + //glMatrixMode(GL_MODELVIEW); + //glLoadIdentity(); + + //glDisable(GL_COLOR_MATERIAL); + //glDisable(GL_CULL_FACE); + //glDisable(GL_DEPTH_TEST); + //glDisable(GL_LIGHTING); + //glBegin(GL_QUADS); + //glTexCoord2d(0, 0); glVertex3f(-1, 1, 1); + //glTexCoord2d(1, 0); glVertex3f( 1, 1, 1); + //glTexCoord2d(1, 1); glVertex3f( 1, -1, 1); + //glTexCoord2d(0, 1); glVertex3f(-1, -1, 1); + //glEnd(); + //glDeleteTextures(1, &tex); + //cairo_destroy(cairo); + //cairo_surface_destroy(surface); +} + + +/**************** + * GObject code * + ****************/ +/* Plugin init */ +static void gis_plugin_test_plugin_init(GisPluginInterface *iface); +G_DEFINE_TYPE_WITH_CODE(GisPluginTest, gis_plugin_test, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(GIS_TYPE_PLUGIN, + gis_plugin_test_plugin_init)); +static void gis_plugin_test_plugin_init(GisPluginInterface *iface) +{ + g_debug("GisPluginTest: plugin_init"); + /* Add methods to the interface */ + iface->expose = gis_plugin_test_expose; +} +/* Class/Object init */ +static void gis_plugin_test_init(GisPluginTest *self) +{ + g_debug("GisPluginTest: init"); + /* Set defaults */ + self->view = NULL; + self->opengl = NULL; +} +static void gis_plugin_test_dispose(GObject *gobject) +{ + g_debug("GisPluginTest: dispose"); + GisPluginTest *self = GIS_PLUGIN_TEST(gobject); + /* Drop references */ + G_OBJECT_CLASS(gis_plugin_test_parent_class)->dispose(gobject); +} +static void gis_plugin_test_finalize(GObject *gobject) +{ + g_debug("GisPluginTest: finalize"); + GisPluginTest *self = GIS_PLUGIN_TEST(gobject); + /* Free data */ + G_OBJECT_CLASS(gis_plugin_test_parent_class)->finalize(gobject); + +} +static void gis_plugin_test_class_init(GisPluginTestClass *klass) +{ + g_debug("GisPluginTest: class_init"); + GObjectClass *gobject_class = (GObjectClass*)klass; + gobject_class->dispose = gis_plugin_test_dispose; + gobject_class->finalize = gis_plugin_test_finalize; +} diff --git a/src/plugins/test.h b/src/plugins/test.h new file mode 100644 index 0000000..939e95c --- /dev/null +++ b/src/plugins/test.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2009 Andy Spencer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __TEST_H__ +#define __TEST_H__ + +#include + +#define GIS_TYPE_PLUGIN_TEST (gis_plugin_test_get_type ()) +#define GIS_PLUGIN_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GIS_TYPE_PLUGIN_TEST, GisPluginTest)) +#define GIS_IS_PLUGIN_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GIS_TYPE_PLUGIN_TEST)) +#define GIS_PLUGIN_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIS_TYPE_PLUGIN_TEST, GisPluginTestClass)) +#define GIS_IS_PLUGIN_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIS_TYPE_PLUGIN_TEST)) +#define GIS_PLUGIN_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIS_TYPE_PLUGIN_TEST, GisPluginTestClass)) + +typedef struct _GisPluginTest GisPluginTest; +typedef struct _GisPluginTestClass GisPluginTestClass; + +struct _GisPluginTest { + GObject parent_instance; + + /* instance members */ + GisView *view; + GisOpenGL *opengl; +}; + +struct _GisPluginTestClass { + GObjectClass parent_class; +}; + +GType gis_plugin_test_get_type(); + +/* Methods */ +GisPluginTest *gis_plugin_test_new(GisWorld *world, GisView *view, GisOpenGL *opengl); + +#endif diff --git a/src/roam.c b/src/roam.c index de09bce..3fe2e4c 100644 --- a/src/roam.c +++ b/src/roam.c @@ -34,19 +34,6 @@ * - Target polygon count/detail */ -/* Misc */ -RoamView *roam_view_new() -{ - return g_new0(RoamView, 1); -} -void roam_view_update(RoamView *view) -{ - glGetDoublev (GL_MODELVIEW_MATRIX, view->model); - glGetDoublev (GL_PROJECTION_MATRIX, view->proj); - glGetIntegerv(GL_VIEWPORT, view->view); - view->version++; -} - /* For GPQueue comparators */ static gint tri_cmp(RoamTriangle *a, RoamTriangle *b, gpointer data) { @@ -535,16 +522,23 @@ RoamSphere *roam_sphere_new() return self; } +void roam_sphere_update_view(RoamSphere *self) +{ + if (!self->view) + self->view = g_new0(RoamView, 1); + glGetDoublev (GL_MODELVIEW_MATRIX, self->view->model); + glGetDoublev (GL_PROJECTION_MATRIX, self->view->proj); + glGetIntegerv(GL_VIEWPORT, self->view->view); + self->view->version++; +} void roam_sphere_update_errors(RoamSphere *self) { g_debug("RoamSphere: update_errors - polys=%d", self->polys); - if (!self->view) - self->view = roam_view_new(); - roam_view_update(self->view); - GPtrArray *tris = g_pqueue_get_array(self->triangles); GPtrArray *dias = g_pqueue_get_array(self->diamonds); + roam_sphere_update_view(self); + for (int i = 0; i < tris->len; i++) { RoamTriangle *tri = tris->pdata[i]; roam_triangle_update_errors(tri, self); diff --git a/src/roam.h b/src/roam.h index 94b205f..3845700 100644 --- a/src/roam.h +++ b/src/roam.h @@ -117,6 +117,7 @@ struct _RoamSphere { RoamTriangle *roots[8]; }; RoamSphere *roam_sphere_new(); +void roam_sphere_update_view(RoamSphere *sphere); void roam_sphere_update_errors(RoamSphere *sphere); void roam_sphere_split_one(RoamSphere *sphere); void roam_sphere_merge_one(RoamSphere *sphere); -- 2.43.2