]> Pileus Git - grits/blob - src/gis-prims.h
Update example plugin
[grits] / src / gis-prims.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_PRIMITIVES_H__
19 #define __GIS_PRIMITIVES_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 /* Primitives */
57 #define GIS_PRIMITIVE(primitive) ((GisPrimitive*)primitive)
58 #define GIS_TRIANGLE (triangle ) ((GisTriangle *)triangel )
59 #define GIS_QUAD     (quad     ) ((GisQuad     *)quad     )
60 #define GIS_CALLBACK (callback ) ((GisCallback *)callback )
61
62 typedef struct _GisPrimitive GisPrimitive;
63 typedef struct _GisTriangle  GisTriangle;
64 typedef struct _GisQuad      GisQuad;
65 typedef struct _GisCallback  GisCallback;
66
67 typedef gpointer (*GisCallbackFunc)(GisCallback *callback, gpointer user_data);
68
69 struct _GisPrimitive {
70         GisPoint       center;
71         GisProjection *proj;
72 };
73 struct _GisTriangle {
74         GisPrimitive  parent;
75         GisPoint     *verts[3];
76         guint tex;
77 };
78 struct _GisQuad {
79         GisPrimitive  parent;
80         GisPoint     *verts[4];
81         guint tex;
82 };
83 struct _GisCallback {
84         GisPrimitive    parent;
85         GisCallbackFunc callback;
86         gpointer        user_data;
87 };
88
89 /* Support functions */
90 GisPoint *gis_point_new();
91 void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
92 void gis_point_set_xyz(GisPoint *point, gdouble x, gdouble y, gdouble z);
93 void gis_point_set_coords(GisPoint *point, gdouble x, gdouble y);
94 void gis_point_project(GisPoint *point, GisProjection *proj);
95 GisPoint *gis_point_ref(GisPoint *point);
96 void gis_point_unref(GisPoint *point);
97
98 GisTriangle *gis_triangle_new(GisPoint *a, GisPoint *b, GisPoint *c, guint tex);
99 void gis_triangle_free(GisTriangle *tri);
100
101 GisQuad *gis_quad_new(GisPoint *a, GisPoint *b, GisPoint *c, GisPoint *d, guint tex);
102 void gis_quad_free(GisQuad *quad);
103
104 GisCallback *gis_callback_new(GisCallbackFunc callback, gpointer user_data);
105 void gis_callback_free(GisCallback *cb);
106
107 #endif