14 |
|
|
15 |
|
#include "platform.h" |
16 |
|
#include "rtio.h" |
17 |
< |
#include "rtprocess.h" |
17 |
> |
#include "paths.h" |
18 |
|
#include "fvect.h" |
19 |
|
|
20 |
|
#ifdef M_PI |
23 |
|
#define PI 3.14159265358979323846 |
24 |
|
#endif |
25 |
|
|
26 |
– |
#define FEQ(a,b) ((a)-(b) <= 1e-7 && (b)-(a) <= 1e-7) |
27 |
– |
|
26 |
|
#define MAXVERT 6 /* maximum number of vertices for markers */ |
27 |
< |
#define MAXMARK 32 /* maximum number of markers */ |
27 |
> |
#define MAXMARK 128 /* maximum number of markers */ |
28 |
|
|
29 |
|
#define USE_XFORM 1 /* use !xform inline command */ |
30 |
|
#define USE_INSTANCE 2 /* use instance primitive */ |
41 |
|
char *modin; /* input modifier indicating marker */ |
42 |
|
char *objname; /* output object file or octree */ |
43 |
|
int usetype; /* one of USE_* above */ |
44 |
< |
} marker[MAXMARK]; /* array of markers */ |
44 |
> |
} marker[MAXMARK+1]; /* array of markers */ |
45 |
|
int nmarkers = 0; /* number of markers */ |
46 |
|
|
47 |
|
int expand; /* expand commands? */ |
100 |
|
} while (argv[i][0] == '-'); |
101 |
|
if (marker[nmarkers].objname == NULL) |
102 |
|
goto userr; |
103 |
+ |
if (nmarkers >= MAXMARK) { |
104 |
+ |
fprintf(stderr, "%s: too many markers\n", progname); |
105 |
+ |
return 1; |
106 |
+ |
} |
107 |
|
marker[nmarkers++].modin = argv[i++]; |
106 |
– |
if (nmarkers >= MAXMARK) |
107 |
– |
break; |
108 |
|
marker[nmarkers].mscale = marker[nmarkers-1].mscale; |
109 |
|
} |
110 |
|
if (nmarkers == 0) |
183 |
|
exit(1); |
184 |
|
} |
185 |
|
convert(buf, pin); |
186 |
< |
pclose(pin); |
186 |
> |
if (pclose(pin) != 0) { |
187 |
> |
fprintf(stderr, |
188 |
> |
"%s: (%s): bad status from \"%s\"\n", |
189 |
> |
progname, fname, buf); |
190 |
> |
exit(1); |
191 |
> |
} |
192 |
|
} else |
193 |
|
printf("\n%s\n", buf); |
194 |
|
} |
205 |
|
int i, n; |
206 |
|
register int j; |
207 |
|
|
208 |
< |
if (fscanf(fin, "%s %s %s", buf, typ, nam) != 3) |
208 |
> |
if (fgetword(buf, sizeof(buf), fin) == NULL || |
209 |
> |
fgetword(typ, sizeof(typ), fin) == NULL || |
210 |
> |
fgetword(nam, sizeof(nam), fin) == NULL) |
211 |
|
goto readerr; |
212 |
|
if (!strcmp(typ, "polygon")) |
213 |
|
for (j = 0; j < nmarkers; j++) |
215 |
|
replace(fname, &marker[j], nam, fin); |
216 |
|
return; |
217 |
|
} |
218 |
< |
printf("\n%s %s %s\n", buf, typ, nam); |
218 |
> |
putchar('\n'); fputword(buf, stdout); |
219 |
> |
printf(" %s ", typ); |
220 |
> |
fputword(nam, stdout); putchar('\n'); |
221 |
|
if (!strcmp(typ, "alias")) { /* alias special case */ |
222 |
< |
if (fscanf(fin, "%s", buf) != 1) |
222 |
> |
if (fgetword(buf, sizeof(buf), fin) == NULL) |
223 |
|
goto readerr; |
224 |
< |
printf("\t%s\n", buf); |
224 |
> |
putchar('\t'); fputword(buf, stdout); putchar('\n'); |
225 |
|
return; |
226 |
|
} |
227 |
|
for (i = 0; i < 3; i++) { /* pass along arguments */ |
394 |
|
int n; |
395 |
|
double theta; |
396 |
|
|
397 |
+ |
if (yp[2]*yp[2] + zp[2]*zp[2] < 2.*FTINY*FTINY) { |
398 |
+ |
/* Special case for X' along Z-axis */ |
399 |
+ |
theta = -atan2(yp[0], yp[1]); |
400 |
+ |
sprintf(xf, " -ry %f -rz %f", |
401 |
+ |
xp[2] < 0.0 ? 90.0 : -90.0, |
402 |
+ |
theta*(180./PI)); |
403 |
+ |
return(4); |
404 |
+ |
} |
405 |
|
n = 0; |
406 |
|
theta = atan2(yp[2], zp[2]); |
407 |
< |
if (!FEQ(theta,0.0)) { |
407 |
> |
if (!FABSEQ(theta,0.0)) { |
408 |
|
sprintf(xf, " -rx %f", theta*(180./PI)); |
409 |
|
while (*xf) ++xf; |
410 |
|
n += 2; |
411 |
|
} |
412 |
< |
theta = asin(-xp[2]); |
413 |
< |
if (!FEQ(theta,0.0)) { |
412 |
> |
theta = Asin(-xp[2]); |
413 |
> |
if (!FABSEQ(theta,0.0)) { |
414 |
|
sprintf(xf, " -ry %f", theta*(180./PI)); |
415 |
|
while (*xf) ++xf; |
416 |
|
n += 2; |
417 |
|
} |
418 |
|
theta = atan2(xp[1], xp[0]); |
419 |
< |
if (!FEQ(theta,0.0)) { |
419 |
> |
if (!FABSEQ(theta,0.0)) { |
420 |
|
sprintf(xf, " -rz %f", theta*(180./PI)); |
421 |
|
/* while (*xf) ++xf; */ |
422 |
|
n += 2; |