Sort of fix panning when rotated
authorAndy Spencer <andy753421@gmail.com>
Mon, 8 Feb 2010 05:38:00 +0000 (05:38 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 8 Feb 2010 05:38:00 +0000 (05:38 +0000)
Use the current rotation to move the expected direction. This isn't
accurate because it uses lat-lon which aren't Cartesian coordinates.

src/gis-viewer.c
src/gis-viewer.h

index a4d7dc5..5b89a71 100644 (file)
@@ -211,13 +211,23 @@ void gis_viewer_get_location(GisViewer *self, gdouble *lat, gdouble *lon, gdoubl
        *elev = self->location[2];
 }
 
-void gis_viewer_pan(GisViewer *self, gdouble lat, gdouble lon, gdouble elev)
+void gis_viewer_pan(GisViewer *self, gdouble forward, gdouble sideways, gdouble up)
 {
        g_assert(GIS_IS_VIEWER(self));
-       g_debug("GisViewer: pan - lat=%8.3f, lon=%8.3f, elev=%8.3f", lat, lon, elev);
-       self->location[0] += lat;
-       self->location[1] += lon;
-       self->location[2] += elev;
+       g_debug("GisViewer: pan - forward=%8.3f, sideways=%8.3f, up=%8.3f",
+                       forward, sideways, up);
+       gdouble dist   = sqrt(forward*forward + sideways*sideways);
+       gdouble angle1 = deg2rad(self->rotation[2]);
+       gdouble angle2 = atan2(sideways, forward);
+       gdouble angle  = angle1 + angle2;
+       g_message("pan: dist=%f, angle=%f+%f=%f move=%f,%f",
+                       dist, angle1, angle2, angle,
+                       dist*cos(angle),
+                       dist*sin(angle));
+       /* This isn't accurate, but it's usable */
+       self->location[0] += dist*cos(angle);
+       self->location[1] += dist*sin(angle);
+       self->location[2] += up;
        _gis_viewer_fix_location(self);
        _gis_viewer_emit_location_changed(self);
 }
index c20cac8..ea07348 100644 (file)
@@ -92,8 +92,8 @@ gchar *gis_viewer_get_time(GisViewer *viewer);
 
 void gis_viewer_set_location(GisViewer *viewer, gdouble  lat, gdouble  lon, gdouble  elev);
 void gis_viewer_get_location(GisViewer *viewer, gdouble *lat, gdouble *lon, gdouble *elev);
-void gis_viewer_pan         (GisViewer *viewer, gdouble  lat, gdouble  lon, gdouble  elev);
-void gis_viewer_zoom        (GisViewer *viewer, gdouble  scale);
+void gis_viewer_pan(GisViewer *self, gdouble forward, gdouble sideways, gdouble up);
+void gis_viewer_zoom(GisViewer *viewer, gdouble  scale);
 
 void gis_viewer_set_rotation(GisViewer *viewer, gdouble  x, gdouble  y, gdouble  z);
 void gis_viewer_get_rotation(GisViewer *viewer, gdouble *x, gdouble *y, gdouble *z);