]> Pileus Git - grits/blob - src/gis-object.h
Markers as individual textures
[grits] / src / gis-object.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GIS_OBJECT_H__
19 #define __GIS_OBJECT_H__
20
21 #include <glib.h>
22 #include <cairo.h>
23
24 /* Base types */
25 typedef struct _GisProjection GisProjection;
26 typedef struct _GisPoint      GisPoint;
27
28 struct _GisProjection {
29         gdouble model[16];
30         gdouble proj[16];
31         gint    view[4];
32 };
33 struct _GisPoint {
34         union {
35                 gdouble lle[3];
36                 struct { gdouble lat, lon, elev; };
37         };
38         union {
39                 gdouble xyz[3];
40                 struct { gdouble x, y, z; };
41         };
42         union {
43                 gdouble proj[3];
44                 struct { gdouble px, py, pz; };
45         };
46         union {
47                 gdouble norm[3];
48                 struct { gdouble nx, ny, nz; };
49         };
50         union {
51                 gdouble coords[2];
52                 struct { gdouble cx, cy, xz; };
53         };
54         gint refs;
55 };
56
57 /* Objects */
58 #define GIS_OBJECT(object)     ((GisObject  *)object)
59 #define GIS_TRIANGLE(triangle) ((GisTriangle*)triangle)
60 #define GIS_QUAD(quad)         ((GisQuad    *)quad)
61 #define GIS_CALLBACK(callback) ((GisCallback*)callback)
62 #define GIS_MARKER(marker)     ((GisMarker  *)marker)
63
64 typedef enum {
65         GIS_TYPE_TRIANGLE,
66         GIS_TYPE_QUAD,
67         GIS_TYPE_CALLBACK,
68         GIS_TYPE_MARKER,
69         GIS_NUM_TYPES,
70 } GisObjectType;
71
72 typedef struct _GisObject   GisObject;
73 typedef struct _GisTriangle GisTriangle;
74 typedef struct _GisQuad     GisQuad;
75 typedef struct _GisCallback GisCallback;
76 typedef struct _GisMarker   GisMarker;
77
78 typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
79
80 struct _GisObject {
81         GisObjectType  type;
82         GisPoint       center;
83         GisProjection *proj;
84         gdouble        lod;
85 };
86 struct _GisTriangle {
87         GisObject  parent;
88         GisPoint  *verts[3];
89         guint      tex;
90 };
91 struct _GisQuad {
92         GisObject  parent;
93         GisPoint  *verts[4];
94         guint     tex;
95 };
96 struct _GisCallback {
97         GisObject       parent;
98         GisCallbackFunc callback;
99         gpointer        user_data;
100 };
101 struct _GisMarker   {
102         GisObject  parent;
103         gint       xoff, yoff;
104         gchar     *label;
105         cairo_t   *cairo;
106         guint      tex;
107 };
108
109 /* Support functions */
110 #define gis_object_center(object) \
111         (&GIS_OBJECT(object)->center)
112
113 GisPoint *gis_point_new();
114 void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
115 void gis_point_set_xyz(GisPoint *point, gdouble x, gdouble y, gdouble z);
116 void gis_point_set_coords(GisPoint *point, gdouble x, gdouble y);
117 void gis_point_project(GisPoint *point, GisProjection *proj);
118 GisPoint *gis_point_ref(GisPoint *point);
119 void gis_point_unref(GisPoint *point);
120
121 GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex);
122 void gis_triangle_free(GisTriangle *tri);
123
124 GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex);
125 void gis_quad_free(GisQuad *quad);
126
127 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
128 void gis_callback_free(GisCallback *cb);
129
130 GisMarker *gis_marker_new(const gchar *label);
131 void gis_marker_free(GisMarker *marker);
132
133 #endif