2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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.
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.
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/>.
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;
33 * @user_data: user data passed to the function
37 * Returns: the elevation
39 typedef gdouble (*RoamHeightFunc)(gdouble lat, gdouble lon, gpointer user_data);
44 * @model: model view matrix
45 * @proj: projection matrix
46 * @view: viewport matrix
49 * Stores projection matrices
64 * Points are used as vertices for triangles. A single point my be shared among
65 * several triangles in order to conceive space and avoid recalculating
66 * projections. Points also store a lot of cached data. The normal vertex normal
67 * is the averaged surface normal of each associated triangle.
71 gdouble x, y, z; /* Model coordinates */
72 gdouble px, py, pz; /* Projected coordinates */
73 gint pversion; /* Version of cached projection */
75 gint tris; /* Count of associated triangles */
76 gdouble norm[3]; /* Vertex normal */
78 /* For get_intersect */
79 gdouble lat, lon, elev;
82 RoamHeightFunc height_func;
85 RoamPoint *roam_point_new(double lat, double lon, double elev);
86 void roam_point_add_triangle(RoamPoint *point, RoamTriangle *triangle);
87 void roam_point_remove_triangle(RoamPoint *point, RoamTriangle *triangle);
88 void roam_point_update_height(RoamPoint *point);
89 void roam_point_update_projection(RoamPoint *point, RoamView *view);
97 * Triangles are one of the key datatypes in ROAM. The surface is made up of
98 * triangles. Each triangle has an associated "error". When the surface is being
99 * updated after the view changes, each triangles error is updated. Afterwards
100 * the triangles with the most error are split int to triangles, each with a
101 * lower error than the original.
103 * Triangles store a lot of data about their location in the mesh so that they
104 * can be split and merged (unsplit) without having to recreate the mesh.
106 struct _RoamTriangle {
108 /* Left, middle and right vertices */
109 struct { RoamPoint *l,*m,*r; } p;
111 /* Left, base, and right neighbor triangles */
112 struct { RoamTriangle *l,*b,*r; } t;
114 RoamPoint *split; /* Split point */
115 RoamDiamond *parent; /* Parent diamond */
116 double norm[3]; /* Surface normal */
117 double error; /* Screen space error */
118 GPQueueHandle handle;
120 /* For get_intersect */
121 struct { gdouble n,s,e,w; } edge;
122 RoamTriangle *kids[2];
124 RoamTriangle *roam_triangle_new(RoamPoint *l, RoamPoint *m, RoamPoint *r);
125 void roam_triangle_free(RoamTriangle *triangle);
126 void roam_triangle_add(RoamTriangle *triangle,
127 RoamTriangle *left, RoamTriangle *base, RoamTriangle *right,
129 void roam_triangle_remove(RoamTriangle *triangle, RoamSphere *sphere);
130 void roam_triangle_update_errors(RoamTriangle *triangle, RoamSphere *sphere);
131 void roam_triangle_split(RoamTriangle *triangle, RoamSphere *sphere);
132 void roam_triangle_draw(RoamTriangle *triangle);
133 void roam_triangle_draw_normal(RoamTriangle *triangle);
141 * When two adjacent triangles are split, they, along with the four new child
142 * triangles, are added to a diamond which keeps track of them.
144 * Like triangles, diamond have an error associated with it. However, when a
145 * diamonds error is small enough it is "merged". That is, the diamond along
146 * with the child triangles is removed and the original two triangles triangles
147 * are added back into the mesh.
149 struct _RoamDiamond {
151 RoamTriangle *kids[4]; /* Child triangles */
152 RoamTriangle *parents[2]; /* Parent triangles */
153 double error; /* Screen space error */
154 gboolean active; /* For internal use */
155 GPQueueHandle handle;
157 RoamDiamond *roam_diamond_new(
158 RoamTriangle *parent0, RoamTriangle *parent1,
159 RoamTriangle *kid0, RoamTriangle *kid1,
160 RoamTriangle *kid2, RoamTriangle *kid3);
161 void roam_diamond_add(RoamDiamond *diamond, RoamSphere *sphere);
162 void roam_diamond_remove(RoamDiamond *diamond, RoamSphere *sphere);
163 void roam_diamond_merge(RoamDiamond *diamond, RoamSphere *sphere);
164 void roam_diamond_update_errors(RoamDiamond *diamond, RoamSphere *sphere);
172 * The sphere keeps track of the triangles and diamonds in the mesh.
174 * Originally the sphere consists of only 8 triangles forming a octahedron.
175 * These triangles are quickly split to create a smoother sphere.
179 GPQueue *triangles; /* List of triangles */
180 GPQueue *diamonds; /* List of diamonds */
181 RoamView *view; /* Current projection */
182 gint polys; /* Polygon count */
184 /* For get_intersect */
185 RoamTriangle *roots[8]; /* Original 8 triangles */
187 RoamSphere *roam_sphere_new();
188 void roam_sphere_update_view(RoamSphere *sphere);
189 void roam_sphere_update_errors(RoamSphere *sphere);
190 void roam_sphere_split_one(RoamSphere *sphere);
191 void roam_sphere_merge_one(RoamSphere *sphere);
192 gint roam_sphere_split_merge(RoamSphere *sphere);
193 void roam_sphere_draw(RoamSphere *sphere);
194 void roam_sphere_draw_normals(RoamSphere *sphere);
195 GList *roam_sphere_get_intersect(RoamSphere *sphere, gboolean all,
196 gdouble n, gdouble s, gdouble e, gdouble w);
197 void roam_sphere_free(RoamSphere *sphere);