]> Pileus Git - grits/blobdiff - src/grits-viewer.c
Add grits_viewer_unproject function
[grits] / src / grits-viewer.c
index 7d857c48a1172ff7757e286d3d3b46fa9883d310..d9e28878dbcd53ed03c1875c59769186a776af50 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
+ * Copyright (C) 2009-2011 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -445,8 +445,8 @@ void grits_viewer_center_position(GritsViewer *viewer,
  * grits_viewer_project:
  * @viewer: the viewer
  * @lat:  the latitude
- * @lon:  the latitude
- * @elev: the latitude
+ * @lon:  the longitude
+ * @elev: the elevation
  * @px:   the project x coordinate
  * @py:   the project y coordinate
  * @pz:   the project z coordinate
@@ -465,6 +465,31 @@ void grits_viewer_project(GritsViewer *viewer,
        klass->project(viewer, lat, lon, elev, px, py, pz);
 }
 
+/**
+ * grits_viewer_unproject:
+ * @viewer: the viewer
+ * @x:    x coordinate in screen space
+ * @y:    y coordinate in screen space
+ * @z:    z coordinate in screen space, or -1 to use the value
+ *        from the depth buffer at x and y as the z value
+ * @lat:  the latitude
+ * @lon:  the longitude
+ * @elev: the elevation
+ *
+ * Project a x, y point in screen space to a latitude, longitude, and elevation
+ * point. Useful for finding the position of the cursor or another on-screen
+ * object in world coordinates.
+ */
+void grits_viewer_unproject(GritsViewer *viewer,
+               gdouble px, gdouble py, gdouble pz,
+               gdouble *lat, gdouble *lon, gdouble *elev)
+{
+       GritsViewerClass *klass = GRITS_VIEWER_GET_CLASS(viewer);
+       if (!klass->unproject)
+               g_warning("GritsViewer: unproject - Unimplemented");
+       klass->unproject(viewer, px, py, pz, lat, lon, elev);
+}
+
 /**
  * grits_viewer_clear_height_func:
  * @viewer: the viewer
@@ -542,15 +567,12 @@ gpointer grits_viewer_add(GritsViewer *viewer, GritsObject *object,
  *
  * Returns: the #GritsObject referenced by the handle
  */
-GritsObject *grits_viewer_remove(GritsViewer *viewer, gpointer _object)
+GritsObject *grits_viewer_remove(GritsViewer *viewer, GritsObject *object)
 {
-       GritsObject *object = _object;
        GritsViewerClass *klass = GRITS_VIEWER_GET_CLASS(viewer);
        if (!klass->remove)
                g_warning("GritsViewer: remove - Unimplemented");
-       klass->remove(viewer, object->ref);
-       object->ref    = NULL;
-       object->viewer = NULL;
+       klass->remove(viewer, object);
        return object;
 }