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.3 by greg, Fri Jun 4 14:29:58 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  
# Line 25 | 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;
35 < 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 44 | 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;
60 <                        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 74 | 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 98 | 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 122 | 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 131 | 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);
140 < }
141 <
142 <
143 < side(a, b, c, d)                /* generate a rectangular face */
144 < int  a, b, c, d;
145 < {
146 <        printf("\n%s polygon %s.%c%c%c%c\n", cmtype, cname,
147 <                        let[a], let[b], let[c], let[d]);
148 <        printf("0\n0\n12\n");
149 <        if (reverse) {
150 <                vertex(d);
151 <                vertex(c);
152 <                vertex(b);
153 <                vertex(a);
154 <        } else {
155 <                vertex(a);
156 <                vertex(b);
157 <                vertex(c);
158 <                vertex(d);
159 <        }
160 < }
161 <
162 <
163 < corner(a, b, c)                 /* generate a triangular face */
164 < int  a, b, c;
165 < {
166 <        printf("\n%s polygon %s.%c%c%c\n", cmtype, cname,
167 <                        let[a], let[b], let[c]);
168 <        printf("0\n0\n9\n");
169 <        if (reverse) {
170 <                vertex(c);
171 <                vertex(b);
172 <                vertex(a);
173 <        } else {
174 <                vertex(a);
175 <                vertex(b);
176 <                vertex(c);
177 <        }
178 < }
179 <
180 <
181 < cylinder(v0, v1)                /* generate a cylinder */
182 < int  v0, v1;
183 < {
184 <        printf("\n%s cylinder %s.%c%c\n", cmtype, cname, v0+'0', v1+'0');
185 <        printf("0\n0\n7\n");
186 <        vertex(v0);
187 <        vertex(v1);
188 <        printf("\t%18.12g\n", bevel);
189 < }
190 <
191 <
192 < sphere(v0)                      /* generate a sphere */
193 < int  v0;
194 < {
195 <        printf("\n%s sphere %s.%c\n", cmtype, cname, v0+'0');
196 <        printf("0\n0\n4\n");
197 <        vertex(v0);
198 <        printf("\t%18.12g\n", bevel);
199 < }
200 <
201 <
202 < vertex(v)
203 < register int  v;
204 < {
205 <        register int  i;
206 <
207 <        for (i = 0; i < 3; i++) {
208 <                if (v & 010)
209 <                        printf("\t%18.12g", v & 01 ? size[i]-bevel : bevel);
210 <                else
211 <                        printf("\t%18.12g", v & 01 ? size[i] : 0.0);
212 <                v >>= 1;
213 <        }
214 <        printf("\n");
215 < }
216 <
217 <
218 < printhead(ac, av)               /* print command header */
219 < register int  ac;
220 < register char  **av;
221 < {
222 <        putchar('#');
223 <        while (ac--) {
224 <                putchar(' ');
225 <                fputs(*av++, stdout);
226 <        }
227 <        putchar('\n');
205 >        return(1);
206   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines