]> Pileus Git - grits/blob - src/roam.h
Convert self to real names
[grits] / src / roam.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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 __ROAM_H__
19 #define __ROAM_H__
20
21 #include "gpqueue.h"
22
23 /* Roam */
24 typedef struct _RoamView     RoamView;
25 typedef struct _RoamPoint    RoamPoint;
26 typedef struct _RoamTriangle RoamTriangle;
27 typedef struct _RoamDiamond  RoamDiamond;
28 typedef struct _RoamSphere   RoamSphere;
29 typedef gdouble (*RoamHeightFunc)(gdouble lat, gdouble lon, gpointer user_data);
30
31 /* Misc */
32 struct _RoamView {
33         gdouble model[16];
34         gdouble proj[16];
35         gint view[4];
36         gint version;
37 };
38
39 /*************
40  * RoamPoint *
41  *************/
42 struct _RoamPoint {
43         gdouble  x,y,z;     // Model coordinates
44         gdouble  px,py,pz;  // Projected coordinates
45         gint     pversion;  // Version of cached projection
46
47         gint     tris;      // Associated triangles
48         gdouble  norm[3];   // Vertex normal
49
50         /* For get_intersect */
51         gdouble  lat, lon, elev;
52
53         /* For terrain */
54         RoamHeightFunc height_func;
55         gpointer       height_data;
56 };
57 RoamPoint *roam_point_new(double x, double y, double z);
58 void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle);
59 void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle);
60 void roam_point_update_height(RoamPoint *point);
61 void roam_point_update_projection(RoamPoint *point, RoamSphere *sphere);
62
63 /****************
64  * RoamTriangle *
65  ****************/
66 struct _RoamTriangle {
67         struct { RoamPoint    *l,*m,*r; } p;
68         struct { RoamTriangle *l,*b,*r; } t;
69         RoamPoint *split;
70         RoamDiamond *parent;
71         double norm[3];
72         double error;
73         GPQueueHandle handle;
74
75         /* For get_intersect */
76         struct { gdouble n,s,e,w; } edge;
77         RoamTriangle *kids[2];
78 };
79 RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r);
80 void roam_triangle_add(RoamTriangle *triangle,
81                 RoamTriangle *left, RoamTriangle *base, RoamTriangle *right,
82                 RoamSphere *sphere);
83 void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere);
84 void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere);
85 void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere);
86 void roam_triangle_draw_normal(RoamTriangle *triangle);
87
88 /***************
89  * RoamDiamond *
90  ***************/
91 struct _RoamDiamond {
92         RoamTriangle *kids[4];
93         RoamTriangle *parents[2];
94         double error;
95         gboolean active;
96         GPQueueHandle handle;
97 };
98 RoamDiamond *roam_diamond_new(
99                 RoamTriangle *parent0, RoamTriangle *parent1,
100                 RoamTriangle *kid0, RoamTriangle *kid1,
101                 RoamTriangle *kid2, RoamTriangle *kid3);
102 void roam_diamond_add(RoamDiamond *diamond, RoamSphere *sphere);
103 void roam_diamond_remove(RoamDiamond *diamond, RoamSphere *sphere);
104 void roam_diamond_merge(RoamDiamond *diamond, RoamSphere *sphere);
105 void roam_diamond_update_errors(RoamDiamond *diamond, RoamSphere *sphere);
106
107 /**************
108  * RoamSphere *
109  **************/
110 struct _RoamSphere {
111         GPQueue *triangles;
112         GPQueue *diamonds;
113         RoamView *view;
114         gint polys;
115
116         /* For get_intersect */
117         RoamTriangle *roots[8];
118 };
119 RoamSphere *roam_sphere_new();
120 void roam_sphere_update_view(RoamSphere *sphere);
121 void roam_sphere_update_errors(RoamSphere *sphere);
122 void roam_sphere_split_one(RoamSphere *sphere);
123 void roam_sphere_merge_one(RoamSphere *sphere);
124 gint roam_sphere_split_merge(RoamSphere *sphere);
125 void roam_sphere_draw(RoamSphere *sphere);
126 void roam_sphere_draw_normals(RoamSphere *sphere);
127 GList *roam_sphere_get_intersect(RoamSphere *sphere, gboolean all,
128                 gdouble n, gdouble s, gdouble e, gdouble w);
129 void roam_sphere_free(RoamSphere *sphere);
130
131 #endif