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 |
|
* |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
|
|
12 |
+ |
#include <stdlib.h> |
13 |
+ |
|
14 |
|
#include <math.h> |
15 |
|
|
16 |
|
|
18 |
– |
#ifdef DCL_ATOF |
19 |
– |
extern double atof(); |
20 |
– |
#endif |
21 |
– |
|
17 |
|
char let[]="0123456789._ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
18 |
|
|
19 |
|
char *cmtype; /* ppd material type */ |
24 |
|
|
25 |
|
double bevel = 0.0; /* bevel amount */ |
26 |
|
|
27 |
< |
int round = 0; /* boolean true for round edges */ |
27 |
> |
int rounde = 0; /* boolean true for rounde edges */ |
28 |
|
|
29 |
|
int reverse = 0; /* boolean true for reversed normals */ |
30 |
|
|
31 |
|
|
32 |
+ |
|
33 |
+ |
static void |
34 |
+ |
vertex(v) |
35 |
+ |
register int v; |
36 |
+ |
{ |
37 |
+ |
register int i; |
38 |
+ |
|
39 |
+ |
for (i = 0; i < 3; i++) { |
40 |
+ |
if (v & 010) |
41 |
+ |
printf("\t%18.12g", v & 01 ? size[i]-bevel : bevel); |
42 |
+ |
else |
43 |
+ |
printf("\t%18.12g", v & 01 ? size[i] : 0.0); |
44 |
+ |
v >>= 1; |
45 |
+ |
} |
46 |
+ |
printf("\n"); |
47 |
+ |
} |
48 |
+ |
|
49 |
+ |
|
50 |
+ |
static void |
51 |
+ |
side(a, b, c, d) /* generate a rectangular face */ |
52 |
+ |
int a, b, c, d; |
53 |
+ |
{ |
54 |
+ |
printf("\n%s polygon %s.%c%c%c%c\n", cmtype, cname, |
55 |
+ |
let[a], let[b], let[c], let[d]); |
56 |
+ |
printf("0\n0\n12\n"); |
57 |
+ |
if (reverse) { |
58 |
+ |
vertex(d); |
59 |
+ |
vertex(c); |
60 |
+ |
vertex(b); |
61 |
+ |
vertex(a); |
62 |
+ |
} else { |
63 |
+ |
vertex(a); |
64 |
+ |
vertex(b); |
65 |
+ |
vertex(c); |
66 |
+ |
vertex(d); |
67 |
+ |
} |
68 |
+ |
} |
69 |
+ |
|
70 |
+ |
|
71 |
+ |
static void |
72 |
+ |
corner(a, b, c) /* generate a triangular face */ |
73 |
+ |
int a, b, c; |
74 |
+ |
{ |
75 |
+ |
printf("\n%s polygon %s.%c%c%c\n", cmtype, cname, |
76 |
+ |
let[a], let[b], let[c]); |
77 |
+ |
printf("0\n0\n9\n"); |
78 |
+ |
if (reverse) { |
79 |
+ |
vertex(c); |
80 |
+ |
vertex(b); |
81 |
+ |
vertex(a); |
82 |
+ |
} else { |
83 |
+ |
vertex(a); |
84 |
+ |
vertex(b); |
85 |
+ |
vertex(c); |
86 |
+ |
} |
87 |
+ |
} |
88 |
+ |
|
89 |
+ |
|
90 |
+ |
static void |
91 |
+ |
cylinder(v0, v1) /* generate a cylinder */ |
92 |
+ |
int v0, v1; |
93 |
+ |
{ |
94 |
+ |
printf("\n%s cylinder %s.%c%c\n", cmtype, cname, v0+'0', v1+'0'); |
95 |
+ |
printf("0\n0\n7\n"); |
96 |
+ |
vertex(v0); |
97 |
+ |
vertex(v1); |
98 |
+ |
printf("\t%18.12g\n", bevel); |
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
|
102 |
+ |
static void |
103 |
+ |
sphere(v0) /* generate a sphere */ |
104 |
+ |
int v0; |
105 |
+ |
{ |
106 |
+ |
printf("\n%s sphere %s.%c\n", cmtype, cname, v0+'0'); |
107 |
+ |
printf("0\n0\n4\n"); |
108 |
+ |
vertex(v0); |
109 |
+ |
printf("\t%18.12g\n", bevel); |
110 |
+ |
} |
111 |
+ |
|
112 |
+ |
|
113 |
+ |
static void |
114 |
+ |
printhead(ac, av) /* print command header */ |
115 |
+ |
register int ac; |
116 |
+ |
register char **av; |
117 |
+ |
{ |
118 |
+ |
putchar('#'); |
119 |
+ |
while (ac--) { |
120 |
+ |
putchar(' '); |
121 |
+ |
fputs(*av++, stdout); |
122 |
+ |
} |
123 |
+ |
putchar('\n'); |
124 |
+ |
} |
125 |
+ |
|
126 |
+ |
|
127 |
+ |
int |
128 |
|
main(argc, argv) |
129 |
|
int argc; |
130 |
|
char **argv; |
145 |
|
goto userr; |
146 |
|
switch (argv[i][1]) { |
147 |
|
case 'r': |
148 |
< |
round = 1; |
148 |
> |
rounde = 1; |
149 |
|
/* fall through */ |
150 |
|
case 'b': |
151 |
|
bevel = atof(argv[++i]); |
169 |
|
side(065, 061, 063, 067); |
170 |
|
side(036, 034, 035, 037); |
171 |
|
} |
172 |
< |
if (bevel > 0.0 && !round) { |
172 |
> |
if (bevel > 0.0 && !rounde) { |
173 |
|
/* bevel faces */ |
174 |
|
side(031, 051, 050, 030); |
175 |
|
side(060, 062, 032, 030); |
193 |
|
corner(053, 063, 033); |
194 |
|
corner(037, 067, 057); |
195 |
|
} |
196 |
< |
if (bevel > 0.0 && round) { |
197 |
< |
/* round edges */ |
196 |
> |
if (bevel > 0.0 && rounde) { |
197 |
> |
/* rounde edges */ |
198 |
|
cylinder(070, 071); |
199 |
|
cylinder(070, 074); |
200 |
|
cylinder(070, 072); |
207 |
|
cylinder(076, 072); |
208 |
|
cylinder(076, 074); |
209 |
|
cylinder(076, 077); |
210 |
< |
/* round corners */ |
210 |
> |
/* rounde corners */ |
211 |
|
sphere(070); |
212 |
|
sphere(071); |
213 |
|
sphere(072); |
230 |
|
userr: |
231 |
|
fprintf(stderr, "Usage: %s ", argv[0]); |
232 |
|
fprintf(stderr, "material name xsize ysize zsize "); |
233 |
< |
fprintf(stderr, "[-i] [-b bevel | -r round]\n"); |
233 |
> |
fprintf(stderr, "[-i] [-b bevel | -r rounde]\n"); |
234 |
|
exit(1); |
235 |
|
} |
236 |
|
|
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'); |
232 |
– |
} |