double width = GTK_WIDGET(opengl)->allocation.width;
double height = GTK_WIDGET(opengl)->allocation.height;
- double ang = atan(height/FOV_DIST);
+ double ang = atan((height/2)/FOV_DIST)*2;
double atmos = 100000;
double near = MAX(elev*0.75 - atmos, 50); // View 100km of atmosphere
double far = elev + 2*EARTH_R + atmos; // on both sides of the earth
grits_viewer_get_location(GRITS_VIEWER(opengl), &lat, &lon, &elev);
glViewport(0, 0, width, height);
- gluPerspective(rad2deg(ang)*2, width/height, near, far);
+ gluPerspective(rad2deg(ang), width/height, near, far);
/* Setup camera and lighting */
glMatrixMode(GL_MODELVIEW);
g_ptr_array_free(objects, TRUE);
g_mutex_unlock(opengl->objects_lock);
+ /* Test unproject */
+ gdouble lat, lon, elev;
+ grits_viewer_unproject(GRITS_VIEWER(opengl),
+ gl_x, gl_y, -1, &lat, &lon, &elev);
+
/* Cleanup */
glMatrixMode(GL_PROJECTION);
glPopMatrix();
px, py, pz);
}
+static void grits_opengl_unproject(GritsViewer *_opengl,
+ gdouble px, gdouble py, gdouble pz,
+ gdouble *lat, gdouble *lon, gdouble *elev)
+{
+ GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
+ gdouble x, y, z;
+ if (pz < 0) {
+ gfloat tmp = 0;
+ glReadPixels(px, py, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &tmp);
+ pz = tmp;
+ }
+ gluUnProject(px, py, pz,
+ opengl->sphere->view->model,
+ opengl->sphere->view->proj,
+ opengl->sphere->view->view,
+ &x, &y, &z);
+ xyz2lle(x, y, z, lat, lon, elev);
+ //g_message("GritsOpenGL: unproject - "
+ // "%4.0lf,%4.0lf,(%5.3lf) -> "
+ // "%8.0lf,%8.0lf,%8.0lf -> "
+ // "%6.2lf,%7.2lf,%4.0lf",
+ // px, py, pz, x, y, z, *lat, *lon, *elev);
+}
+
static void grits_opengl_set_height_func(GritsViewer *_opengl, GritsBounds *bounds,
RoamHeightFunc height_func, gpointer user_data, gboolean update)
{
GritsViewerClass *viewer_class = GRITS_VIEWER_CLASS(klass);
viewer_class->center_position = grits_opengl_center_position;
viewer_class->project = grits_opengl_project;
+ viewer_class->unproject = grits_opengl_unproject;
viewer_class->clear_height_func = grits_opengl_clear_height_func;
viewer_class->set_height_func = grits_opengl_set_height_func;
viewer_class->add = grits_opengl_add;