| 26 |
|
|
| 27 |
|
/* the current contexts */ |
| 28 |
|
C_COLOR *c_ccolor = &c_uncolor; |
| 29 |
+ |
char *c_ccname = NULL; |
| 30 |
|
C_MATERIAL *c_cmaterial = &c_unmaterial; |
| 31 |
+ |
char *c_cmname = NULL; |
| 32 |
|
C_VERTEX *c_cvertex = &c_unvertex; |
| 33 |
+ |
char *c_cvname = NULL; |
| 34 |
|
|
| 35 |
|
static LUTAB clr_tab = LU_SINIT(free,free); /* color lookup table */ |
| 36 |
|
static LUTAB mat_tab = LU_SINIT(free,free); /* material lookup table */ |
| 52 |
|
{ |
| 53 |
|
double w, wsum; |
| 54 |
|
register int i; |
| 52 |
– |
char *nm; |
| 55 |
|
register LUENT *lp; |
| 56 |
|
|
| 57 |
|
switch (mg_entity(av[0])) { |
| 61 |
|
if (ac == 1) { /* set unnamed color context */ |
| 62 |
|
c_uncolor = c_dfcolor; |
| 63 |
|
c_ccolor = &c_uncolor; |
| 64 |
+ |
c_ccname = NULL; |
| 65 |
|
return(MG_OK); |
| 66 |
|
} |
| 67 |
|
lp = lu_find(&clr_tab, av[1]); /* lookup context */ |
| 68 |
|
if (lp == NULL) |
| 69 |
|
return(MG_EMEM); |
| 70 |
+ |
c_ccname = lp->key; |
| 71 |
|
c_ccolor = (C_COLOR *)lp->data; |
| 72 |
|
if (ac == 2) { /* reestablish previous context */ |
| 73 |
|
if (c_ccolor == NULL) |
| 84 |
|
lp->data = (char *)malloc(sizeof(C_COLOR)); |
| 85 |
|
if (lp->data == NULL) |
| 86 |
|
return(MG_EMEM); |
| 87 |
+ |
c_ccname = lp->key; |
| 88 |
|
c_ccolor = (C_COLOR *)lp->data; |
| 89 |
|
c_ccolor->clock = 0; |
| 90 |
|
} |
| 86 |
– |
nm = lp->key; |
| 91 |
|
i = c_ccolor->clock; |
| 92 |
|
if (ac == 3) { /* use default template */ |
| 93 |
|
*c_ccolor = c_dfcolor; |
| 90 |
– |
c_ccolor->name = nm; |
| 94 |
|
c_ccolor->clock = i + 1; |
| 95 |
|
return(MG_OK); |
| 96 |
|
} |
| 100 |
|
if (lp->data == NULL) |
| 101 |
|
return(MG_EUNDEF); |
| 102 |
|
*c_ccolor = *(C_COLOR *)lp->data; |
| 100 |
– |
c_ccolor->name = nm; |
| 103 |
|
c_ccolor->clock = i + 1; |
| 104 |
|
return(MG_OK); |
| 105 |
|
case MG_E_CXY: /* assign CIE XY value */ |
| 162 |
|
register char **av; |
| 163 |
|
{ |
| 164 |
|
int i; |
| 163 |
– |
char *nm; |
| 165 |
|
register LUENT *lp; |
| 166 |
|
|
| 167 |
|
switch (mg_entity(av[0])) { |
| 171 |
|
if (ac == 1) { /* set unnamed material context */ |
| 172 |
|
c_unmaterial = c_dfmaterial; |
| 173 |
|
c_cmaterial = &c_unmaterial; |
| 174 |
+ |
c_cmname = NULL; |
| 175 |
|
return(MG_OK); |
| 176 |
|
} |
| 177 |
|
lp = lu_find(&mat_tab, av[1]); /* lookup context */ |
| 178 |
|
if (lp == NULL) |
| 179 |
|
return(MG_EMEM); |
| 180 |
+ |
c_cmname = lp->key; |
| 181 |
|
c_cmaterial = (C_MATERIAL *)lp->data; |
| 182 |
|
if (ac == 2) { /* reestablish previous context */ |
| 183 |
|
if (c_cmaterial == NULL) |
| 194 |
|
lp->data = (char *)malloc(sizeof(C_MATERIAL)); |
| 195 |
|
if (lp->data == NULL) |
| 196 |
|
return(MG_EMEM); |
| 197 |
+ |
c_cmname = lp->key; |
| 198 |
|
c_cmaterial = (C_MATERIAL *)lp->data; |
| 199 |
|
c_cmaterial->clock = 0; |
| 200 |
|
} |
| 197 |
– |
nm = lp->key; |
| 201 |
|
i = c_cmaterial->clock; |
| 202 |
|
if (ac == 3) { /* use default template */ |
| 203 |
|
*c_cmaterial = c_dfmaterial; |
| 201 |
– |
c_cmaterial->name = nm; |
| 204 |
|
c_cmaterial->clock = i + 1; |
| 205 |
|
return(MG_OK); |
| 206 |
|
} |
| 210 |
|
if (lp->data == NULL) |
| 211 |
|
return(MG_EUNDEF); |
| 212 |
|
*c_cmaterial = *(C_MATERIAL *)lp->data; |
| 211 |
– |
c_cmaterial->name = nm; |
| 213 |
|
c_cmaterial->clock = i + 1; |
| 214 |
|
return(MG_OK); |
| 215 |
|
case MG_E_RD: /* set diffuse reflectance */ |
| 271 |
|
c_cmaterial->ts_c = *c_ccolor; |
| 272 |
|
c_cmaterial->clock++; |
| 273 |
|
return(MG_OK); |
| 274 |
+ |
case MG_E_SIDES: /* set number of sides */ |
| 275 |
+ |
if (ac != 2) |
| 276 |
+ |
return(MG_EARGC); |
| 277 |
+ |
if (!isint(av[1])) |
| 278 |
+ |
return(MG_ETYPE); |
| 279 |
+ |
i = atoi(av[1]); |
| 280 |
+ |
if (i == 1) |
| 281 |
+ |
c_cmaterial->sided = 1; |
| 282 |
+ |
else if (i == 2) |
| 283 |
+ |
c_cmaterial->sided = 0; |
| 284 |
+ |
else |
| 285 |
+ |
return(MG_EILL); |
| 286 |
+ |
c_cmaterial->clock++; |
| 287 |
+ |
return(MG_OK); |
| 288 |
|
} |
| 289 |
|
return(MG_EUNK); |
| 290 |
|
} |
| 296 |
|
register char **av; |
| 297 |
|
{ |
| 298 |
|
int i; |
| 284 |
– |
char *nm; |
| 299 |
|
register LUENT *lp; |
| 300 |
|
|
| 301 |
|
switch (mg_entity(av[0])) { |
| 305 |
|
if (ac == 1) { /* set unnamed vertex context */ |
| 306 |
|
c_unvertex = c_dfvertex; |
| 307 |
|
c_cvertex = &c_unvertex; |
| 308 |
+ |
c_cvname = NULL; |
| 309 |
|
return(MG_OK); |
| 310 |
|
} |
| 311 |
|
lp = lu_find(&vtx_tab, av[1]); /* lookup context */ |
| 312 |
|
if (lp == NULL) |
| 313 |
|
return(MG_EMEM); |
| 314 |
+ |
c_cvname = lp->key; |
| 315 |
|
c_cvertex = (C_VERTEX *)lp->data; |
| 316 |
|
if (ac == 2) { /* reestablish previous context */ |
| 317 |
|
if (c_cvertex == NULL) |
| 328 |
|
lp->data = (char *)malloc(sizeof(C_VERTEX)); |
| 329 |
|
if (lp->data == NULL) |
| 330 |
|
return(MG_EMEM); |
| 331 |
+ |
c_cvname = lp->key; |
| 332 |
|
c_cvertex = (C_VERTEX *)lp->data; |
| 333 |
|
} |
| 317 |
– |
nm = lp->key; |
| 334 |
|
i = c_cvertex->clock; |
| 335 |
|
if (ac == 3) { /* use default template */ |
| 336 |
|
*c_cvertex = c_dfvertex; |
| 321 |
– |
c_cvertex->name = nm; |
| 337 |
|
c_cvertex->clock = i + 1; |
| 338 |
|
return(MG_OK); |
| 339 |
|
} |
| 343 |
|
if (lp->data == NULL) |
| 344 |
|
return(MG_EUNDEF); |
| 345 |
|
*c_cvertex = *(C_VERTEX *)lp->data; |
| 331 |
– |
c_cvertex->name = nm; |
| 346 |
|
c_cvertex->clock = i + 1; |
| 347 |
|
return(MG_OK); |
| 348 |
|
case MG_E_POINT: /* set point */ |
| 376 |
|
{ |
| 377 |
|
c_uncolor = c_dfcolor; |
| 378 |
|
c_ccolor = &c_uncolor; |
| 379 |
+ |
c_ccname = NULL; |
| 380 |
|
lu_done(&clr_tab); |
| 381 |
|
c_unmaterial = c_dfmaterial; |
| 382 |
|
c_cmaterial = &c_unmaterial; |
| 383 |
+ |
c_cmname = NULL; |
| 384 |
|
lu_done(&mat_tab); |
| 385 |
|
c_unvertex = c_dfvertex; |
| 386 |
|
c_cvertex = &c_unvertex; |
| 387 |
+ |
c_cvname = NULL; |
| 388 |
|
lu_done(&vtx_tab); |
| 389 |
|
} |
| 390 |
|
|