From: Andy Spencer Date: Mon, 25 Jan 2010 07:45:09 +0000 (+0000) Subject: Removing unnecessary things from gis-object X-Git-Tag: v0.4~135 X-Git-Url: http://pileus.org/git/?p=grits;a=commitdiff_plain;h=a0a503f0fd257c18eaff3a5a1ae0a037f351f187 Removing unnecessary things from gis-object - GisObject primitives aren't being used anymore (for now) --- diff --git a/src/gis-object.c b/src/gis-object.c index cfd1870..bd6c5c9 100644 --- a/src/gis-object.c +++ b/src/gis-object.c @@ -21,10 +21,6 @@ #include "gis-object.h" #include "gis-util.h" -/* TODO - * - Manage normals for GisPoint - */ - /* GisPoint */ GisPoint *gis_point_new() { @@ -36,113 +32,15 @@ void gis_point_set_lle(GisPoint *self, gdouble lat, gdouble lon, gdouble elev) self->lat = lat; self->lon = lon; self->elev = elev; - lle2xyz(self->lat, self->lon, self->elev, - &self->x, &self->y, &self->z); -} - -void gis_point_set_xyz(GisPoint *self, gdouble x, gdouble y, gdouble z) -{ - self->x = x; - self->y = y; - self->z = z; } -void gis_point_set_coords(GisPoint *self, gdouble x, gdouble y) +void gis_point_free(GisPoint *self) { - self->cx = x; - self->cy = y; -} - -void gis_point_project(GisPoint *self, GisProjection *proj) -{ - gluProject(self->x, self->y, self->z, - proj->model, proj->proj, proj->view, - &self->px, &self->py, &self->pz); -} - -GisPoint *gis_point_ref(GisPoint *self) -{ - self->refs++; - return self; -} - -void gis_point_unref(GisPoint *self) -{ - self->refs--; - if (self->refs <= 0) - g_free(self); -} - - -/* GisTriangle */ -GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex) -{ - GisTriangle *self = g_new0(GisTriangle, 1); - GIS_OBJECT(self)->type = GIS_TYPE_TRIANGLE; - gis_point_set_xyz(&GIS_OBJECT(self)->center, - (a->x + b->x + c->x)/3, - (a->y + b->y + c->y)/3, - (a->z + b->z + c->z)/3); - self->verts[0] = gis_point_ref(a); - self->verts[1] = gis_point_ref(b); - self->verts[2] = gis_point_ref(c); - self->tex = tex; - return self; -} - -void gis_triangle_free(GisTriangle *self) -{ - gis_point_unref(self->verts[0]); - gis_point_unref(self->verts[1]); - gis_point_unref(self->verts[2]); - g_free(self); -} - - -/* GisQuad */ -GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex) -{ - GisQuad *self = g_new0(GisQuad, 1); - GIS_OBJECT(self)->type = GIS_TYPE_QUAD; - gis_point_set_xyz(&GIS_OBJECT(self)->center, - (a->x + b->x + c->x + d->x)/4, - (a->y + b->y + c->y + d->y)/4, - (a->z + b->z + c->z + d->z)/4); - self->verts[0] = gis_point_ref(a); - self->verts[1] = gis_point_ref(b); - self->verts[2] = gis_point_ref(c); - self->verts[3] = gis_point_ref(d); - self->tex = tex; - return self; -} - -void gis_quad_free(GisQuad *self) -{ - gis_point_unref(self->verts[0]); - gis_point_unref(self->verts[1]); - gis_point_unref(self->verts[2]); - gis_point_unref(self->verts[3]); g_free(self); } -/* GisCallback */ -GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data) -{ - GisCallback *self = g_new0(GisCallback, 1); - GIS_OBJECT(self)->type = GIS_TYPE_CALLBACK; - self->callback = callback; - self->user_data = user_data; - return self; -} - -void gis_callback_free(GisCallback *self) -{ - g_free(self); -} - - -/* GisCallback */ +/* GisMarker */ GisMarker *gis_marker_new(const gchar *label) { static const int RADIUS = 4; @@ -172,3 +70,19 @@ void gis_marker_free(GisMarker *self) g_free(self->label); g_free(self); } + + +/* GisCallback */ +GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data) +{ + GisCallback *self = g_new0(GisCallback, 1); + GIS_OBJECT(self)->type = GIS_TYPE_CALLBACK; + self->callback = callback; + self->user_data = user_data; + return self; +} + +void gis_callback_free(GisCallback *self) +{ + g_free(self); +} diff --git a/src/gis-object.h b/src/gis-object.h index a58b815..9fc0ba7 100644 --- a/src/gis-object.h +++ b/src/gis-object.h @@ -21,83 +21,46 @@ #include #include -/* Base types */ -typedef struct _GisProjection GisProjection; +/* GisPoint */ typedef struct _GisPoint GisPoint; -struct _GisProjection { - gdouble model[16]; - gdouble proj[16]; - gint view[4]; -}; struct _GisPoint { - union { - gdouble lle[3]; - struct { gdouble lat, lon, elev; }; - }; - union { - gdouble xyz[3]; - struct { gdouble x, y, z; }; - }; - union { - gdouble proj[3]; - struct { gdouble px, py, pz; }; - }; - union { - gdouble norm[3]; - struct { gdouble nx, ny, nz; }; - }; - union { - gdouble coords[2]; - struct { gdouble cx, cy, xz; }; - }; - gint refs; + gdouble lat, lon, elev; }; -/* Objects */ +GisPoint *gis_point_new(); +void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev); +void gis_point_free(GisPoint *point); + + +/* GisObject */ #define GIS_OBJECT(object) ((GisObject *)object) -#define GIS_TRIANGLE(triangle) ((GisTriangle*)triangle) -#define GIS_QUAD(quad) ((GisQuad *)quad) -#define GIS_CALLBACK(callback) ((GisCallback*)callback) -#define GIS_MARKER(marker) ((GisMarker *)marker) typedef enum { - GIS_TYPE_TRIANGLE, - GIS_TYPE_QUAD, GIS_TYPE_CALLBACK, GIS_TYPE_MARKER, GIS_NUM_TYPES, } GisObjectType; -typedef struct _GisObject GisObject; -typedef struct _GisTriangle GisTriangle; -typedef struct _GisQuad GisQuad; -typedef struct _GisCallback GisCallback; -typedef struct _GisMarker GisMarker; - -typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data); +typedef struct _GisObject GisObject; struct _GisObject { - GisObjectType type; - GisPoint center; - GisProjection *proj; - gdouble lod; -}; -struct _GisTriangle { - GisObject parent; - GisPoint *verts[3]; - guint tex; -}; -struct _GisQuad { - GisObject parent; - GisPoint *verts[4]; - guint tex; -}; -struct _GisCallback { - GisObject parent; - GisCallbackFunc callback; - gpointer user_data; + GisObjectType type; + GisPoint center; + gdouble lod; }; + +static inline GisPoint *gis_object_center(GisObject *object) +{ + return &GIS_OBJECT(object)->center; +} + + +/* GisMarker */ +#define GIS_MARKER(marker) ((GisMarker *)marker) + +typedef struct _GisMarker GisMarker; + struct _GisMarker { GisObject parent; gint xoff, yoff; @@ -106,28 +69,24 @@ struct _GisMarker { guint tex; }; -/* Support functions */ -#define gis_object_center(object) \ - (&GIS_OBJECT(object)->center) +GisMarker *gis_marker_new(const gchar *label); +void gis_marker_free(GisMarker *marker); -GisPoint *gis_point_new(); -void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev); -void gis_point_set_xyz(GisPoint *point, gdouble x, gdouble y, gdouble z); -void gis_point_set_coords(GisPoint *point, gdouble x, gdouble y); -void gis_point_project(GisPoint *point, GisProjection *proj); -GisPoint *gis_point_ref(GisPoint *point); -void gis_point_unref(GisPoint *point); -GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex); -void gis_triangle_free(GisTriangle *tri); +/* GisCallback */ +#define GIS_CALLBACK(callback) ((GisCallback*)callback) -GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex); -void gis_quad_free(GisQuad *quad); +typedef struct _GisCallback GisCallback; +typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data); + +struct _GisCallback { + GisObject parent; + GisCallbackFunc callback; + gpointer user_data; +}; GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data); void gis_callback_free(GisCallback *cb); -GisMarker *gis_marker_new(const gchar *label); -void gis_marker_free(GisMarker *marker); #endif diff --git a/src/gis-opengl.c b/src/gis-opengl.c index 0bcde3d..b1886c2 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -65,9 +65,11 @@ static void _gis_opengl_end(GisOpenGL *self) ********************/ static void _draw_marker(GisOpenGL *self, GisMarker *marker) { - GisProjection *proj = (GisProjection*)self->sphere->view; - GisPoint *point = gis_object_center(marker); - gis_point_project(point, proj); + GisPoint *point = gis_object_center(GIS_OBJECT(marker)); + gdouble px, py, pz; + gis_viewer_project(GIS_VIEWER(self), + point->lat, point->lon, point->elev, + &px, &py, &pz); g_debug("GisOpenGL: draw_marker - texture=%d", marker->tex); @@ -79,8 +81,8 @@ static void _draw_marker(GisOpenGL *self, GisMarker *marker) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glOrtho(0, GTK_WIDGET(self)->allocation.width, 0, GTK_WIDGET(self)->allocation.height, -1, 1); - glTranslated(gis_object_center(marker)->px - marker->xoff, - gis_object_center(marker)->py - marker->yoff, 0); + glTranslated(px - marker->xoff, + py - marker->yoff, 0); glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); diff --git a/src/plugins/test.c b/src/plugins/test.c index 5be0fd7..5094758 100644 --- a/src/plugins/test.c +++ b/src/plugins/test.c @@ -33,7 +33,7 @@ GisPluginTest *gis_plugin_test_new(GisViewer *viewer) self->viewer = viewer; GisMarker *marker = gis_marker_new("St. Charles"); - gis_point_set_lle(gis_object_center(marker), 38.841847, -90.491982, 0); + gis_point_set_lle(gis_object_center(GIS_OBJECT(marker)), 38.841847, -90.491982, 0); gis_viewer_add(self->viewer, GIS_OBJECT(marker)); return self;