]> Pileus Git - grits/blob - src/gis-object.h
Add support for GisMarker to Gis{Viewer,OpenGL}
[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
23 /* Base types */
24 typedef struct _GisProjection GisProjection;
25 typedef struct _GisPoint      GisPoint;
26
27 struct _GisProjection {
28         gdouble model[16];
29         gdouble proj[16];
30         gint    view[4];
31 };
32 struct _GisPoint {
33         union {
34                 gdouble lle[3];
35                 struct { gdouble lat, lon, elev; };
36         };
37         union {
38                 gdouble xyz[3];
39                 struct { gdouble x, y, z; };
40         };
41         union {
42                 gdouble proj[3];
43                 struct { gdouble px, py, pz; };
44         };
45         union {
46                 gdouble norm[3];
47                 struct { gdouble nx, ny, nz; };
48         };
49         union {
50                 gdouble coords[2];
51                 struct { gdouble cx, cy, xz; };
52         };
53         gint refs;
54 };
55
56 /* Objects */
57 #define GIS_OBJECT(object)     ((GisObject  *)object)
58 #define GIS_TRIANGLE(triangle) ((GisTriangle*)triangle)
59 #define GIS_QUAD(quad)         ((GisQuad    *)quad)
60 #define GIS_CALLBACK(callback) ((GisCallback*)callback)
61 #define GIS_MARKER(marker)     ((GisMarker  *)marker)
62
63 typedef enum {
64         GIS_TYPE_TRIANGLE,
65         GIS_TYPE_QUAD,
66         GIS_TYPE_CALLBACK,
67         GIS_TYPE_MARKER,
68         GIS_NUM_TYPES,
69 } GisObjectType;
70
71 typedef struct _GisObject   GisObject;
72 typedef struct _GisTriangle GisTriangle;
73 typedef struct _GisQuad     GisQuad;
74 typedef struct _GisCallback GisCallback;
75 typedef struct _GisMarker   GisMarker;
76
77 typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
78
79 struct _GisObject {
80         GisObjectType  type;
81         GisPoint       center;
82         GisProjection *proj;
83         gdouble        lod;
84 };
85 struct _GisTriangle {
86         GisObject  parent;
87         GisPoint  *verts[3];
88         guint      tex;
89 };
90 struct _GisQuad {
91         GisObject  parent;
92         GisPoint  *verts[4];
93         guint     tex;
94 };
95 struct _GisCallback {
96         GisObject       parent;
97         GisCallbackFunc callback;
98         gpointer        user_data;
99 };
100 struct _GisMarker   {
101         GisObject  parent;
102         gchar     *label;
103 };
104
105 /* Support functions */
106 #define gis_object_center(object) \
107         (&GIS_OBJECT(object)->center)
108
109 GisPoint *gis_point_new();
110 void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
111 void gis_point_set_xyz(GisPoint *point, gdouble x, gdouble y, gdouble z);
112 void gis_point_set_coords(GisPoint *point, gdouble x, gdouble y);
113 void gis_point_project(GisPoint *point, GisProjection *proj);
114 GisPoint *gis_point_ref(GisPoint *point);
115 void gis_point_unref(GisPoint *point);
116
117 GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex);
118 void gis_triangle_free(GisTriangle *tri);
119
120 GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex);
121 void gis_quad_free(GisQuad *quad);
122
123 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
124 void gis_callback_free(GisCallback *cb);
125
126 GisMarker *gis_marker_new(const gchar *label);
127 void gis_marker_free(GisMarker *marker);
128
129 #endif