| 1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 239 |
|
{ |
| 240 |
|
register SPOT *ns; |
| 241 |
|
|
| 242 |
+ |
if ((ns = (SPOT *)m->os) != NULL) |
| 243 |
+ |
return(ns); |
| 244 |
|
if ((ns = (SPOT *)malloc(sizeof(SPOT))) == NULL) |
| 245 |
|
return(NULL); |
| 246 |
|
ns->siz = 2.0*PI * (1.0 - cos(PI/180.0/2.0 * m->oargs.farg[3])); |
| 247 |
|
VCOPY(ns->aim, m->oargs.farg+4); |
| 248 |
|
if ((ns->flen = normalize(ns->aim)) == 0.0) |
| 249 |
|
objerror(m, USER, "zero focus vector"); |
| 250 |
+ |
m->os = (char *)ns; |
| 251 |
|
return(ns); |
| 252 |
|
} |
| 253 |
|
|
| 254 |
|
|
| 255 |
+ |
spotout(r, s, dist) /* check if we're outside spot region */ |
| 256 |
+ |
register RAY *r; |
| 257 |
+ |
register SPOT *s; |
| 258 |
+ |
int dist; |
| 259 |
+ |
{ |
| 260 |
+ |
double d; |
| 261 |
+ |
FVECT vd; |
| 262 |
+ |
|
| 263 |
+ |
if (s == NULL) |
| 264 |
+ |
return(0); |
| 265 |
+ |
if (dist) { /* distant source */ |
| 266 |
+ |
vd[0] = s->aim[0] - r->rorg[0]; |
| 267 |
+ |
vd[1] = s->aim[1] - r->rorg[1]; |
| 268 |
+ |
vd[2] = s->aim[2] - r->rorg[2]; |
| 269 |
+ |
d = DOT(r->rdir,vd); |
| 270 |
+ |
/* wrong side? |
| 271 |
+ |
if (d <= FTINY) |
| 272 |
+ |
return(1); */ |
| 273 |
+ |
d = DOT(vd,vd) - d*d; |
| 274 |
+ |
if (PI*d > s->siz) |
| 275 |
+ |
return(1); /* out */ |
| 276 |
+ |
return(0); /* OK */ |
| 277 |
+ |
} |
| 278 |
+ |
/* local source */ |
| 279 |
+ |
if (s->siz < 2.0*PI * (1.0 + DOT(s->aim,r->rdir))) |
| 280 |
+ |
return(1); /* out */ |
| 281 |
+ |
return(0); /* OK */ |
| 282 |
+ |
} |
| 283 |
+ |
|
| 284 |
+ |
|
| 285 |
|
double |
| 286 |
|
fgetmaxdisk(ocent, op) /* get center and squared radius of face */ |
| 287 |
|
FVECT ocent; |
| 530 |
|
return(1); |
| 531 |
|
} |
| 532 |
|
return(0); |
| 500 |
– |
} |
| 501 |
– |
|
| 502 |
– |
|
| 503 |
– |
#define wrongsource(m, r) (r->rsrc>=0 && \ |
| 504 |
– |
source[r->rsrc].so!=r->ro && \ |
| 505 |
– |
(m->otype!=MAT_ILLUM || \ |
| 506 |
– |
objptr(source[r->rsrc].so->omod)->otype==MAT_ILLUM)) |
| 507 |
– |
|
| 508 |
– |
#define distglow(m, r) (m->otype==MAT_GLOW && \ |
| 509 |
– |
r->rot > m->oargs.farg[3]) |
| 510 |
– |
|
| 511 |
– |
#define badambient(m, r) ((r->crtype&(AMBIENT|SHADOW))==AMBIENT && \ |
| 512 |
– |
!distglow(m, r)) |
| 513 |
– |
|
| 514 |
– |
#define passillum(m, r) (m->otype==MAT_ILLUM && \ |
| 515 |
– |
!(r->rsrc>=0&&source[r->rsrc].so==r->ro)) |
| 516 |
– |
|
| 517 |
– |
#define srcignore(m, r) (directinvis && !(r->crtype&SHADOW) && \ |
| 518 |
– |
!distglow(m, r)) |
| 519 |
– |
|
| 520 |
– |
|
| 521 |
– |
m_light(m, r) /* ray hit a light source */ |
| 522 |
– |
register OBJREC *m; |
| 523 |
– |
register RAY *r; |
| 524 |
– |
{ |
| 525 |
– |
/* check for over-counting */ |
| 526 |
– |
if (wrongsource(m, r) || badambient(m, r)) |
| 527 |
– |
return; |
| 528 |
– |
/* check for passed illum */ |
| 529 |
– |
if (passillum(m, r)) { |
| 530 |
– |
if (m->oargs.nsargs < 1 || !strcmp(m->oargs.sarg[0], VOIDID)) |
| 531 |
– |
raytrans(r); |
| 532 |
– |
else |
| 533 |
– |
rayshade(r, modifier(m->oargs.sarg[0])); |
| 534 |
– |
return; |
| 535 |
– |
} |
| 536 |
– |
/* otherwise treat as source */ |
| 537 |
– |
/* check for behind */ |
| 538 |
– |
if (r->rod < 0.0) |
| 539 |
– |
return; |
| 540 |
– |
/* check for invisibility */ |
| 541 |
– |
if (srcignore(m, r)) |
| 542 |
– |
return; |
| 543 |
– |
/* get distribution pattern */ |
| 544 |
– |
raytexture(r, m->omod); |
| 545 |
– |
/* get source color */ |
| 546 |
– |
setcolor(r->rcol, m->oargs.farg[0], |
| 547 |
– |
m->oargs.farg[1], |
| 548 |
– |
m->oargs.farg[2]); |
| 549 |
– |
/* modify value */ |
| 550 |
– |
multcolor(r->rcol, r->pcol); |
| 533 |
|
} |