]> Pileus Git - grits/commitdiff
Add primitive rendering types
authorAndy Spencer <andy753421@gmail.com>
Sat, 14 Nov 2009 08:45:52 +0000 (08:45 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sat, 14 Nov 2009 08:45:52 +0000 (08:45 +0000)
These types are not full GObjects, hopefully they will be faster and
more space efficient this way since there will likely be a very large
number of these objects. However, the API is similar.

GisProjection:
  Stores camera parameters.

GisPoint:
  Corresponds to OpenGL Vertex.

GisPrimitive:
  Base class for primitive drawing objects.
    - Contains a centroid for depth sorting
    - Contains a projection so that xyz values for vertexes associated with the
      primitive points can be store relative to a projection.

GisTriangle:
  For GL_TRIANGLES

GisQuad:
  For GL_QUADS

GisCallback:
  Contains a callback and user_data pointer that is called when the object is
  to be rendered.

src/Makefile.am
src/gis-prims.c [new file with mode: 0644]
src/gis-prims.h [new file with mode: 0644]

index d82df9dc4b5dfea1e4a82719628df022d6003c95..b609d2f7edeb5048a7dfd4a2dceda49decd74aa0 100644 (file)
@@ -30,6 +30,7 @@ libgis_la_SOURCES = \
        gis-data.c    gis-data.h    \
        gis-tile.c    gis-tile.h    \
        gis-wms.c     gis-wms.h     \
+       gis-prims.c   gis-prims.h   \
        roam.c        roam.h        \
        gpqueue.c     gpqueue.h
 libgis_la_CPPFLAGS = $(AM_CPPFLAGS) \
diff --git a/src/gis-prims.c b/src/gis-prims.c
new file mode 100644 (file)
index 0000000..80d29cc
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib.h>
+#include <GL/glu.h>
+
+#include "gis-world.h"
+#include "gis-prims.h"
+
+/* TODO
+ *   - Manage normals for GisPoint
+ */
+
+/* GisPoint */
+GisPoint *gis_point_new()
+{
+       return g_new0(GisPoint, 1);
+}
+
+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)
+{
+       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_point_set_xyz(&GIS_PRIMITIVE(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_point_set_xyz(&GIS_PRIMITIVE(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);
+       self->callback  = callback;
+       self->user_data = user_data;
+       return self;
+}
+
+void gis_callback_free(GisCallback *self)
+{
+       g_free(self);
+}
diff --git a/src/gis-prims.h b/src/gis-prims.h
new file mode 100644 (file)
index 0000000..1317733
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIS_PRIMITIVES_H__
+#define __GIS_PRIMITIVES_H__
+
+#include <glib.h>
+
+/* Base types */
+typedef struct _GisProjection GisProjection;
+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;
+};
+
+/* Primitives */
+#define GIS_PRIMITIVE(primitive) ((GisPrimitive*)primitive)
+#define GIS_TRIANGLE (triangle ) ((GisTriangle *)triangel )
+#define GIS_QUAD     (quad     ) ((GisQuad     *)quad     )
+#define GIS_CALLBACK (callback ) ((GisCallback *)callback )
+
+typedef struct _GisPrimitive GisPrimitive;
+typedef struct _GisTriangle  GisTriangle;
+typedef struct _GisQuad      GisQuad;
+typedef struct _GisCallback  GisCallback;
+
+typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
+
+struct _GisPrimitive {
+       GisPoint       center;
+       GisProjection *proj;
+};
+struct _GisTriangle {
+       GisPrimitive  parent;
+       GisPoint     *verts[3];
+       guint tex;
+};
+struct _GisQuad {
+       GisPrimitive  parent;
+       GisPoint     *verts[4];
+       guint tex;
+};
+struct _GisCallback {
+       GisPrimitive    parent;
+       GisCallbackFunc callback;
+       gpointer        user_data;
+};
+
+/* Support functions */
+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);
+
+GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex);
+void gis_quad_free(GisQuad *quad);
+
+GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
+void gis_callback_free(GisCallback *cb);
+
+#endif