]> Pileus Git - grits/commitdiff
Add ortho flag to GritsMarker
authorAndy Spencer <andy753421@gmail.com>
Thu, 9 Feb 2012 09:20:58 +0000 (09:20 +0000)
committerAndy Spencer <andy753421@gmail.com>
Thu, 9 Feb 2012 09:35:46 +0000 (09:35 +0000)
Setting ortho to true causes the marker to be drawn orthographic and
flat against the screen. This is the default and behavior and is markers
have been drawn in the past.

Clearing the flag causes he marker to be drawn using the viewers
perspective projection but scaled to a fixed size.

src/objects/grits-marker.c
src/objects/grits-marker.h

index 148289cc9db43e3dc469618c31c41cca080ceaae..162e4bbdbac445fd7acf2a918dbc634399339c0a 100644 (file)
@@ -78,37 +78,9 @@ static void render_icon(GritsMarker *marker)
 {
        g_assert(marker->icon_img != NULL);
 
 {
        g_assert(marker->icon_img != NULL);
 
-       /* This code assumes the icon is an image pointing toward 0 degrees
-       * (ie. north/up).  If marker->flip is set, then it will rotate the
-       * icon appropriately then reflect it across the vertical axis so
-       * it's never upside down. */
-       gdouble flip = 1.0;
-       gdouble angle = marker->angle % 360;
-       if (marker->flip && (angle < 360 && angle > 180)) {
-               /* if icon rotates to the left half it will be upside down */
-               flip = -1.0; /* flip horizontally */
-       }
-
-       cairo_save(marker->cairo);
-
        /* move to marker location */
        cairo_translate(marker->cairo, marker->xoff, marker->yoff);
 
        /* move to marker location */
        cairo_translate(marker->cairo, marker->xoff, marker->yoff);
 
-       /* perform rotation and flip in one transformation */
-       gdouble C = cos(angle*(M_PI/180.0));
-       gdouble S = sin(angle*(M_PI/180.0));
-       gdouble fx = flip; 
-       gdouble fy = 1.0;
-       gdouble tx = 0.0;
-       gdouble ty = 0.0;
-       cairo_matrix_t matrix;
-       cairo_matrix_init(&matrix,
-               fx*C, fx*S,
-               -S*fy, C*fy,
-               C*tx*(1-fx)-S*ty*(fy-1)+tx-C*tx+S*ty,
-               S*tx*(1-fx)+C*ty*(fy-1)+ty-S*tx-C*ty);
-       cairo_transform(marker->cairo, &matrix);
-
        /* center image */
        cairo_translate(marker->cairo, -marker->icon_width/2,
                                       -marker->icon_height/2);
        /* center image */
        cairo_translate(marker->cairo, -marker->icon_width/2,
                                       -marker->icon_height/2);
@@ -116,7 +88,6 @@ static void render_icon(GritsMarker *marker)
        cairo_set_source_surface(marker->cairo, marker->icon_img, 0, 0);
 
        cairo_paint(marker->cairo);
        cairo_set_source_surface(marker->cairo, marker->icon_img, 0, 0);
 
        cairo_paint(marker->cairo);
-       cairo_restore(marker->cairo);
 }
 
 static void render_all(GritsMarker *marker)
 }
 
 static void render_all(GritsMarker *marker)
@@ -140,8 +111,8 @@ static void render_all(GritsMarker *marker)
        glTexImage2D(GL_TEXTURE_2D, 0, 4, marker->width, marker->height,
                0, GL_BGRA, GL_UNSIGNED_BYTE,
                cairo_image_surface_get_data(cairo_get_target(marker->cairo)));
        glTexImage2D(GL_TEXTURE_2D, 0, 4, marker->width, marker->height,
                0, GL_BGRA, GL_UNSIGNED_BYTE,
                cairo_image_surface_get_data(cairo_get_target(marker->cairo)));
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 }
 
 
 }
 
 
@@ -265,28 +236,46 @@ static void grits_marker_draw(GritsObject *_marker, GritsOpenGL *opengl)
 {
        GritsMarker *marker = GRITS_MARKER(_marker);
        GritsPoint  *point  = grits_object_center(marker);
 {
        GritsMarker *marker = GRITS_MARKER(_marker);
        GritsPoint  *point  = grits_object_center(marker);
-       gdouble px, py, pz;
-       grits_viewer_project(GRITS_VIEWER(opengl),
-                       point->lat, point->lon, point->elev,
-                       &px, &py, &pz);
-
-       gint win_width  = GTK_WIDGET(opengl)->allocation.width;
-       gint win_height = GTK_WIDGET(opengl)->allocation.height;
-       py = win_height - py;
-       if (pz > 1)
-               return;
-
-       //g_debug("GritsOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
 
        cairo_surface_t *surface = cairo_get_target(marker->cairo);
        gdouble width  = cairo_image_surface_get_width(surface);
        gdouble height = cairo_image_surface_get_height(surface);
 
 
        cairo_surface_t *surface = cairo_get_target(marker->cairo);
        gdouble width  = cairo_image_surface_get_width(surface);
        gdouble height = cairo_image_surface_get_height(surface);
 
-       glMatrixMode(GL_PROJECTION); glLoadIdentity();
-       glMatrixMode(GL_MODELVIEW);  glLoadIdentity();
-       glOrtho(0, win_width, win_height, 0, -1, 1);
-       glTranslated(px - marker->xoff,
-                    py - marker->yoff, 0);
+       if (marker->ortho) {
+               gdouble px, py, pz;
+               grits_viewer_project(GRITS_VIEWER(opengl),
+                               point->lat, point->lon, point->elev,
+                               &px, &py, &pz);
+
+               gint win_width  = GTK_WIDGET(opengl)->allocation.width;
+               gint win_height = GTK_WIDGET(opengl)->allocation.height;
+               if (pz > 1)
+                       return;
+
+               glMatrixMode(GL_PROJECTION); glLoadIdentity();
+               glMatrixMode(GL_MODELVIEW);  glLoadIdentity();
+               glOrtho(0, win_width, win_height, 0, 1, -1);
+               glTranslated(px, win_height-py, 0);
+               glRotatef(marker->angle, 0, 0, -1);
+               glTranslated(-marker->xoff, -marker->yoff, 0);
+       } else {
+               gdouble scale, eye[3], pos[3] =
+                       {point->lat, point->lon, point->elev};
+               grits_viewer_get_location(GRITS_VIEWER(opengl),
+                      &eye[0], &eye[1], &eye[2]);
+               lle2xyz(eye[0],  eye[1],  eye[2],
+                      &eye[0], &eye[1], &eye[2]);
+               lle2xyz(pos[0],  pos[1],  pos[2],
+                      &pos[0], &pos[1], &pos[2]);
+               scale = MPPX(distd(eye, pos));
+
+               glRotatef(marker->angle, 0, 0, -1);
+               glRotatef(180, 1, 0, 0);
+               glScalef(scale, scale, 1);
+               glTranslated(-marker->xoff, -marker->yoff, 0);
+       }
+
+       //g_debug("GritsOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
 
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
 
        glDisable(GL_LIGHTING);
        glDisable(GL_COLOR_MATERIAL);
@@ -295,10 +284,10 @@ static void grits_marker_draw(GritsObject *_marker, GritsOpenGL *opengl)
        glBindTexture(GL_TEXTURE_2D, marker->tex);
        glDisable(GL_CULL_FACE);
        glBegin(GL_QUADS);
        glBindTexture(GL_TEXTURE_2D, marker->tex);
        glDisable(GL_CULL_FACE);
        glBegin(GL_QUADS);
-       glTexCoord2f(1, 0); glVertex3f(width, 0     , 0);
-       glTexCoord2f(1, 1); glVertex3f(width, height, 0);
-       glTexCoord2f(0, 1); glVertex3f(0    , height, 0);
-       glTexCoord2f(0, 0); glVertex3f(0    , 0     , 0);
+       glTexCoord2f(1, 0); glVertex3f(width, 0     , 0); // 0 - 3    0 
+       glTexCoord2f(1, 1); glVertex3f(width, height, 0); // 1 - |    | 
+       glTexCoord2f(0, 1); glVertex3f(0    , height, 0); // 2 - |    | 
+       glTexCoord2f(0, 0); glVertex3f(0    , 0     , 0); // 3 - 2----1 
        glEnd();
 }
 
        glEnd();
 }
 
@@ -307,6 +296,7 @@ static void grits_marker_draw(GritsObject *_marker, GritsOpenGL *opengl)
 G_DEFINE_TYPE(GritsMarker, grits_marker, GRITS_TYPE_OBJECT);
 static void grits_marker_init(GritsMarker *marker)
 {
 G_DEFINE_TYPE(GritsMarker, grits_marker, GRITS_TYPE_OBJECT);
 static void grits_marker_init(GritsMarker *marker)
 {
+       marker->ortho = TRUE;
 }
 
 static void grits_marker_finalize(GObject *_marker)
 }
 
 static void grits_marker_finalize(GObject *_marker)
index 41a2f39b3e780001f6375496afce7258b99aab0e..0e44901754eb79abd9633ab4bc2d0d5b31a2043c 100644 (file)
@@ -48,6 +48,7 @@ struct _GritsMarker {
        gchar     *label;
        cairo_t   *cairo;
        guint      tex;
        gchar     *label;
        cairo_t   *cairo;
        guint      tex;
+       gboolean   ortho;
 
        cairo_surface_t *icon_img;
 
 
        cairo_surface_t *icon_img;