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.4 by greg, Mon Aug 2 14:22:59 1993 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>
11 <
10 > #include  "rtio.h"
11 > #include  <stdlib.h>
12   #include  <math.h>
13  
14  
18 #ifdef  DCL_ATOF
19 extern double  atof();
20 #endif
21
15   char  let[]="0123456789._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
16  
17   char  *cmtype;          /* ppd material type */
# Line 29 | 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;
39 < char  **argv;
30 > static void
31 > vertex(int v)
32   {
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 48 | 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;
64 <                        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 78 | 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 102 | 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 126 | 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 135 | 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);
144 < }
145 <
146 <
147 < side(a, b, c, d)                /* generate a rectangular face */
148 < int  a, b, c, d;
149 < {
150 <        printf("\n%s polygon %s.%c%c%c%c\n", cmtype, cname,
151 <                        let[a], let[b], let[c], let[d]);
152 <        printf("0\n0\n12\n");
153 <        if (reverse) {
154 <                vertex(d);
155 <                vertex(c);
156 <                vertex(b);
157 <                vertex(a);
158 <        } else {
159 <                vertex(a);
160 <                vertex(b);
161 <                vertex(c);
162 <                vertex(d);
163 <        }
164 < }
165 <
166 <
167 < corner(a, b, c)                 /* generate a triangular face */
168 < int  a, b, c;
169 < {
170 <        printf("\n%s polygon %s.%c%c%c\n", cmtype, cname,
171 <                        let[a], let[b], let[c]);
172 <        printf("0\n0\n9\n");
173 <        if (reverse) {
174 <                vertex(c);
175 <                vertex(b);
176 <                vertex(a);
177 <        } else {
178 <                vertex(a);
179 <                vertex(b);
180 <                vertex(c);
181 <        }
182 < }
183 <
184 <
185 < cylinder(v0, v1)                /* generate a cylinder */
186 < int  v0, v1;
187 < {
188 <        printf("\n%s cylinder %s.%c%c\n", cmtype, cname, v0+'0', v1+'0');
189 <        printf("0\n0\n7\n");
190 <        vertex(v0);
191 <        vertex(v1);
192 <        printf("\t%18.12g\n", bevel);
193 < }
194 <
195 <
196 < sphere(v0)                      /* generate a sphere */
197 < int  v0;
198 < {
199 <        printf("\n%s sphere %s.%c\n", cmtype, cname, v0+'0');
200 <        printf("0\n0\n4\n");
201 <        vertex(v0);
202 <        printf("\t%18.12g\n", bevel);
203 < }
204 <
205 <
206 < vertex(v)
207 < register int  v;
208 < {
209 <        register int  i;
210 <
211 <        for (i = 0; i < 3; i++) {
212 <                if (v & 010)
213 <                        printf("\t%18.12g", v & 01 ? size[i]-bevel : bevel);
214 <                else
215 <                        printf("\t%18.12g", v & 01 ? size[i] : 0.0);
216 <                v >>= 1;
217 <        }
218 <        printf("\n");
219 < }
220 <
221 <
222 < printhead(ac, av)               /* print command header */
223 < register int  ac;
224 < register char  **av;
225 < {
226 <        putchar('#');
227 <        while (ac--) {
228 <                putchar(' ');
229 <                fputs(*av++, stdout);
230 <        }
231 <        putchar('\n');
205 >        return(1);
206   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines