diff --git a/solidify/main.pov b/solidify/main.pov index bf107e2..44b79e7 100644 --- a/solidify/main.pov +++ b/solidify/main.pov @@ -1,25 +1,51 @@ #include "colors.inc" #include "batcvr.inc" +/* + * POV-Ray defaults to a "camera" coordinate system that can be confusing. + * We use a traditional mathematical/engineering view, with a view from + * X-/Y-/Z+ into the X/Y plane. + */ + camera { - location < 2, 2, 3> - look_at < 0, 0, 0> + location <-30, -80, 40> + look_at <20, 20, 0> + sky z + right -4/3*x } background { color White } light_source { - < 4, 7, 4> + <-200, -300, 200> color White } +/* + * Mark the coordinate axes: + * - a red unit sphere at the center + * - three green spheres at x = 10*i + * - two blue spheres at y = 10*i + * - one yellow sphere at z = 10 + */ + +sphere { < 0, 0, 0>, 1 pigment { color Red } } +sphere { <10, 0, 0>, 1 pigment { color Green } } +sphere { <20, 0, 0>, 1 pigment { color Green } } +sphere { <30, 0, 0>, 1 pigment { color Green } } +sphere { < 0, 10, 0>, 1 pigment { color Blue } } +sphere { < 0, 20, 0>, 1 pigment { color Blue } } +sphere { < 0, 0, 10>, 1 pigment { color Yellow } } + +#declare Finish = finish { + brilliance 2 + phong 0.8 + phong_size 100 + metallic +} + union { Part_batcvr - pigment { rgb <0.9, 0.9, 0.9> } - finish { - brilliance 2 - phong 0.8 - phong_size 100 - metallic - } + pigment { rgbf <0.9, 0.9, 0.9, 0.5> } + finish { Finish } } diff --git a/solidify/solid.c b/solidify/solid.c index 90df6b5..535108c 100644 --- a/solidify/solid.c +++ b/solidify/solid.c @@ -63,6 +63,35 @@ static void sanitize(const char *s, char *res) } +/* + * For now, we put the part such that its x/y/z center is at the origin. + * Later, we will also have to consider the changes the user made and the + * relation with the opposing face. + */ + +static void povray_face(const struct face *f, const char *side, + const char *prefix) +{ + int sz = f->a->max_z-f->a->min_z; + + /* + * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g., + * to 0.0001 + */ + printf( +"\theight_field {\n" +"\t pgm \"%s-%s.pgm\"\n" +"\t water_level 0.00001\n" +"\t smooth\n" +"\t scale <%g, %g, %g>\n" +"\t rotate <90, 0, 0>\n" +"\t translate <%g, %g, %g>\n" +"\t}\n", prefix, side, + f->sx*f->x_step, sz*f->z_step, f->sy*f->y_step, + -f->sx*f->x_step/2, f->sy*f->y_step/2, -sz*f->z_step/2); +} + + void povray(const char *name, const struct solid *s) { struct matrix m; @@ -77,15 +106,9 @@ void povray(const char *name, const struct solid *s) sprintf(tmp, "%s-bot.pgm", name); height_field(tmp, s->b, &m); - /* - * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g., - * to 0.0001 - */ sanitize(name, tmp); - printf( -"#declare Part_%s =\n" -" intersection {\n" -" height_field { pgm \"%s-top.pgm\" water_level 0.00001 smooth }\n" -" height_field { pgm \"%s-bot.pgm\" water_level 0.00001 smooth }\n" -" }\n", tmp, name, name); + printf("#declare Part_%s =\n intersection {\n", tmp); + povray_face(s->a, "top", name); + povray_face(s->b, "bot", name); + printf(" }\n"); }