From 6ac06aab7c81d55c10c0a4f3411e3817c99ea39f Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 22 Sep 2010 19:20:29 -0300 Subject: [PATCH] Control inclination of the z0 plane. (Needs more work.) - solidify/face.h (struct face), solidify/face.c (read_face), solidify/level.c (draw_map, draw_image): introduce inclination of the z0 plane - solidify/level.c (draw_map): make blue z == z0 display more continuous - solidify/level.c (scroll_event): moved z0 shift to scroll_z - solidify/level.c (scroll_event, scroll_xy): added manipulation of the z0 plane's inclination --- solidify/face.c | 2 ++ solidify/face.h | 3 ++- solidify/level.c | 60 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/solidify/face.c b/solidify/face.c index d057ba6..8193005 100644 --- a/solidify/face.c +++ b/solidify/face.c @@ -58,6 +58,8 @@ struct face *read_face(const char *name) h = make_histo(f->a); f->z_ref = f->a->min_z+median(h); free_histo(h); + f->fx = f->fy = 0; + fprintf(stderr, "%d-%d / %d-%d / %d-%d\n", f->a->min_x, f->a->max_x, f->a->min_y, f->a->max_y, f->a->min_z, f->a->max_z); diff --git a/solidify/face.h b/solidify/face.h index 1ed5273..42d0708 100644 --- a/solidify/face.h +++ b/solidify/face.h @@ -6,8 +6,9 @@ struct face { struct array *a; - int sx, sy; + int sx, sy; /* size */ int z_ref; + double fx, fy; /* inclination factor */ }; diff --git a/solidify/level.c b/solidify/level.c index abfa40a..077fbce 100644 --- a/solidify/level.c +++ b/solidify/level.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "array.h" @@ -10,6 +11,7 @@ static void draw_map(GtkWidget *widget, struct face *f) { int x, y, z; + double z0; guchar *rgbbuf, *p; rgbbuf = p = calloc(f->sx*f->sy, 3); @@ -24,19 +26,20 @@ static void draw_map(GtkWidget *widget, struct face *f) p += 3; continue; } - if (z == f->z_ref) { - *p++ = 0; - *p++ = 0; + z0 = f->z_ref+f->fx*(x-f->sx/2)+f->fy*(y-f->sy/2); + if (fabs(z-z0) < 1) { + *p++ = 255*fabs(z-z0); + *p++ = 255*fabs(z-z0); *p++ = 255; continue; } - if (z < f->z_ref) { - z = 255.0*(z-f->z_ref)/(f->z_ref-f->a->min_z); + if (z < z0) { + z = 255.0*(z-z0)/(z0-f->a->min_z); *p++ = 255; *p++ = z; *p++ = z; } else { - z = 255.0*(f->z_ref-z)/(f->a->max_z-f->z_ref); + z = 255.0*(z0-z)/(f->a->max_z-z0); *p++ = z; *p++ = 255; *p++ = z; @@ -51,29 +54,56 @@ static void draw_map(GtkWidget *widget, struct face *f) static void draw_image(GtkWidget *da, struct face *f) { - fprintf(stderr, "%d\n", f->z_ref); + fprintf(stderr, "%d %g %g\n", f->z_ref, f->fx, f->fy); draw_map(da, f); } +static void scroll_z(GtkWidget *da, struct face *f, int up) +{ + if (up) { + if (f->z_ref < f->a->max_z) + f->z_ref++; + } else { + if (f->z_ref > f->a->min_z) + f->z_ref--; + } + draw_image(da, f); +} + + +static void scroll_xy(GtkWidget *da, struct face *f, int dx, int dy, int up) +{ + double d; + + d = (double) (up ? 1 : -1)/(dx*dx+dy*dy)/2.0; + f->fx += d*dx; + f->fy += d*dy; + draw_image(da, f); +} + + static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data) { GtkWidget *da = gtk_bin_get_child(GTK_BIN(widget)); struct face *f = data; + int dx = event->x-f->sx/2; + int dy = event->y-f->sy/2; + int center = hypot(dx, dy)/hypot(f->sx, f->sy) < 0.25; switch (event->direction) { case GDK_SCROLL_UP: - if (f->z_ref > f->a->min_z) { - f->z_ref--; - draw_image(da, f); - } + if (center) + scroll_z(da, f, 0); + else + scroll_xy(da, f, dx, dy, 1); break; case GDK_SCROLL_DOWN: - if (f->z_ref < f->a->max_z) { - f->z_ref++; - draw_image(da, f); - } + if (center) + scroll_z(da, f, 1); + else + scroll_xy(da, f, dx, dy, 0); break; default: /* ignore */;