21 |
|
|
22 |
|
static MAT4 m4tmp; /* for efficiency */ |
23 |
|
|
24 |
< |
int xf_argc; /* total # transform args. */ |
25 |
< |
char **xf_argv; /* transform arguments */ |
26 |
< |
XF_SPEC *xf_context; /* current context */ |
24 |
> |
XF_SPEC *xf_context; /* current context */ |
25 |
> |
char **xf_argend; /* end of transform argument list */ |
26 |
> |
static char **xf_argbeg; /* beginning of transform argument list */ |
27 |
|
|
28 |
– |
static int xf_maxarg; /* # allocated arguments */ |
29 |
– |
|
28 |
|
static XF_SPEC *new_xf(); |
29 |
|
static long comp_xfid(); |
30 |
|
static int put_oname(); |
38 |
|
register XF_SPEC *spec; |
39 |
|
register int n; |
40 |
|
int rv; |
43 |
– |
XF thisxf; |
41 |
|
|
42 |
|
if (ac == 1) { /* something with existing transform */ |
43 |
|
if ((spec = xf_context) == NULL) |
44 |
< |
return(MG_OK); /* should be error? */ |
44 |
> |
return(MG_ECNTXT); |
45 |
|
n = -1; |
46 |
|
if (spec->xarr != NULL) { /* check for iteration */ |
47 |
|
register struct xf_array *ap = spec->xarr; |
63 |
|
free((MEM_PTR)ap); |
64 |
|
} |
65 |
|
if (n < 0) { /* pop transform */ |
69 |
– |
xf_argv[xf_argc=spec->xav0] = NULL; |
66 |
|
xf_context = spec->prev; |
67 |
|
free((MEM_PTR)spec); |
68 |
|
return(MG_OK); |
74 |
|
xf_context = spec; |
75 |
|
} |
76 |
|
/* translate new specification */ |
77 |
< |
if (xf(&thisxf, spec->xac, &xf_argv[spec->xav0]) != spec->xac) |
77 |
> |
n = xf_ac(spec); |
78 |
> |
if (spec->prev != NULL) /* incremental comp. is more eff. */ |
79 |
> |
n -= xf_ac(spec->prev); |
80 |
> |
if (xf(&spec->xf, n, xf_av(spec)) != n) |
81 |
|
return(MG_ETYPE); |
82 |
+ |
/* check for vertex reversal */ |
83 |
+ |
if ((spec->rev = (spec->xf.sca < 0.))) |
84 |
+ |
spec->xf.sca = -spec->xf.sca; |
85 |
|
/* compute total transformation */ |
86 |
|
if (spec->prev != NULL) { |
87 |
< |
multmat4(spec->xf.xfm, spec->prev->xf.xfm, thisxf.xfm); |
88 |
< |
spec->xf.sca = spec->prev->xf.sca * thisxf.sca; |
89 |
< |
} else |
90 |
< |
spec->xf = thisxf; |
87 |
> |
multmat4(spec->xf.xfm, spec->xf.xfm, spec->prev->xf.xfm); |
88 |
> |
spec->xf.sca *= spec->prev->xf.sca; |
89 |
> |
spec->rev ^= spec->prev->rev; |
90 |
> |
} |
91 |
|
spec->xid = comp_xfid(spec->xf.xfm); /* compute unique ID */ |
92 |
|
return(MG_OK); |
93 |
|
} |
124 |
|
spec->xarr->ndim = 0; /* incremented below */ |
125 |
|
} else |
126 |
|
spec->xarr = NULL; |
127 |
< |
spec->xav0 = xf_argc; |
126 |
< |
spec->xac = ac; |
127 |
> |
spec->xac = ac + xf_argc; |
128 |
|
/* and store new xf arguments */ |
129 |
< |
if (xf_argc+ac+1 > xf_maxarg) { |
130 |
< |
if (!xf_maxarg) |
131 |
< |
xf_argv = (char **)malloc( |
132 |
< |
(xf_maxarg=ac+1)*sizeof(char *)); |
132 |
< |
else |
133 |
< |
xf_argv = (char **)realloc((MEM_PTR)xf_argv, |
134 |
< |
(xf_maxarg=xf_argc+ac+1)*sizeof(char *)); |
135 |
< |
if (xf_argv == NULL) |
129 |
> |
if (xf_argbeg == NULL || xf_av(spec) < xf_argbeg) { |
130 |
> |
register char **newav = |
131 |
> |
(char **)malloc((spec->xac+1)*sizeof(char *)); |
132 |
> |
if (newav == NULL) |
133 |
|
return(NULL); |
134 |
+ |
for (i = xf_argc; i-- > 0; ) |
135 |
+ |
newav[ac+i] = xf_argend[i-xf_context->xac]; |
136 |
+ |
*(xf_argend = newav + spec->xac) = NULL; |
137 |
+ |
if (xf_argbeg != NULL) |
138 |
+ |
free((MEM_PTR)xf_argbeg); |
139 |
+ |
xf_argbeg = newav; |
140 |
|
} |
141 |
|
cp = (char *)(spec + 1); /* use memory allocated above */ |
142 |
|
for (i = 0; i < ac; i++) |
143 |
|
if (!strcmp(av[i], "-a")) { |
144 |
< |
xf_argv[xf_argc++] = "-i"; |
145 |
< |
xf_argv[xf_argc++] = strcpy( |
144 |
> |
xf_av(spec)[i++] = "-i"; |
145 |
> |
xf_av(spec)[i] = strcpy( |
146 |
|
spec->xarr->aarg[spec->xarr->ndim].arg, |
147 |
|
"0"); |
148 |
|
spec->xarr->aarg[spec->xarr->ndim].i = 0; |
149 |
< |
spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[++i]); |
149 |
> |
spec->xarr->aarg[spec->xarr->ndim++].n = atoi(av[i]); |
150 |
|
} else { |
151 |
< |
xf_argv[xf_argc++] = strcpy(cp, av[i]); |
151 |
> |
xf_av(spec)[i] = strcpy(cp, av[i]); |
152 |
|
cp += strlen(av[i]) + 1; |
153 |
|
} |
151 |
– |
xf_argv[xf_argc] = NULL; |
154 |
|
if (spec->xarr != NULL) |
155 |
|
(void)put_oname(spec->xarr); |
156 |
|
return(spec); |
206 |
|
{ |
207 |
|
register XF_SPEC *spec; |
208 |
|
|
209 |
< |
if (xf_maxarg) { |
210 |
< |
free((MEM_PTR)xf_argv); |
211 |
< |
xf_argv = NULL; |
210 |
< |
xf_maxarg = 0; |
209 |
> |
if (xf_argbeg != NULL) { |
210 |
> |
free((MEM_PTR)xf_argbeg); |
211 |
> |
xf_argbeg = xf_argend = NULL; |
212 |
|
} |
212 |
– |
xf_argc = 0; |
213 |
|
while ((spec = xf_context) != NULL) { |
214 |
|
xf_context = spec->prev; |
215 |
|
if (spec->xarr != NULL) |
224 |
|
FVECT v1, v2; |
225 |
|
{ |
226 |
|
if (xf_context == NULL) { |
227 |
< |
v1[0] = v2[0]; |
228 |
< |
v1[1] = v2[1]; |
229 |
< |
v1[2] = v2[2]; |
227 |
> |
VCOPY(v1, v2); |
228 |
|
return; |
229 |
|
} |
230 |
|
multp3(v1, v2, xf_context->xf.xfm); |
236 |
|
FVECT v1, v2; |
237 |
|
{ |
238 |
|
if (xf_context == NULL) { |
239 |
< |
v1[0] = v2[0]; |
242 |
< |
v1[1] = v2[1]; |
243 |
< |
v1[2] = v2[2]; |
239 |
> |
VCOPY(v1, v2); |
240 |
|
return; |
241 |
|
} |
242 |
|
multv3(v1, v2, xf_context->xf.xfm); |