1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
27 |
|
|
28 |
|
int (*mg_ehand[MG_NENTITIES])(); |
29 |
|
|
30 |
+ |
/* Handler routine for unknown entities */ |
31 |
+ |
|
32 |
+ |
int (*mg_uhand)() = mg_defuhand; |
33 |
+ |
|
34 |
+ |
unsigned mg_nunknown; /* count of unknown entities */ |
35 |
+ |
|
36 |
|
/* error messages */ |
37 |
|
|
38 |
|
char *mg_err[MG_NERRS] = MG_ERRLIST; |
59 |
|
|
60 |
|
/* temporary settings for testing */ |
61 |
|
#define e_ies e_any_toss |
56 |
– |
#define e_cmix e_any_toss |
57 |
– |
#define e_cspec e_any_toss |
62 |
|
/* alternate handler routines */ |
63 |
|
|
64 |
|
static int e_any_toss(), /* discard unneeded entity */ |
65 |
|
e_ies(), /* IES luminaire file */ |
66 |
|
e_include(), /* include file */ |
67 |
|
e_sph(), /* sphere */ |
68 |
+ |
e_cct(), /* color temperature */ |
69 |
|
e_cmix(), /* color mixtures */ |
70 |
< |
e_cspec(); /* color spectra */ |
70 |
> |
e_cspec(), /* color spectra */ |
71 |
|
e_cyl(), /* cylinder */ |
72 |
|
e_cone(), /* cone */ |
73 |
|
e_prism(), /* prism */ |
95 |
|
mg_ehand[MG_E_INCLUDE] = e_include; |
96 |
|
if (mg_ehand[MG_E_SPH] == NULL) { |
97 |
|
mg_ehand[MG_E_SPH] = e_sph; |
98 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
98 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
99 |
|
} else |
100 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
100 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
101 |
|
if (mg_ehand[MG_E_CYL] == NULL) { |
102 |
|
mg_ehand[MG_E_CYL] = e_cyl; |
103 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
103 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
104 |
|
} else |
105 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
105 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
106 |
|
if (mg_ehand[MG_E_CONE] == NULL) { |
107 |
|
mg_ehand[MG_E_CONE] = e_cone; |
108 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
108 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
109 |
|
} else |
110 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
110 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
111 |
|
if (mg_ehand[MG_E_RING] == NULL) { |
112 |
|
mg_ehand[MG_E_RING] = e_ring; |
113 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
113 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
114 |
|
} else |
115 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
115 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
116 |
|
if (mg_ehand[MG_E_PRISM] == NULL) { |
117 |
|
mg_ehand[MG_E_PRISM] = e_prism; |
118 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_VERTEX; |
118 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX; |
119 |
|
} else |
120 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
120 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
121 |
|
if (mg_ehand[MG_E_TORUS] == NULL) { |
122 |
|
mg_ehand[MG_E_TORUS] = e_torus; |
123 |
< |
ineed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX; |
123 |
> |
ineed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX; |
124 |
|
} else |
125 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_NORMAL|1<<MG_E_VERTEX|1<<MG_E_XF; |
125 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_NORMAL|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
126 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
127 |
< |
if (mg_ehand[MG_E_CMIX] == NULL) |
127 |
> |
if (mg_ehand[MG_E_CMIX] == NULL) { |
128 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
129 |
< |
if (mg_ehand[MG_E_CSPEC] == NULL) |
129 |
> |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
130 |
> |
} |
131 |
> |
if (mg_ehand[MG_E_CSPEC] == NULL) { |
132 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
133 |
+ |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
134 |
+ |
} |
135 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
136 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
137 |
+ |
ineed |= 1L<<MG_E_COLOR|1L<<MG_E_CXY|1L<<MG_E_CSPEC|1L<<MG_E_CMIX|1L<<MG_E_CCT; |
138 |
+ |
} |
139 |
|
} |
140 |
|
/* check for consistency */ |
141 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
142 |
< |
uneed |= 1<<MG_E_POINT|1<<MG_E_VERTEX|1<<MG_E_XF; |
143 |
< |
if (mg_ehand[MG_E_CXY] != NULL) |
144 |
< |
uneed |= 1<<MG_E_COLOR; |
142 |
> |
uneed |= 1L<<MG_E_POINT|1L<<MG_E_VERTEX|1L<<MG_E_XF; |
143 |
> |
if (mg_ehand[MG_E_CXY] != NULL || mg_ehand[MG_E_CSPEC] != NULL || |
144 |
> |
mg_ehand[MG_E_CMIX] != NULL) |
145 |
> |
uneed |= 1L<<MG_E_COLOR; |
146 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
147 |
+ |
mg_ehand[MG_E_IR] != NULL || |
148 |
|
mg_ehand[MG_E_ED] != NULL || |
149 |
|
mg_ehand[MG_E_RS] != NULL || |
150 |
< |
mg_ehand[MG_E_TS] != NULL) |
151 |
< |
uneed |= 1<<MG_E_MATERIAL; |
150 |
> |
mg_ehand[MG_E_TS] != NULL || |
151 |
> |
mg_ehand[MG_E_SIDES] != NULL) |
152 |
> |
uneed |= 1L<<MG_E_MATERIAL; |
153 |
|
for (i = 0; i < MG_NENTITIES; i++) |
154 |
< |
if (uneed & 1<<i && mg_ehand[i] == NULL) { |
154 |
> |
if (uneed & 1L<<i && mg_ehand[i] == NULL) { |
155 |
|
fprintf(stderr, "Missing support for \"%s\" entity\n", |
156 |
|
mg_ename[i]); |
157 |
|
exit(1); |
158 |
|
} |
159 |
|
/* add support as needed */ |
160 |
< |
if (ineed & 1<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
160 |
> |
if (ineed & 1L<<MG_E_VERTEX && mg_ehand[MG_E_VERTEX] != c_hvertex) |
161 |
|
e_supp[MG_E_VERTEX] = c_hvertex; |
162 |
< |
if (ineed & 1<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
162 |
> |
if (ineed & 1L<<MG_E_POINT && mg_ehand[MG_E_POINT] != c_hvertex) |
163 |
|
e_supp[MG_E_POINT] = c_hvertex; |
164 |
< |
if (ineed & 1<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
164 |
> |
if (ineed & 1L<<MG_E_NORMAL && mg_ehand[MG_E_NORMAL] != c_hvertex) |
165 |
|
e_supp[MG_E_NORMAL] = c_hvertex; |
166 |
+ |
if (ineed & 1L<<MG_E_COLOR && mg_ehand[MG_E_COLOR] != c_hcolor) |
167 |
+ |
e_supp[MG_E_COLOR] = c_hcolor; |
168 |
+ |
if (ineed & 1L<<MG_E_CXY && mg_ehand[MG_E_CXY] != c_hcolor) |
169 |
+ |
e_supp[MG_E_CXY] = c_hcolor; |
170 |
+ |
if (ineed & 1L<<MG_E_CSPEC && mg_ehand[MG_E_CSPEC] != c_hcolor) |
171 |
+ |
e_supp[MG_E_CSPEC] = c_hcolor; |
172 |
+ |
if (ineed & 1L<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
173 |
+ |
e_supp[MG_E_CMIX] = c_hcolor; |
174 |
+ |
if (ineed & 1L<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
175 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
176 |
|
/* discard remaining entities */ |
177 |
|
for (i = 0; i < MG_NENTITIES; i++) |
178 |
|
if (mg_ehand[i] == NULL) |
180 |
|
} |
181 |
|
|
182 |
|
|
157 |
– |
|
183 |
|
int |
184 |
|
mg_entity(name) /* get entity number from its name */ |
185 |
|
char *name; |
186 |
|
{ |
187 |
< |
static LUTAB ent_tab; /* entity lookup table */ |
187 |
> |
static LUTAB ent_tab = LU_SINIT(NULL,NULL); /* lookup table */ |
188 |
|
register char *cp; |
189 |
|
|
190 |
|
if (!ent_tab.tsiz) { /* initialize hash table */ |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
< |
static int |
205 |
< |
handle_it(en, ac, av) /* pass entity to appropriate handler */ |
204 |
> |
int |
205 |
> |
mg_handle(en, ac, av) /* pass entity to appropriate handler */ |
206 |
|
register int en; |
207 |
|
int ac; |
208 |
|
char **av; |
209 |
|
{ |
210 |
|
int rv; |
211 |
|
|
212 |
< |
if (en < 0 && (en = mg_entity(av[0])) < 0) |
212 |
> |
if (en < 0 && (en = mg_entity(av[0])) < 0) { /* unknown entity */ |
213 |
> |
if (mg_uhand != NULL) |
214 |
> |
return((*mg_uhand)(ac, av)); |
215 |
|
return(MG_EUNK); |
216 |
< |
if (e_supp[en] != NULL) { |
216 |
> |
} |
217 |
> |
if (e_supp[en] != NULL) { /* support handler */ |
218 |
|
if ((rv = (*e_supp[en])(ac, av)) != MG_OK) |
219 |
|
return(rv); |
220 |
|
} |
221 |
< |
return((*mg_ehand[en])(ac, av)); |
221 |
> |
return((*mg_ehand[en])(ac, av)); /* assigned handler */ |
222 |
|
} |
223 |
|
|
224 |
|
|
227 |
|
register MG_FCTXT *ctx; |
228 |
|
char *fn; |
229 |
|
{ |
230 |
< |
int olen; |
230 |
> |
static int nfids; |
231 |
|
register char *cp; |
232 |
|
|
233 |
+ |
ctx->fid = ++nfids; |
234 |
|
ctx->lineno = 0; |
235 |
|
if (fn == NULL) { |
236 |
< |
ctx->fname = "<stdin>"; |
236 |
> |
strcpy(ctx->fname, "<stdin>"); |
237 |
|
ctx->fp = stdin; |
238 |
|
ctx->prev = mg_file; |
239 |
|
mg_file = ctx; |
240 |
|
return(MG_OK); |
241 |
|
} |
242 |
|
/* get name relative to this context */ |
243 |
< |
if (mg_file != NULL && |
215 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
216 |
< |
olen = cp - mg_file->fname + 1; |
217 |
< |
else |
218 |
< |
olen = 0; |
219 |
< |
ctx->fname = (char *)malloc(olen+strlen(fn)+1); |
220 |
< |
if (ctx->fname == NULL) |
221 |
< |
return(MG_EMEM); |
222 |
< |
if (olen) |
243 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
244 |
|
strcpy(ctx->fname, mg_file->fname); |
245 |
< |
strcpy(ctx->fname+olen, fn); |
245 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
246 |
> |
} else |
247 |
> |
strcpy(ctx->fname, fn); |
248 |
|
ctx->fp = fopen(ctx->fname, "r"); |
249 |
< |
if (ctx->fp == NULL) { |
227 |
< |
free((MEM_PTR)ctx->fname); |
249 |
> |
if (ctx->fp == NULL) |
250 |
|
return(MG_ENOFILE); |
229 |
– |
} |
251 |
|
ctx->prev = mg_file; /* establish new context */ |
252 |
|
mg_file = ctx; |
253 |
|
return(MG_OK); |
263 |
|
if (ctx->fp == stdin) |
264 |
|
return; /* don't close standard input */ |
265 |
|
fclose(ctx->fp); |
245 |
– |
free((MEM_PTR)ctx->fname); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
+ |
void |
270 |
+ |
mg_fgetpos(pos) /* get current position in input file */ |
271 |
+ |
register MG_FPOS *pos; |
272 |
+ |
{ |
273 |
+ |
extern long ftell(); |
274 |
+ |
|
275 |
+ |
pos->fid = mg_file->fid; |
276 |
+ |
pos->lineno = mg_file->lineno; |
277 |
+ |
pos->offset = ftell(mg_file->fp); |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
|
281 |
|
int |
282 |
< |
mg_rewind() /* rewind input file */ |
282 |
> |
mg_fgoto(pos) /* reposition input file pointer */ |
283 |
> |
register MG_FPOS *pos; |
284 |
|
{ |
285 |
< |
if (mg_file->lineno == 0) |
285 |
> |
if (pos->fid != mg_file->fid) |
286 |
> |
return(MG_ESEEK); |
287 |
> |
if (pos->lineno == mg_file->lineno) |
288 |
|
return(MG_OK); |
289 |
|
if (mg_file->fp == stdin) |
290 |
|
return(MG_ESEEK); /* cannot seek on standard input */ |
291 |
< |
if (fseek(mg_file->fp, 0L, 0) == EOF) |
291 |
> |
if (fseek(mg_file->fp, pos->offset, 0) == EOF) |
292 |
|
return(MG_ESEEK); |
293 |
< |
mg_file->lineno = 0; |
293 |
> |
mg_file->lineno = pos->lineno; |
294 |
|
return(MG_OK); |
295 |
|
} |
296 |
|
|
339 |
|
return(MG_OK); /* no words in line */ |
340 |
|
*ap = NULL; |
341 |
|
/* else handle it */ |
342 |
< |
return(handle_it(-1, ap-argv, argv)); |
342 |
> |
return(mg_handle(-1, ap-argv, argv)); |
343 |
|
} |
344 |
|
|
345 |
|
|
366 |
|
} |
367 |
|
|
368 |
|
|
369 |
+ |
int |
370 |
+ |
mg_defuhand(ac, av) /* default handler for unknown entities */ |
371 |
+ |
int ac; |
372 |
+ |
char **av; |
373 |
+ |
{ |
374 |
+ |
if (mg_nunknown++ == 0) /* report first incident */ |
375 |
+ |
fprintf(stderr, "%s: %d: %s: %s\n", mg_file->fname, |
376 |
+ |
mg_file->lineno, mg_err[MG_EUNK], av[0]); |
377 |
+ |
return(MG_OK); |
378 |
+ |
} |
379 |
+ |
|
380 |
+ |
|
381 |
|
void |
382 |
|
mg_clear() /* clear parser history */ |
383 |
|
{ |
386 |
|
} |
387 |
|
|
388 |
|
|
342 |
– |
int |
343 |
– |
mg_iterate(ac, av, f) /* iterate on statement */ |
344 |
– |
int ac; |
345 |
– |
register char **av; |
346 |
– |
int (*f)(); |
347 |
– |
{ |
348 |
– |
int niter, rval; |
349 |
– |
register int i, j; |
350 |
– |
char *argv[MG_MAXARGC]; |
351 |
– |
char cntbuf[10]; |
352 |
– |
/* build partial transformation */ |
353 |
– |
for (i = 0; i < ac; i++) { |
354 |
– |
if (av[i][0] == '-' && av[i][1] == 'a' && av[i][2] == '\0') |
355 |
– |
break; |
356 |
– |
argv[i+1] = av[i]; |
357 |
– |
} |
358 |
– |
argv[i+1] = NULL; |
359 |
– |
if (i) { /* handle transformation */ |
360 |
– |
argv[0] = mg_ename[MG_E_XF]; |
361 |
– |
if ((rval = handle_it(MG_E_XF, i+1, argv)) != MG_OK) |
362 |
– |
return(rval); |
363 |
– |
} |
364 |
– |
if (i < ac) { /* run array */ |
365 |
– |
if (i+1 >= ac || !isint(av[i+1])) |
366 |
– |
return(MG_ETYPE); |
367 |
– |
niter = atoi(av[i+1]); |
368 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
369 |
– |
argv[1] = cntbuf; |
370 |
– |
for (j = 2; j+i < ac; j++) |
371 |
– |
argv[j] = av[j+i]; |
372 |
– |
argv[j] = NULL; |
373 |
– |
for (j = 0; j < niter; j++) { |
374 |
– |
sprintf(cntbuf, "%d", j); |
375 |
– |
if ((rval = handle_it(MG_E_OBJECT, 2, argv)) != MG_OK) |
376 |
– |
return(rval); |
377 |
– |
argv[0] = "-i"; |
378 |
– |
if ((rval = mg_iterate(ac-i, argv, f)) != MG_OK) |
379 |
– |
return(rval); |
380 |
– |
argv[0] = mg_ename[MG_E_OBJECT]; |
381 |
– |
if ((rval = handle_it(MG_E_OBJECT, 1, argv)) != MG_OK) |
382 |
– |
return(rval); |
383 |
– |
} |
384 |
– |
} else if ((rval = (*f)()) != MG_OK) /* else do this instance */ |
385 |
– |
return(rval); |
386 |
– |
if (i) { /* reset the transform */ |
387 |
– |
argv[0] = mg_ename[MG_E_XF]; |
388 |
– |
argv[1] = NULL; |
389 |
– |
(void)handle_it(MG_E_XF, 1, argv); |
390 |
– |
} |
391 |
– |
return(MG_OK); |
392 |
– |
} |
393 |
– |
|
394 |
– |
|
389 |
|
/**************************************************************************** |
390 |
|
* The following routines handle unsupported entities |
391 |
|
*/ |
401 |
|
|
402 |
|
|
403 |
|
static int |
410 |
– |
reload_file() /* reload current MGF file */ |
411 |
– |
{ |
412 |
– |
register int rval; |
413 |
– |
|
414 |
– |
if ((rval = mg_rewind()) != MG_OK) |
415 |
– |
return(rval); |
416 |
– |
while (mg_read()) |
417 |
– |
if ((rval = mg_parse()) != MG_OK) |
418 |
– |
return(rval); |
419 |
– |
return(MG_OK); |
420 |
– |
} |
421 |
– |
|
422 |
– |
|
423 |
– |
static int |
404 |
|
e_include(ac, av) /* include file */ |
405 |
|
int ac; |
406 |
|
char **av; |
407 |
|
{ |
408 |
+ |
char *xfarg[MG_MAXARGC]; |
409 |
|
MG_FCTXT ictx; |
410 |
+ |
XF_SPEC *xf_orig = xf_context; |
411 |
|
int rv; |
412 |
|
|
413 |
|
if (ac < 2) |
414 |
|
return(MG_EARGC); |
415 |
|
if ((rv = mg_open(&ictx, av[1])) != MG_OK) |
416 |
|
return(rv); |
417 |
< |
if ((rv = mg_iterate(ac-2, av+2, reload_file)) != MG_OK) { |
418 |
< |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
419 |
< |
ictx.lineno, mg_err[rv], ictx.inpline); |
420 |
< |
mg_close(); |
421 |
< |
return(MG_EINCL); |
417 |
> |
if (ac > 2) { |
418 |
> |
register int i; |
419 |
> |
|
420 |
> |
xfarg[0] = mg_ename[MG_E_XF]; |
421 |
> |
for (i = 1; i < ac-1; i++) |
422 |
> |
xfarg[i] = av[i+1]; |
423 |
> |
xfarg[ac-1] = NULL; |
424 |
> |
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
425 |
> |
return(rv); |
426 |
|
} |
427 |
+ |
do { |
428 |
+ |
while (mg_read()) |
429 |
+ |
if ((rv = mg_parse()) != MG_OK) { |
430 |
+ |
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
431 |
+ |
ictx.lineno, mg_err[rv], |
432 |
+ |
ictx.inpline); |
433 |
+ |
mg_close(); |
434 |
+ |
return(MG_EINCL); |
435 |
+ |
} |
436 |
+ |
if (ac > 2) |
437 |
+ |
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
438 |
+ |
return(rv); |
439 |
+ |
} while (xf_context != xf_orig); |
440 |
|
mg_close(); |
441 |
|
return(MG_OK); |
442 |
|
} |
484 |
|
rad = atof(av[2]); |
485 |
|
/* initialize */ |
486 |
|
warpconends = 1; |
487 |
< |
if ((rval = handle_it(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
487 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 3, v2ent)) != MG_OK) |
488 |
|
return(rval); |
489 |
|
sprintf(p2x, FLTFMT, cv->p[0]); |
490 |
|
sprintf(p2y, FLTFMT, cv->p[1]); |
491 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad); |
492 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
492 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
493 |
|
return(rval); |
494 |
|
r2[0] = '0'; r2[1] = '\0'; |
495 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
496 |
|
theta = i*(PI/2)/mg_nqcdivs; |
497 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
497 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
498 |
|
return(rval); |
499 |
|
sprintf(p2z, FLTFMT, cv->p[2]+rad*cos(theta)); |
500 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
500 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
501 |
|
return(rval); |
502 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
502 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
503 |
|
return(rval); |
504 |
|
strcpy(r1, r2); |
505 |
|
sprintf(r2, FLTFMT, rad*sin(theta)); |
506 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
506 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
507 |
|
return(rval); |
508 |
|
} |
509 |
|
warpconends = 0; |
558 |
|
for (j = 0; j < 3; j++) |
559 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
560 |
|
.5*sgn*(maxrad-minrad)*cv->n[j]); |
561 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
561 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
562 |
|
return(rval); |
563 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
563 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
564 |
|
return(rval); |
565 |
|
sprintf(r2, FLTFMT, avgrad=.5*(minrad+maxrad)); |
566 |
|
/* run outer section */ |
567 |
|
for (i = 1; i <= 2*mg_nqcdivs; i++) { |
568 |
|
theta = i*(PI/2)/mg_nqcdivs; |
569 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
569 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
570 |
|
return(rval); |
571 |
|
for (j = 0; j < 3; j++) |
572 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
573 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
574 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
574 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
575 |
|
return(rval); |
576 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
576 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
577 |
|
return(rval); |
578 |
|
strcpy(r1, r2); |
579 |
|
sprintf(r2, FLTFMT, avgrad + .5*(maxrad-minrad)*sin(theta)); |
580 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
580 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
581 |
|
return(rval); |
582 |
|
} |
583 |
|
/* run inner section */ |
587 |
|
for (j = 0; j < 3; j++) |
588 |
|
sprintf(p2[j], FLTFMT, cv->p[j] + |
589 |
|
.5*sgn*(maxrad-minrad)*cos(theta)*cv->n[j]); |
590 |
< |
if ((rval = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
590 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
591 |
|
return(rval); |
592 |
< |
if ((rval = handle_it(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
592 |
> |
if ((rval = mg_handle(MG_E_VERTEX, 2, v2ent)) != MG_OK) |
593 |
|
return(rval); |
594 |
< |
if ((rval = handle_it(MG_E_POINT, 4, p2ent)) != MG_OK) |
594 |
> |
if ((rval = mg_handle(MG_E_POINT, 4, p2ent)) != MG_OK) |
595 |
|
return(rval); |
596 |
|
strcpy(r1, r2); |
597 |
|
sprintf(r2, FLTFMT, -avgrad - .5*(maxrad-minrad)*sin(theta)); |
598 |
< |
if ((rval = handle_it(MG_E_CONE, 5, conent)) != MG_OK) |
598 |
> |
if ((rval = mg_handle(MG_E_CONE, 5, conent)) != MG_OK) |
599 |
|
return(rval); |
600 |
|
} |
601 |
|
warpconends = 0; |
616 |
|
avnew[2] = av[2]; |
617 |
|
avnew[3] = av[3]; |
618 |
|
avnew[4] = av[2]; |
619 |
< |
return(handle_it(MG_E_CONE, 5, avnew)); |
619 |
> |
return(mg_handle(MG_E_CONE, 5, avnew)); |
620 |
|
} |
621 |
|
|
622 |
|
|
658 |
|
make_axes(u, v, cv->n); |
659 |
|
for (j = 0; j < 3; j++) |
660 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*u[j]); |
661 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
661 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
662 |
|
return(rv); |
663 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
663 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
664 |
|
return(rv); |
665 |
|
if (minrad == 0.) { /* closed */ |
666 |
|
v1ent[3] = av[1]; |
667 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
667 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
668 |
|
return(rv); |
669 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, nzent)) != MG_OK) |
669 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, nzent)) != MG_OK) |
670 |
|
return(rv); |
671 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
672 |
|
theta = i*(PI/2)/mg_nqcdivs; |
673 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
673 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
674 |
|
return(rv); |
675 |
|
for (j = 0; j < 3; j++) |
676 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + |
677 |
|
maxrad*u[j]*cos(theta) + |
678 |
|
maxrad*v[j]*sin(theta)); |
679 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
679 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
680 |
|
return(rv); |
681 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
681 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
682 |
|
return(rv); |
683 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
683 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
684 |
|
return(rv); |
685 |
|
} |
686 |
|
} else { /* open */ |
687 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
687 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
688 |
|
return(rv); |
689 |
|
for (j = 0; j < 3; j++) |
690 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*u[j]); |
691 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
691 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
692 |
|
return(rv); |
693 |
|
v1ent[3] = "_rv4"; |
694 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
695 |
|
theta = i*(PI/2)/mg_nqcdivs; |
696 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
696 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
697 |
|
return(rv); |
698 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
698 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
699 |
|
return(rv); |
700 |
|
for (j = 0; j < 3; j++) { |
701 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
702 |
|
sprintf(p3[j], FLTFMT, cv->p[j] + maxrad*d); |
703 |
|
sprintf(p4[j], FLTFMT, cv->p[j] + minrad*d); |
704 |
|
} |
705 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
705 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
706 |
|
return(rv); |
707 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
707 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
708 |
|
return(rv); |
709 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
709 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
710 |
|
return(rv); |
711 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
711 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
712 |
|
return(rv); |
713 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
713 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
714 |
|
return(rv); |
715 |
|
} |
716 |
|
} |
792 |
|
else |
793 |
|
sprintf(n3[j], FLTFMT, u[j] + w[j]*n2off); |
794 |
|
} |
795 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
795 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v3ent)) != MG_OK) |
796 |
|
return(rv); |
797 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
797 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
798 |
|
return(rv); |
799 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
799 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
800 |
|
return(rv); |
801 |
|
if (rad1 == 0.) { /* triangles */ |
802 |
|
v1ent[3] = av[1]; |
803 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
803 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
804 |
|
return(rv); |
805 |
|
for (j = 0; j < 3; j++) |
806 |
|
sprintf(n4[j], FLTFMT, w[j]); |
807 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
807 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
808 |
|
return(rv); |
809 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
810 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
811 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
811 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
812 |
|
return(rv); |
813 |
|
for (j = 0; j < 3; j++) { |
814 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
816 |
|
if (n2off > -FHUGE) |
817 |
|
sprintf(n3[j], FLTFMT, d + w[j]*n2off); |
818 |
|
} |
819 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
819 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
820 |
|
return(rv); |
821 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
821 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
822 |
|
return(rv); |
823 |
|
if (n2off > -FHUGE && |
824 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
824 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
825 |
|
return(rv); |
826 |
< |
if ((rv = handle_it(MG_E_FACE, 4, fent)) != MG_OK) |
826 |
> |
if ((rv = mg_handle(MG_E_FACE, 4, fent)) != MG_OK) |
827 |
|
return(rv); |
828 |
|
} |
829 |
|
} else { /* quads */ |
842 |
|
else |
843 |
|
sprintf(n4[j], FLTFMT, u[j] + w[j]*n1off); |
844 |
|
} |
845 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
845 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 3, v4ent)) != MG_OK) |
846 |
|
return(rv); |
847 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
847 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
848 |
|
return(rv); |
849 |
< |
if ((rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
849 |
> |
if ((rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
850 |
|
return(rv); |
851 |
|
for (i = 1; i <= 4*mg_nqcdivs; i++) { |
852 |
|
theta = sgn*i*(PI/2)/mg_nqcdivs; |
853 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
853 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v1ent)) != MG_OK) |
854 |
|
return(rv); |
855 |
< |
if ((rv = handle_it(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
855 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, v2ent)) != MG_OK) |
856 |
|
return(rv); |
857 |
|
for (j = 0; j < 3; j++) { |
858 |
|
d = u[j]*cos(theta) + v[j]*sin(theta); |
863 |
|
if (n1off < FHUGE) |
864 |
|
sprintf(n4[j], FLTFMT, d + w[j]*n1off); |
865 |
|
} |
866 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
866 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v3ent)) != MG_OK) |
867 |
|
return(rv); |
868 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p3ent)) != MG_OK) |
868 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p3ent)) != MG_OK) |
869 |
|
return(rv); |
870 |
|
if (n2off > -FHUGE && |
871 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
871 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n3ent)) != MG_OK) |
872 |
|
return(rv); |
873 |
< |
if ((rv = handle_it(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
873 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 2, v4ent)) != MG_OK) |
874 |
|
return(rv); |
875 |
< |
if ((rv = handle_it(MG_E_POINT, 4, p4ent)) != MG_OK) |
875 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, p4ent)) != MG_OK) |
876 |
|
return(rv); |
877 |
|
if (n1off < FHUGE && |
878 |
< |
(rv = handle_it(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
878 |
> |
(rv = mg_handle(MG_E_NORMAL, 4, n4ent)) != MG_OK) |
879 |
|
return(rv); |
880 |
< |
if ((rv = handle_it(MG_E_FACE, 5, fent)) != MG_OK) |
880 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, fent)) != MG_OK) |
881 |
|
return(rv); |
882 |
|
} |
883 |
|
} |
891 |
|
char **av; |
892 |
|
{ |
893 |
|
static char p[3][24]; |
894 |
< |
static char *vent[4] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
894 |
> |
static char *vent[5] = {mg_ename[MG_E_VERTEX],NULL,"="}; |
895 |
|
static char *pent[5] = {mg_ename[MG_E_POINT],p[0],p[1],p[2]}; |
896 |
+ |
static char *znorm[5] = {mg_ename[MG_E_NORMAL],"0","0","0"}; |
897 |
|
char *newav[MG_MAXARGC], nvn[MG_MAXARGC-1][8]; |
898 |
|
double length; |
899 |
+ |
int hasnorm; |
900 |
|
FVECT v1, v2, v3, norm; |
901 |
|
register C_VERTEX *cv; |
902 |
|
C_VERTEX *cv0; |
903 |
|
int rv; |
904 |
|
register int i, j; |
905 |
< |
|
905 |
> |
/* check arguments */ |
906 |
|
if (ac < 5) |
907 |
|
return(MG_EARGC); |
908 |
|
if (!isflt(av[ac-1])) |
910 |
|
length = atof(av[ac-1]); |
911 |
|
if (length <= FTINY && length >= -FTINY) |
912 |
|
return(MG_EILL); |
913 |
< |
/* do bottom face */ |
914 |
< |
newav[0] = mg_ename[MG_E_FACE]; |
914 |
< |
for (i = 1; i < ac-1; i++) |
915 |
< |
newav[i] = av[i]; |
916 |
< |
newav[i] = NULL; |
917 |
< |
if ((rv = handle_it(MG_E_FACE, i, newav)) != MG_OK) |
918 |
< |
return(rv); |
919 |
< |
/* compute face normal */ |
920 |
< |
if ((cv0 = c_getvert(av[2])) == NULL) |
913 |
> |
/* compute face normal */ |
914 |
> |
if ((cv0 = c_getvert(av[1])) == NULL) |
915 |
|
return(MG_EUNDEF); |
916 |
+ |
hasnorm = 0; |
917 |
|
norm[0] = norm[1] = norm[2] = 0.; |
918 |
|
v1[0] = v1[1] = v1[2] = 0.; |
919 |
|
for (i = 2; i < ac-1; i++) { |
920 |
|
if ((cv = c_getvert(av[i])) == NULL) |
921 |
|
return(MG_EUNDEF); |
922 |
+ |
hasnorm += !is0vect(cv->n); |
923 |
|
v2[0] = cv->p[0] - cv0->p[0]; |
924 |
|
v2[1] = cv->p[1] - cv0->p[1]; |
925 |
|
v2[2] = cv->p[2] - cv0->p[2]; |
931 |
|
} |
932 |
|
if (normalize(norm) == 0.) |
933 |
|
return(MG_EILL); |
934 |
< |
/* create moved vertices */ |
934 |
> |
/* create moved vertices */ |
935 |
|
for (i = 1; i < ac-1; i++) { |
936 |
|
sprintf(nvn[i-1], "_pv%d", i); |
937 |
|
vent[1] = nvn[i-1]; |
938 |
< |
if ((rv = handle_it(MG_E_VERTEX, 3, vent)) != MG_OK) |
938 |
> |
vent[3] = av[i]; |
939 |
> |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
940 |
|
return(rv); |
941 |
|
cv = c_getvert(av[i]); /* checked above */ |
942 |
|
for (j = 0; j < 3; j++) |
943 |
|
sprintf(p[j], FLTFMT, cv->p[j] - length*norm[j]); |
944 |
< |
if ((rv = handle_it(MG_E_POINT, 4, pent)) != MG_OK) |
944 |
> |
if ((rv = mg_handle(MG_E_POINT, 4, pent)) != MG_OK) |
945 |
|
return(rv); |
949 |
– |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
946 |
|
} |
947 |
< |
/* do top face */ |
948 |
< |
if ((rv = handle_it(MG_E_FACE, ac-1, newav)) != MG_OK) |
953 |
< |
return(rv); |
947 |
> |
/* make faces */ |
948 |
> |
newav[0] = mg_ename[MG_E_FACE]; |
949 |
|
/* do the side faces */ |
950 |
|
newav[5] = NULL; |
951 |
|
newav[3] = av[ac-2]; |
953 |
|
for (i = 1; i < ac-1; i++) { |
954 |
|
newav[1] = nvn[i-1]; |
955 |
|
newav[2] = av[i]; |
956 |
< |
if ((rv = handle_it(MG_E_FACE, 5, newav)) != MG_OK) |
956 |
> |
if ((rv = mg_handle(MG_E_FACE, 5, newav)) != MG_OK) |
957 |
|
return(rv); |
958 |
|
newav[3] = newav[2]; |
959 |
|
newav[4] = newav[1]; |
960 |
|
} |
961 |
+ |
/* do top face */ |
962 |
+ |
for (i = 1; i < ac-1; i++) { |
963 |
+ |
if (hasnorm) { /* zero normals */ |
964 |
+ |
vent[1] = nvn[i-1]; |
965 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 2, vent)) != MG_OK) |
966 |
+ |
return(rv); |
967 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
968 |
+ |
return(rv); |
969 |
+ |
} |
970 |
+ |
newav[ac-1-i] = nvn[i-1]; /* reverse */ |
971 |
+ |
} |
972 |
+ |
if ((rv = mg_handle(MG_E_FACE, ac-1, newav)) != MG_OK) |
973 |
+ |
return(rv); |
974 |
+ |
/* do bottom face */ |
975 |
+ |
if (hasnorm) |
976 |
+ |
for (i = 1; i < ac-1; i++) { |
977 |
+ |
vent[1] = nvn[i-1]; |
978 |
+ |
vent[3] = av[i]; |
979 |
+ |
if ((rv = mg_handle(MG_E_VERTEX, 4, vent)) != MG_OK) |
980 |
+ |
return(rv); |
981 |
+ |
if ((rv = mg_handle(MG_E_NORMAL, 4, znorm)) != MG_OK) |
982 |
+ |
return(rv); |
983 |
+ |
newav[i] = nvn[i-1]; |
984 |
+ |
} |
985 |
+ |
else |
986 |
+ |
for (i = 1; i < ac-1; i++) |
987 |
+ |
newav[i] = av[i]; |
988 |
+ |
newav[i] = NULL; |
989 |
+ |
if ((rv = mg_handle(MG_E_FACE, i, newav)) != MG_OK) |
990 |
+ |
return(rv); |
991 |
+ |
return(MG_OK); |
992 |
+ |
} |
993 |
+ |
|
994 |
+ |
|
995 |
+ |
static int |
996 |
+ |
put_cxy() /* put out current xy chromaticities */ |
997 |
+ |
{ |
998 |
+ |
static char xbuf[24], ybuf[24]; |
999 |
+ |
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
1000 |
+ |
int rv; |
1001 |
+ |
|
1002 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
1003 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
1004 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
1005 |
+ |
return(rv); |
1006 |
+ |
return(MG_OK); |
1007 |
+ |
} |
1008 |
+ |
|
1009 |
+ |
|
1010 |
+ |
static int |
1011 |
+ |
put_cspec() /* put out current color spectrum */ |
1012 |
+ |
{ |
1013 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
1014 |
+ |
char *newav[C_CNSS+4]; |
1015 |
+ |
double sf; |
1016 |
+ |
register int i; |
1017 |
+ |
|
1018 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1019 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1020 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1021 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1022 |
+ |
newav[1] = wl[0]; |
1023 |
+ |
newav[2] = wl[1]; |
1024 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1025 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1026 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1027 |
+ |
newav[i+3] = vbuf[i]; |
1028 |
+ |
} |
1029 |
+ |
newav[C_CNSS+3] = NULL; |
1030 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1031 |
+ |
return(i); |
1032 |
+ |
} |
1033 |
+ |
return(MG_OK); |
1034 |
+ |
} |
1035 |
+ |
|
1036 |
+ |
|
1037 |
+ |
static int |
1038 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1039 |
+ |
int ac; |
1040 |
+ |
char **av; |
1041 |
+ |
{ |
1042 |
+ |
/* convert to xy chromaticity */ |
1043 |
+ |
c_ccvt(c_ccolor, C_CSXY); |
1044 |
+ |
/* if it's really their handler, use it */ |
1045 |
+ |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1046 |
+ |
return(put_cxy()); |
1047 |
+ |
return(MG_OK); |
1048 |
+ |
} |
1049 |
+ |
|
1050 |
+ |
|
1051 |
+ |
static int |
1052 |
+ |
e_cmix(ac, av) /* handle mixing of colors */ |
1053 |
+ |
int ac; |
1054 |
+ |
char **av; |
1055 |
+ |
{ |
1056 |
+ |
/* |
1057 |
+ |
* Contorted logic works as follows: |
1058 |
+ |
* 1. the colors are already mixed in c_hcolor() support function |
1059 |
+ |
* 2. if we would handle a spectral result, make sure it's not |
1060 |
+ |
* 3. if c_hcolor() would handle a spectral result, don't bother |
1061 |
+ |
* 4. otherwise, make cspec entity and pass it to their handler |
1062 |
+ |
* 5. if we have only xy results, handle it as c_spec() would |
1063 |
+ |
*/ |
1064 |
+ |
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1065 |
+ |
c_ccvt(c_ccolor, C_CSXY); |
1066 |
+ |
else if (c_ccolor->flags & C_CDSPEC) |
1067 |
+ |
return(put_cspec()); |
1068 |
+ |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1069 |
+ |
return(put_cxy()); |
1070 |
+ |
return(MG_OK); |
1071 |
+ |
} |
1072 |
+ |
|
1073 |
+ |
|
1074 |
+ |
static int |
1075 |
+ |
e_cct(ac, av) /* handle color temperature */ |
1076 |
+ |
int ac; |
1077 |
+ |
char **av; |
1078 |
+ |
{ |
1079 |
+ |
/* |
1080 |
+ |
* Logic is similar to e_cmix here. Support handler has already |
1081 |
+ |
* converted temperature to spectral color. Put it out as such |
1082 |
+ |
* if they support it, otherwise convert to xy chromaticity and |
1083 |
+ |
* put it out if they handle it. |
1084 |
+ |
*/ |
1085 |
+ |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1086 |
+ |
return(put_cspec()); |
1087 |
+ |
c_ccvt(c_ccolor, C_CSXY); |
1088 |
+ |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1089 |
+ |
return(put_cxy()); |
1090 |
|
return(MG_OK); |
1091 |
|
} |