Date:2010-09-24 05:43:56 (8 years 8 months ago)
Author:Werner Almesberger
Commit:525e1557ec1a8e924b25a86c1efe61c93da21179
Message:Use two faces and show how they overlap (in progress)

- solidify/face.h (face_z0): calculate height of z0 plane
- solidify/level.c (draw_image): use face_z0 instead of open-coding the
calculation
- solidify/overlap.c (draw_image, point): moved per-point processing from
draw_image() to point()
- solidify/overlap.c (point): show differences between both faces
- solidify/solidify.c (usage, main): load both faces
- solidify/solidify.c (usage, main): accept distance between faces as third
argument
Files: solidify/face.h (1 diff)
solidify/level.c (1 diff)
solidify/overlap.c (2 diffs)
solidify/solidify.c (2 diffs)

Change Details

solidify/face.h
3838};
3939
4040
41static inline double face_z0(const struct face *f, int x, int y)
42{
43    return f->z_ref+f->fx*(x-f->sx/2)+f->fy*(y-f->sy/2);
44}
45
46
4147struct face *read_face(const char *name);
4248
4349#endif /* FACE_H */
solidify/level.c
4242                p += 3;
4343                continue;
4444            }
45            z0 = f->z_ref+f->fx*(x-f->sx/2)+f->fy*(y-f->sy/2);
45            z0 = face_z0(f, x, y);
4646            if (fabs(z-z0) < NEAR) {
4747                *p++ = 255*fabs(z-z0);
4848                *p++ = 255*fabs(z-z0);
solidify/overlap.c
7373}
7474
7575
76static void point(const struct solid *s, int x, int y, guchar *p)
77{
78    double za, zb, z;
79    int xa = x+s->a->a->min_x;
80    int ya = y+s->a->a->min_y;
81    int yb = sy(s)-1-y+s->a->a->min_y;
82
83    za = zmix(s->a,
84        xa*s->a->m.a[0][0]+ya*s->a->m.a[0][1]+s->a->m.b[0],
85        xa*s->a->m.a[1][0]+ya*s->a->m.a[1][1]+s->a->m.b[1]);
86
87    zb = zmix(s->b,
88        xa*s->b->m.a[0][0]+yb*s->b->m.a[0][1]+s->b->m.b[0],
89        xa*s->b->m.a[1][0]+yb*s->b->m.a[1][1]+s->b->m.b[1]);
90
91    if (za == UNDEF_F && zb == UNDEF_F)
92        return;
93
94    if (za == UNDEF_F) {
95        z = 128.0*(zb-s->b->a->min_z)/(s->b->a->max_z-s->b->a->min_z);
96        if (z < 0)
97            z = 0;
98        if (z > 255)
99            z = 255;
100        p[0] = 255;
101        p[1] = z;
102        p[2] = z;
103        return;
104    }
105    if (zb == UNDEF_F) {
106        z = 128.0*(za-s->a->a->min_z)/(s->a->a->max_z-s->a->a->min_z);
107        if (z < 0)
108            z = 0;
109        if (z > 255)
110            z = 255;
111        p[0] = z;
112        p[1] = 255;
113        p[2] = z;
114        return;
115    }
116
117    z = za;
118    za -= face_z0(s->a, xa, ya);
119    zb -= face_z0(s->b, xa, yb);
120
121    if (za+zb < -s->dist) {
122        p[0] = 0;
123        p[1] = 0;
124        p[2] = 255;
125        return;
126    }
127
128    z = 256.0*(z-s->a->a->min_z)/(s->a->a->max_z-s->a->a->min_z);
129    if (z < 0)
130        z = 0;
131    if (z > 255)
132        z = 255;
133    p[0] = z;
134    p[1] = z;
135    p[2] = z;
136}
137
138
76139static void draw_image(GtkWidget *widget, struct solid *s)
77140{
78141    guchar *rgbbuf, *p;
79142    int x, y;
80    double z;
81    struct face *f = s->a;
82143
83144    rgbbuf = p = calloc(sx(s)*sy(s), 3);
84145    if (!rgbbuf) {
...... 
87148    }
88149    for (y = sy(s)-1; y >= 0; y--)
89150        for (x = 0; x != sx(s) ; x++) {
90            int xa = x+f->a->min_x;
91            int ya = y+f->a->min_y;
92
93            z = zmix(f,
94                xa*f->m.a[0][0]+ya*f->m.a[0][1]+f->m.b[0],
95                xa*f->m.a[1][0]+ya*f->m.a[1][1]+f->m.b[1]);
96            if (z == UNDEF_F) {
97                p += 3;
98                continue;
99            }
100            z = 256.0*(z-f->a->min_z)/(f->a->max_z-f->a->min_z);
101            if (z < 0)
102                z = 0;
103            if (z > 255)
104                z = 255;
105            *p++ = z;
106            *p++ = z;
107            *p++ = z;
151            point(s, x, y, p);
152            p += 3;
108153        }
109154    gdk_draw_rgb_image(widget->window,
110155        widget->style->fg_gc[GTK_STATE_NORMAL],
solidify/solidify.c
115115
116116static void usage(const char *name)
117117{
118    fprintf(stderr, "usage: %s top XXXbottomXXX\n", name);
118    fprintf(stderr, "usage: %s top bottom dist\n", name);
119119    exit(1);
120120}
121121
...... 
124124{
125125    gtk_init(&argc, &argv);
126126    switch (argc) {
127    case 2:
127    case 4:
128128        break;
129129    default:
130130        usage(*argv);
131131    }
132132    setlocale(LC_ALL, "C"); /* damage control */
133133    solid.a = read_face(argv[1]);
134    solid.b = solid.a;
134    solid.b = read_face(argv[2]);
135    solid.dist = atof(argv[3])/0.025; /* @@@ hack */
135136    gui();
136137
137138    return 0;

Archive Download the corresponding diff file

Branches:
master



interactive