ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/gen/genbox.c
(Generate patch)

Comparing ray/src/gen/genbox.c (file contents):
Revision 2.1 by greg, Tue Nov 12 17:04:38 1991 UTC vs.
Revision 2.10 by greg, Thu Apr 8 15:13:08 2021 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  genbox.c - generate a parallelepiped.
6   *
7   *     1/8/86
8   */
9  
10 < #include  <stdio.h>
10 > #include  "rtio.h"
11 > #include  <stdlib.h>
12 > #include  <math.h>
13  
14  
15   char  let[]="0123456789._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
# Line 23 | Line 22 | double  size[3];       /* ppd size */
22  
23   double  bevel = 0.0;    /* bevel amount */
24  
25 < int  round = 0;         /* boolean true for round edges */
25 > int  rounde = 0;        /* boolean true for round edges */
26  
27   int  reverse = 0;       /* boolean true for reversed normals */
28  
29  
30 < main(argc, argv)
31 < int  argc;
33 < char  **argv;
30 > static void
31 > vertex(int v)
32   {
35        double  atof();
33          int  i;
34 +
35 +        for (i = 0; i < 3; i++) {
36 +                if (v & 010)
37 +                        printf("\t%18.12g", (v&01)^reverse ? size[i]-bevel : bevel);
38 +                else
39 +                        printf("\t%18.12g", (v&01)^reverse ? size[i] : 0.0);
40 +                v >>= 1;
41 +        }
42 +        fputc('\n', stdout);
43 + }
44 +
45 +
46 + static void
47 + side(int a, int b, int c, int d)                /* generate a rectangular face */
48 + {
49 +        printf("\n%s polygon %s.%c%c%c%c\n", cmtype, cname,
50 +                        let[a], let[b], let[c], let[d]);
51 +        printf("0\n0\n12\n");
52 +        vertex(a);
53 +        vertex(b);
54 +        vertex(c);
55 +        vertex(d);
56 + }
57 +
58 +
59 + static void
60 + corner(int a, int b, int c)                     /* generate a triangular face */
61 + {
62 +        printf("\n%s polygon %s.%c%c%c\n", cmtype, cname,
63 +                        let[a], let[b], let[c]);
64 +        printf("0\n0\n9\n");
65 +        vertex(a);
66 +        vertex(b);
67 +        vertex(c);
68 + }
69 +
70 +
71 + static void
72 + cylinder(int v0, int v1)                /* generate a cylinder */
73 + {
74 +        printf("\n%s cylinder %s.%c%c\n", cmtype, cname, v0+'0', v1+'0');
75 +        printf("0\n0\n7\n");
76 +        vertex(v0);
77 +        vertex(v1);
78 +        printf("\t%18.12g\n", bevel);
79 + }
80 +
81 +
82 + static void
83 + sphere(int v0)                  /* generate a sphere */
84 + {
85 +        printf("\n%s sphere %s.%c\n", cmtype, cname, v0+'0');
86 +        printf("0\n0\n4\n");
87 +        vertex(v0);
88 +        printf("\t%18.12g\n", bevel);
89 + }
90 +
91 +
92 + int
93 + main(int argc, char *argv[])
94 + {
95 +        int  i;
96          
97          if (argc < 6)
98                  goto userr;
# Line 43 | Line 102 | char  **argv;
102          size[0] = atof(argv[3]);
103          size[1] = atof(argv[4]);
104          size[2] = atof(argv[5]);
105 +        if ((size[0] <= 0.0) | (size[1] <= 0.0) | (size[2] <= 0.0))
106 +                goto userr;
107  
108          for (i = 6; i < argc; i++) {
109                  if (argv[i][0] != '-')
110                          goto userr;
111                  switch (argv[i][1]) {
112 +                case 'i':
113 +                        reverse = 1;
114 +                        break;
115                  case 'r':
116 <                        round = 1;
116 >                        rounde = 1;
117                          /* fall through */
118                  case 'b':
119                          bevel = atof(argv[++i]);
120 <                        break;
121 <                case 'i':
122 <                        reverse = 1;
59 <                        break;
120 >                        if (bevel > 0.0)
121 >                                break;
122 >                        /* fall through on error */
123                  default:
124                          goto userr;
125                  }
126          }
127 +        if (rounde & reverse)
128 +                fprintf(stderr, "%s: warning - option -i ignored with -r\n",
129 +                                argv[0]);
130  
131 <        printhead(argc, argv);
131 >        fputs("# ", stdout);
132 >        printargs(argc, argv, stdout);
133  
134          if (bevel > 0.0) {
135                                          /* minor faces */
# Line 73 | Line 140 | char  **argv;
140                  side(065, 061, 063, 067);
141                  side(036, 034, 035, 037);
142          }
143 <        if (bevel > 0.0 && !round) {
143 >        if (bevel > 0.0 && !rounde) {
144                                          /* bevel faces */
145                  side(031, 051, 050, 030);
146                  side(060, 062, 032, 030);
# Line 97 | Line 164 | char  **argv;
164                  corner(053, 063, 033);
165                  corner(037, 067, 057);
166          }
167 <        if (bevel > 0.0 && round) {
167 >        if (bevel > 0.0 && rounde) {
168                                          /* round edges */
169                  cylinder(070, 071);
170                  cylinder(070, 074);
# Line 121 | Line 188 | char  **argv;
188                  sphere(076);
189                  sphere(077);
190          }
191 <        if (bevel == 0.0 ) {
191 >        if (bevel == 0.0) {
192                                          /* only need major faces */
193                  side(1, 5, 4, 0);
194                  side(4, 6, 2, 0);
# Line 130 | Line 197 | char  **argv;
197                  side(5, 1, 3, 7);
198                  side(6, 4, 5, 7);
199          }
200 <        exit(0);
200 >        return(0);
201   userr:
202          fprintf(stderr, "Usage: %s ", argv[0]);
203          fprintf(stderr, "material name xsize ysize zsize ");
204          fprintf(stderr, "[-i] [-b bevel | -r round]\n");
205 <        exit(1);
139 < }
140 <
141 <
142 < side(a, b, c, d)                /* generate a rectangular face */
143 < int  a, b, c, d;
144 < {
145 <        printf("\n%s polygon %s.%c%c%c%c\n", cmtype, cname,
146 <                        let[a], let[b], let[c], let[d]);
147 <        printf("0\n0\n12\n");
148 <        if (reverse) {
149 <                vertex(d);
150 <                vertex(c);
151 <                vertex(b);
152 <                vertex(a);
153 <        } else {
154 <                vertex(a);
155 <                vertex(b);
156 <                vertex(c);
157 <                vertex(d);
158 <        }
159 < }
160 <
161 <
162 < corner(a, b, c)                 /* generate a triangular face */
163 < int  a, b, c;
164 < {
165 <        printf("\n%s polygon %s.%c%c%c\n", cmtype, cname,
166 <                        let[a], let[b], let[c]);
167 <        printf("0\n0\n9\n");
168 <        if (reverse) {
169 <                vertex(c);
170 <                vertex(b);
171 <                vertex(a);
172 <        } else {
173 <                vertex(a);
174 <                vertex(b);
175 <                vertex(c);
176 <        }
177 < }
178 <
179 <
180 < cylinder(v0, v1)                /* generate a cylinder */
181 < int  v0, v1;
182 < {
183 <        printf("\n%s cylinder %s.%c%c\n", cmtype, cname, v0+'0', v1+'0');
184 <        printf("0\n0\n7\n");
185 <        vertex(v0);
186 <        vertex(v1);
187 <        printf("\t%18.12g\n", bevel);
188 < }
189 <
190 <
191 < sphere(v0)                      /* generate a sphere */
192 < int  v0;
193 < {
194 <        printf("\n%s sphere %s.%c\n", cmtype, cname, v0+'0');
195 <        printf("0\n0\n4\n");
196 <        vertex(v0);
197 <        printf("\t%18.12g\n", bevel);
198 < }
199 <
200 <
201 < vertex(v)
202 < register int  v;
203 < {
204 <        register int  i;
205 <
206 <        for (i = 0; i < 3; i++) {
207 <                if (v & 010)
208 <                        printf("\t%18.12g", v & 01 ? size[i]-bevel : bevel);
209 <                else
210 <                        printf("\t%18.12g", v & 01 ? size[i] : 0.0);
211 <                v >>= 1;
212 <        }
213 <        printf("\n");
214 < }
215 <
216 <
217 < printhead(ac, av)               /* print command header */
218 < register int  ac;
219 < register char  **av;
220 < {
221 <        putchar('#');
222 <        while (ac--) {
223 <                putchar(' ');
224 <                fputs(*av++, stdout);
225 <        }
226 <        putchar('\n');
205 >        return(1);
206   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines