1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
12 |
|
* 11/6/86 Finally added error checking! |
13 |
|
*/ |
14 |
|
|
15 |
< |
#include <stdio.h> |
15 |
> |
#include "standard.h" |
16 |
|
|
17 |
|
#include <ctype.h> |
18 |
|
|
22 |
|
char **xav; /* global xform argument pointer */ |
23 |
|
int xfa; /* start of xf arguments */ |
24 |
|
|
25 |
< |
double totxform[4][4]; /* total transformation matrix */ |
26 |
< |
double totscale; /* total scale factor */ |
25 |
> |
XF tot; /* total transformation */ |
26 |
|
int reverse; /* boolean true if scene inverted */ |
27 |
|
|
28 |
|
int expand = 0; /* boolean true to expand commands */ |
29 |
|
|
30 |
+ |
char *newmod = NULL; /* new modifier for surfaces */ |
31 |
+ |
|
32 |
|
char *idprefix = NULL; /* prefix for object identifiers */ |
33 |
|
|
34 |
|
#define ALIAS NUMOTYPE /* put alias at end of array */ |
46 |
|
double *farg; /* float arguments */ |
47 |
|
} FUNARGS; |
48 |
|
|
49 |
< |
#define MAXSTR 512 /* maximum string length */ |
49 |
> |
#define MAXSTR 128 /* maximum string length */ |
50 |
|
|
51 |
|
FUNARGS *getfargs(); |
52 |
|
char *malloc(); |
71 |
|
for (a = 1; a < argc; a++) { |
72 |
|
if (argv[a][0] == '-') |
73 |
|
switch (argv[a][1]) { |
74 |
+ |
case 'm': |
75 |
+ |
if (argv[a][2] || a+1 >= argc) |
76 |
+ |
break; |
77 |
+ |
newmod = argv[++a]; |
78 |
+ |
continue; |
79 |
|
case 'n': |
80 |
|
if (argv[a][2] || a+1 >= argc) |
81 |
|
break; |
93 |
|
xav = argv; |
94 |
|
xfa = a; |
95 |
|
|
96 |
< |
totscale = 1.0; |
91 |
< |
setident4(totxform); |
96 |
> |
a += xf(&tot, argc-a, argv+a); |
97 |
|
|
98 |
< |
a += xf(totxform, &totscale, argc-a, argv+a); |
98 |
> |
if (reverse = tot.sca < 0.0) |
99 |
> |
tot.sca = -tot.sca; |
100 |
|
|
95 |
– |
if (reverse = totscale < 0.0) |
96 |
– |
totscale = -totscale; |
97 |
– |
|
101 |
|
if (a < argc && argv[a][0] == '-') { |
102 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
103 |
|
argv[0], argv[a]); |
168 |
|
} |
169 |
|
|
170 |
|
|
171 |
< |
xform(name, fin) /* transform stream by totxform */ |
171 |
> |
xform(name, fin) /* transform stream by tot.xfm */ |
172 |
|
char *name; |
173 |
|
register FILE *fin; |
174 |
|
{ |
235 |
|
char *fname; |
236 |
|
FILE *fin; |
237 |
|
{ |
238 |
< |
char stmp[MAXSTR]; |
238 |
> |
char typ[16], nam[MAXSTR]; |
239 |
|
int fn; |
240 |
< |
|
241 |
< |
fscanf(fin, "%s", stmp); /* modifier */ |
242 |
< |
printf("\n%s ", stmp); |
240 |
< |
fscanf(fin, "%s", stmp); /* object type */ |
241 |
< |
if ((fn = otype(stmp)) < 0) { |
240 |
> |
/* modifier and type */ |
241 |
> |
fscanf(fin, "%s %s", nam, typ); |
242 |
> |
if ((fn = otype(typ)) < 0) { |
243 |
|
fprintf(stderr, "%s: (%s): unknown object type \"%s\"\n", |
244 |
< |
progname, fname, stmp); |
244 |
> |
progname, fname, typ); |
245 |
|
exit(1); |
246 |
|
} |
247 |
< |
printf("%s ", stmp); |
248 |
< |
fscanf(fin, "%s", stmp); /* object name */ |
247 |
> |
printf("\n%s %s ", newmod!=NULL && issurface(fn) ? newmod : nam, typ); |
248 |
> |
/* object name */ |
249 |
> |
fscanf(fin, "%s", nam); |
250 |
|
if (idprefix != NULL && issurface(fn)) |
251 |
< |
printf("%s.%s\n", idprefix, stmp); |
251 |
> |
printf("%s.%s\n", idprefix, nam); |
252 |
|
else |
253 |
< |
printf("%s\n", stmp); |
254 |
< |
/* transform arguments */ |
253 |
> |
printf("%s\n", nam); |
254 |
> |
/* transform arguments */ |
255 |
|
if ((*ofun[fn].funp)(fin) < 0) { |
256 |
|
fprintf(stderr, "%s: (%s): bad %s \"%s\"\n", |
257 |
< |
progname, fname, ofun[fn].funame, stmp); |
257 |
> |
progname, fname, ofun[fn].funame, nam); |
258 |
|
exit(1); |
259 |
|
} |
260 |
|
} |
335 |
|
alias(fin) /* transfer alias */ |
336 |
|
FILE *fin; |
337 |
|
{ |
338 |
< |
char alias[MAXSTR]; |
338 |
> |
char aliasnm[MAXSTR]; |
339 |
|
|
340 |
< |
if (fscanf(fin, "%s", alias) != 1) |
340 |
> |
if (fscanf(fin, "%s", aliasnm) != 1) |
341 |
|
return(-1); |
342 |
< |
printf("\t%s\n", alias); |
342 |
> |
printf("\t%s\n", aliasnm); |
343 |
|
return(0); |
344 |
|
} |
345 |
|
|
356 |
|
printf("0\n0\n4"); |
357 |
|
printf(" %18.12g %18.12g %18.12g", |
358 |
|
fa->farg[0], fa->farg[1], fa->farg[2]); |
359 |
< |
printf(" %18.12g\n", fa->farg[3] * totscale); |
359 |
> |
printf(" %18.12g\n", fa->farg[3] * tot.sca); |
360 |
|
freefargs(fa); |
361 |
|
return(0); |
362 |
|
} |
375 |
|
printf("0\n0\n7"); |
376 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
377 |
|
fa->farg[0], fa->farg[1], fa->farg[2], fa->farg[3]); |
378 |
< |
multv3(v, fa->farg+4, totxform); |
378 |
> |
multv3(v, fa->farg+4, tot.xfm); |
379 |
|
printf("\t%18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
380 |
|
freefargs(fa); |
381 |
|
return(0); |
394 |
|
return(-1); |
395 |
|
printf("0\n0\n5"); |
396 |
|
printf(" %18.12g %18.12g %18.12g", |
397 |
< |
pow(fa->farg[0], 1.0/totscale), |
398 |
< |
pow(fa->farg[1], 1.0/totscale), |
399 |
< |
pow(fa->farg[2], 1.0/totscale)); |
397 |
> |
pow(fa->farg[0], 1.0/tot.sca), |
398 |
> |
pow(fa->farg[1], 1.0/tot.sca), |
399 |
> |
pow(fa->farg[2], 1.0/tot.sca)); |
400 |
|
printf(" %18.12g %18.12g\n", fa->farg[3], fa->farg[4]); |
401 |
|
freefargs(fa); |
402 |
|
return(0); |
415 |
|
return(-1); |
416 |
|
printf("0\n0\n8\n"); |
417 |
|
printf("%18.12g %18.12g %18.12g", |
418 |
< |
pow(fa->farg[0], 1.0/totscale), |
419 |
< |
pow(fa->farg[1], 1.0/totscale), |
420 |
< |
pow(fa->farg[2], 1.0/totscale)); |
418 |
> |
pow(fa->farg[0], 1.0/tot.sca), |
419 |
> |
pow(fa->farg[1], 1.0/tot.sca), |
420 |
> |
pow(fa->farg[2], 1.0/tot.sca)); |
421 |
|
printf(" %18.12g\n", fa->farg[3]); |
422 |
|
printf("%18.12g %18.12g %18.12g", |
423 |
< |
pow(fa->farg[4], 1.0/totscale), |
424 |
< |
pow(fa->farg[5], 1.0/totscale), |
425 |
< |
pow(fa->farg[6], 1.0/totscale)); |
423 |
> |
pow(fa->farg[4], 1.0/tot.sca), |
424 |
> |
pow(fa->farg[5], 1.0/tot.sca), |
425 |
> |
pow(fa->farg[6], 1.0/tot.sca)); |
426 |
|
printf(" %18.12g\n", fa->farg[7]); |
427 |
|
freefargs(fa); |
428 |
|
return(0); |
447 |
|
printf(" %s", fa->sarg[i]); |
448 |
|
printf("\n0\n%d\n", fa->nfargs); |
449 |
|
/* anchor point */ |
450 |
< |
multp3(v, fa->farg, totxform); |
450 |
> |
multp3(v, fa->farg, tot.xfm); |
451 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
452 |
|
/* right vector */ |
453 |
< |
multv3(v, fa->farg+3, totxform); |
453 |
> |
multv3(v, fa->farg+3, tot.xfm); |
454 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
455 |
|
/* down vector */ |
456 |
< |
multv3(v, fa->farg+6, totxform); |
456 |
> |
multv3(v, fa->farg+6, tot.xfm); |
457 |
|
printf(" %18.12g %18.12g %18.12g\n", v[0], v[1], v[2]); |
458 |
|
/* forground and background */ |
459 |
|
if (fa->nfargs == 11) |
480 |
|
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
481 |
|
return(-1); |
482 |
|
/* transform direction vector */ |
483 |
< |
multv3(dv, fa->farg, totxform); |
483 |
> |
multv3(dv, fa->farg, tot.xfm); |
484 |
|
/* output */ |
485 |
|
printf("0\n0\n4"); |
486 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
501 |
|
if (fa->nsargs != 0 || fa->niargs != 0 || fa->nfargs != 4) |
502 |
|
return(-1); |
503 |
|
|
504 |
< |
multp3(cent, fa->farg, totxform); /* transform center */ |
504 |
> |
multp3(cent, fa->farg, tot.xfm); /* transform center */ |
505 |
|
|
506 |
< |
rad = fa->farg[3] * totscale; /* scale radius */ |
506 |
> |
rad = fa->farg[3] * tot.sca; /* scale radius */ |
507 |
|
|
508 |
|
printf("0\n0\n4"); |
509 |
|
printf(" %18.12g %18.12g %18.12g %18.12g\n", |
529 |
|
|
530 |
|
for (i = 0; i < fa->nfargs; i += 3) { |
531 |
|
if (reverse) |
532 |
< |
multp3(p, fa->farg+(fa->nfargs-i-3), totxform); |
532 |
> |
multp3(p, fa->farg+(fa->nfargs-i-3), tot.xfm); |
533 |
|
else |
534 |
< |
multp3(p, fa->farg+i, totxform); |
534 |
> |
multp3(p, fa->farg+i, tot.xfm); |
535 |
|
printf(" %18.12g %18.12g %18.12g\n", p[0], p[1], p[2]); |
536 |
|
} |
537 |
|
freefargs(fa); |
552 |
|
|
553 |
|
printf("0\n0\n8\n"); |
554 |
|
|
555 |
< |
multp3(p0, fa->farg, totxform); |
556 |
< |
multp3(p1, fa->farg+3, totxform); |
557 |
< |
r0 = fa->farg[6] * totscale; |
558 |
< |
r1 = fa->farg[7] * totscale; |
555 |
> |
multp3(p0, fa->farg, tot.xfm); |
556 |
> |
multp3(p1, fa->farg+3, tot.xfm); |
557 |
> |
r0 = fa->farg[6] * tot.sca; |
558 |
> |
r1 = fa->farg[7] * tot.sca; |
559 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
560 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
561 |
|
printf(" %18.12g %18.12g\n", r0, r1); |
578 |
|
|
579 |
|
printf("0\n0\n7\n"); |
580 |
|
|
581 |
< |
multp3(p0, fa->farg, totxform); |
582 |
< |
multp3(p1, fa->farg+3, totxform); |
583 |
< |
rad = fa->farg[6] * totscale; |
581 |
> |
multp3(p0, fa->farg, tot.xfm); |
582 |
> |
multp3(p1, fa->farg+3, tot.xfm); |
583 |
> |
rad = fa->farg[6] * tot.sca; |
584 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
585 |
|
printf(" %18.12g %18.12g %18.12g\n", p1[0], p1[1], p1[2]); |
586 |
|
printf(" %18.12g\n", rad); |
602 |
|
|
603 |
|
printf("0\n0\n8\n"); |
604 |
|
|
605 |
< |
multp3(p0, fa->farg, totxform); |
606 |
< |
multv3(pd, fa->farg+3, totxform); |
607 |
< |
r0 = fa->farg[6] * totscale; |
608 |
< |
r1 = fa->farg[7] * totscale; |
605 |
> |
multp3(p0, fa->farg, tot.xfm); |
606 |
> |
multv3(pd, fa->farg+3, tot.xfm); |
607 |
> |
r0 = fa->farg[6] * tot.sca; |
608 |
> |
r1 = fa->farg[7] * tot.sca; |
609 |
|
printf(" %18.12g %18.12g %18.12g\n", p0[0], p0[1], p0[2]); |
610 |
|
printf(" %18.12g %18.12g %18.12g\n", pd[0], pd[1], pd[2]); |
611 |
|
printf(" %18.12g %18.12g\n", r0, r1); |