2 * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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/>.
21 #include "gis-marshal.h"
22 #include "gis-world.h"
25 double WGS884_SEMI_MAJOR = 6378137.0; // a
26 double WGS884_SEMI_MINOR = 6356752.314245; // b
27 double WGS884_INV_FLAT = 298.257223563; // 1/f
34 static guint signals[NUM_SIGNALS];
38 static void _gis_world_emit_refresh(GisWorld *world)
40 g_signal_emit(world, signals[SIG_REFRESH], 0);
42 static void _gis_world_emit_offline(GisWorld *world)
44 g_signal_emit(world, signals[SIG_OFFLINE], 0,
51 GisWorld *gis_world_new()
53 g_debug("GisWorld: new");
54 return g_object_new(GIS_TYPE_WORLD, NULL);
57 void gis_world_refresh(GisWorld *world)
59 g_debug("GisWorld: refresh");
60 _gis_world_emit_refresh(world);
63 void gis_world_set_offline(GisWorld *world, gboolean offline)
65 g_assert(GIS_IS_WORLD(world));
66 g_debug("GisWorld: set_offline - %d", offline);
67 world->offline = offline;
68 _gis_world_emit_offline(world);
71 gboolean gis_world_get_offline(GisWorld *world)
73 g_assert(GIS_IS_WORLD(world));
74 g_debug("GisWorld: get_offline - %d", world->offline);
75 return world->offline;
82 G_DEFINE_TYPE(GisWorld, gis_world, G_TYPE_OBJECT);
83 static void gis_world_init(GisWorld *self)
85 g_debug("GisWorld: init");
87 self->offline = FALSE;
89 static void gis_world_dispose(GObject *gobject)
91 g_debug("GisWorld: dispose");
92 /* Drop references to other GObjects */
93 G_OBJECT_CLASS(gis_world_parent_class)->dispose(gobject);
95 static void gis_world_finalize(GObject *gobject)
97 g_debug("GisWorld: finalize");
98 GisWorld *self = GIS_WORLD(gobject);
99 G_OBJECT_CLASS(gis_world_parent_class)->finalize(gobject);
101 static void gis_world_class_init(GisWorldClass *klass)
103 g_debug("GisWorld: class_init");
104 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
105 gobject_class->dispose = gis_world_dispose;
106 gobject_class->finalize = gis_world_finalize;
107 signals[SIG_REFRESH] = g_signal_new(
109 G_TYPE_FROM_CLASS(gobject_class),
114 g_cclosure_marshal_VOID__VOID,
117 signals[SIG_OFFLINE] = g_signal_new(
119 G_TYPE_FROM_CLASS(gobject_class),
124 g_cclosure_marshal_VOID__BOOLEAN,
134 void lle2xyz(gdouble lat, gdouble lon, gdouble elev,
135 gdouble *x, gdouble *y, gdouble *z)
137 gdouble rad = elev2rad(elev);
138 gdouble azim = lon2azim(lon);
139 gdouble incl = lat2incl(lat);
140 *z = rad * cos(azim) * sin(incl);
141 *x = rad * sin(azim) * sin(incl);
142 *y = rad * cos(incl);
145 void xyz2lle(gdouble x, gdouble y, gdouble z,
146 gdouble *lat, gdouble *lon, gdouble *elev)
148 gdouble rad = sqrt(x*x + y*y + z*z);
149 *lat = incl2lat(acos(y / rad));
150 *lon = azim2lon(atan2(x,z));
151 *elev = rad2elev(rad);
155 gdouble ll2m(gdouble lon_dist, gdouble lat)
157 gdouble azim = (-lat+90)/180*M_PI;
158 gdouble rad = sin(azim) * EARTH_R;
159 gdouble circ = 2 * M_PI * rad;
160 return lon_dist/360 * circ;
163 gdouble distd(gdouble *a, gdouble *b)
165 return sqrt((a[0]-b[0])*(a[0]-b[0]) +
166 (a[1]-b[1])*(a[1]-b[1]) +
167 (a[2]-b[2])*(a[2]-b[2]));