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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines