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/>.
19 * SECTION:grits-object
20 * @short_description: Base class for drawing operations
22 * Objects in grits are things which can be added to the viewer and will be
23 * displayed to the user. Each object has information such as it's location and
24 * level of detail which are used by the viewer to determine which objects
27 * Each #GritsObject is also a #GObject, but not every GObject in grits is a
28 * GritsObject. The "Object" part of the name is just coincidence.
35 #include "grits-object.h"
41 * @opengl: the viewer the object is being displayed in
43 * Perform any OpenGL commands necessasairy to draw the object.
45 * The GL_PROJECTION and GL_MODELVIEW matricies and GL_ALL_ATTRIB_BITS will be
46 * restored to the default state after the call to draw.
48 void grits_object_draw(GritsObject *object, GritsOpenGL *opengl)
50 GritsObjectClass *klass = GRITS_OBJECT_GET_CLASS(object);
52 g_warning("GritsObject: draw - Unimplemented");
56 /* Skip hidden objects */
60 /* Skip out of range objects */
61 if (object->lod > 0) {
63 gdouble eye[3], obj[3];
64 grits_viewer_get_location(GRITS_VIEWER(opengl), &eye[0], &eye[1], &eye[2]);
65 gdouble elev = eye[2];
66 lle2xyz(eye[0], eye[1], eye[2], &eye[0], &eye[1], &eye[2]);
67 lle2xyz(object->center.lat, object->center.lon, object->center.elev,
68 &obj[0], &obj[1], &obj[2]);
69 gdouble dist = distd(obj, eye);
70 if (object->lod < dist)
74 gdouble c = EARTH_R+elev;
76 gdouble horizon = sqrt(c*c - a*a);
81 /* Save state, draw, restore state */
82 g_mutex_lock(opengl->sphere_lock);
83 glPushAttrib(GL_ALL_ATTRIB_BITS);
84 glMatrixMode(GL_PROJECTION); glPushMatrix();
85 glMatrixMode(GL_MODELVIEW); glPushMatrix();
87 klass->draw(object, opengl);
90 glMatrixMode(GL_PROJECTION); glPopMatrix();
91 glMatrixMode(GL_MODELVIEW); glPopMatrix();
92 g_mutex_unlock(opengl->sphere_lock);
95 void grits_object_queue_draw(GritsObject *object)
98 gtk_widget_queue_draw(GTK_WIDGET(object->viewer));
102 G_DEFINE_ABSTRACT_TYPE(GritsObject, grits_object, G_TYPE_OBJECT);
103 static void grits_object_init(GritsObject *object)
107 static void grits_object_class_init(GritsObjectClass *klass)