Date:2010-09-25 07:44:59 (13 years 5 months ago)
Author:Werner Almesberger
Commit:286a6bdd092f2f77ac37f7f23c1d462988366528
Message:Sanitize POV-Ray output (in progress)

- solidify/main.pov: set up a more traditional view than POV-Ray's "camera"
model
- solidify/main.pov: mark the coordinate axes with colored balls
- solidify/main.pov: make the part semi-transparent so that we can see the
coordinate axes
- solidify/solid.c (povray_face, povray): moved dumping a face from
povray() to povray_face()
- solidify/solid.c (povray_face): scale the height field to its real size
- solidify/solid.c (povray_face): rotate the face such that height is Z
- solidify/solid.c (povray_face): translate the face such that its center
is at the origin
Files: solidify/main.pov (1 diff)
solidify/solid.c (2 diffs)

Change Details

solidify/main.pov
11#include "colors.inc"
22#include "batcvr.inc"
33
4/*
5 * POV-Ray defaults to a "camera" coordinate system that can be confusing.
6 * We use a traditional mathematical/engineering view, with a view from
7 * X-/Y-/Z+ into the X/Y plane.
8 */
9
410camera {
5    location < 2, 2, 3>
6    look_at < 0, 0, 0>
11    location <-30, -80, 40>
12    look_at <20, 20, 0>
13    sky z
14    right -4/3*x
715}
816
917background { color White }
1018
1119light_source {
12    < 4, 7, 4>
20    <-200, -300, 200>
1321    color White
1422}
1523
24/*
25 * Mark the coordinate axes:
26 * - a red unit sphere at the center
27 * - three green spheres at x = 10*i
28 * - two blue spheres at y = 10*i
29 * - one yellow sphere at z = 10
30 */
31
32sphere { < 0, 0, 0>, 1 pigment { color Red } }
33sphere { <10, 0, 0>, 1 pigment { color Green } }
34sphere { <20, 0, 0>, 1 pigment { color Green } }
35sphere { <30, 0, 0>, 1 pigment { color Green } }
36sphere { < 0, 10, 0>, 1 pigment { color Blue } }
37sphere { < 0, 20, 0>, 1 pigment { color Blue } }
38sphere { < 0, 0, 10>, 1 pigment { color Yellow } }
39
40#declare Finish = finish {
41    brilliance 2
42    phong 0.8
43    phong_size 100
44    metallic
45}
46
1647union {
1748    Part_batcvr
18    pigment { rgb <0.9, 0.9, 0.9> }
19    finish {
20        brilliance 2
21        phong 0.8
22        phong_size 100
23        metallic
24    }
49    pigment { rgbf <0.9, 0.9, 0.9, 0.5> }
50    finish { Finish }
2551}
solidify/solid.c
6363}
6464
6565
66/*
67 * For now, we put the part such that its x/y/z center is at the origin.
68 * Later, we will also have to consider the changes the user made and the
69 * relation with the opposing face.
70 */
71
72static void povray_face(const struct face *f, const char *side,
73    const char *prefix)
74{
75    int sz = f->a->max_z-f->a->min_z;
76
77    /*
78     * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g.,
79     * to 0.0001
80     */
81    printf(
82"\theight_field {\n"
83"\t pgm \"%s-%s.pgm\"\n"
84"\t water_level 0.00001\n"
85"\t smooth\n"
86"\t scale <%g, %g, %g>\n"
87"\t rotate <90, 0, 0>\n"
88"\t translate <%g, %g, %g>\n"
89"\t}\n", prefix, side,
90    f->sx*f->x_step, sz*f->z_step, f->sy*f->y_step,
91    -f->sx*f->x_step/2, f->sy*f->y_step/2, -sz*f->z_step/2);
92}
93
94
6695void povray(const char *name, const struct solid *s)
6796{
6897    struct matrix m;
...... 
77106    sprintf(tmp, "%s-bot.pgm", name);
78107    height_field(tmp, s->b, &m);
79108
80    /*
81     * 1/65535 = 0.000015..., so we set the water level a bit lower, e.g.,
82     * to 0.0001
83     */
84109    sanitize(name, tmp);
85    printf(
86"#declare Part_%s =\n"
87" intersection {\n"
88" height_field { pgm \"%s-top.pgm\" water_level 0.00001 smooth }\n"
89" height_field { pgm \"%s-bot.pgm\" water_level 0.00001 smooth }\n"
90" }\n", tmp, name, name);
110    printf("#declare Part_%s =\n intersection {\n", tmp);
111    povray_face(s->a, "top", name);
112    povray_face(s->b, "bot", name);
113    printf(" }\n");
91114}

Archive Download the corresponding diff file

Branches:
master



interactive